use of net.dv8tion.jda.api.exceptions.ErrorHandler in project SkyBot by duncte123.
the class MessageListener method checkMessageForInvites.
// / <editor-fold desc="auto moderation" defaultstate="collapsed">
private void checkMessageForInvites(Guild guild, GuildMessageReceivedEvent event, GuildSetting settings, String raw) {
if (settings.isFilterInvites() && guild.getSelfMember().hasPermission(Permission.MANAGE_SERVER)) {
final Matcher matcher = Message.INVITE_PATTERN.matcher(raw);
if (matcher.find()) {
// Get the invite Id from the message
final String inviteID = matcher.group(matcher.groupCount());
// Prohibiting failure because the bot is currently banned from the other guild.
guild.retrieveInvites().queue((invites) -> {
// Check if the invite is for this guild, if it is not delete the message
if (invites.stream().noneMatch((invite) -> invite.getCode().equals(inviteID))) {
event.getMessage().delete().reason("Contained unauthorized invite.").queue((it) -> sendMsg(MessageConfig.Builder.fromEvent(event).setMessage(event.getAuthor().getAsMention() + ", please don't post invite links here.").setSuccessAction(m -> m.delete().queueAfter(4, TimeUnit.SECONDS)).build()), new ErrorHandler().ignore(UNKNOWN_MESSAGE, MISSING_PERMISSIONS));
}
});
}
}
}
use of net.dv8tion.jda.api.exceptions.ErrorHandler in project Sheikh-Pepe by ICAZ117.
the class Verify method canDM.
public boolean canDM(User user, GuildMessageReceivedEvent event) {
canDM = true;
inverted = false;
user.openPrivateChannel().flatMap(channel -> channel.sendMessage("Assalamu3alaykum Warahmatullahi Wabarakatuh!\n")).delay(Duration.ofSeconds(30)).flatMap(// delete after 30 seconds
Message::delete).queue(null, new ErrorHandler().ignore(// if delete fails that's fine
ErrorResponse.UNKNOWN_MESSAGE).handle(// Fallback handling for blocked messages
ErrorResponse.CANNOT_SEND_TO_USER, (e) -> invert()));
long time = System.currentTimeMillis();
while (System.currentTimeMillis() <= time + 1000) {
}
// System.out.printf("AFTER LOOP\ncanDM: %b\ntime: %d\n", canDM, System.currentTimeMillis());
return canDM;
}
use of net.dv8tion.jda.api.exceptions.ErrorHandler in project SkyBot by DuncteBot.
the class MessageListener method checkSwearFilter.
private boolean checkSwearFilter(Message messageToCheck, GenericGuildMessageEvent event, DunctebotGuild guild) {
final GuildSetting settings = guild.getSettings();
if (settings.isEnableSwearFilter() && !topicContains(event.getChannel(), PROFANITY_DISABLE)) {
final float score = PerspectiveApi.checkSwearFilter(messageToCheck.getContentRaw(), event.getChannel().getId(), variables.getConfig().apis.googl, settings.getFilterType(), variables.getJackson());
// if the score is less than our target value it's not swearing
if (score < settings.getAiSensitivity()) {
return false;
}
final String display = messageToCheck.getContentDisplay();
messageToCheck.delete().reason("Blocked for swearing: " + display).queue(null, new ErrorHandler().ignore(UNKNOWN_MESSAGE, MISSING_PERMISSIONS));
sendMsg(new MessageConfig.Builder().setChannel(event.getChannel()).setMessageFormat(// TODO: allow patrons to customise this message
"Hello there, %s please do not use cursive language within this server.", messageToCheck.getAuthor().getAsMention()).setSuccessAction((m) -> m.delete().queueAfter(5, TimeUnit.SECONDS, null, new ErrorHandler().ignore(UNKNOWN_MESSAGE, MISSING_PERMISSIONS))).build());
modLog(String.format("Message with score %.2f by %#s deleted in %s for profanity, message content was:```\n%s```", score, messageToCheck.getAuthor(), event.getChannel().getAsMention(), // Just to be safe
StringUtils.abbreviate(display, Message.MAX_CONTENT_LENGTH - 150)), guild);
return true;
}
return false;
}
use of net.dv8tion.jda.api.exceptions.ErrorHandler in project Levelbot by Kaktushose.
the class Levelbot method dmRankInfo.
public void dmRankInfo() {
userService.getUsersByDailyEnabled().forEach(botUser -> {
User user = jda.getUserById(botUser.getUserId());
user.openPrivateChannel().flatMap(privateChannel -> privateChannel.sendMessageEmbeds(generateRankInfo(user, true).build())).queue(null, new ErrorHandler().ignore(ErrorResponse.CANNOT_SEND_TO_USER));
});
}
use of net.dv8tion.jda.api.exceptions.ErrorHandler in project Levelbot by Kaktushose.
the class BulkDeleteCommand method onBulkDeleteMessages.
@Command(name = "Nachrichten löschen", usage = "{prefix}delete <amount>", desc = "Löscht die angegebene Zahl von Nachrichten aus einem Channel")
public void onBulkDeleteMessages(CommandEvent event, @Min(value = 1, message = "Muss mindestens eine Nachricht löschen") @Max(value = 100, message = "Kann maximal 100 Nachrichten gleichzeitig löschen") int amount) {
// amount + 1 so we delete the command message as well
// complete aka blocking to make sure that the success message is sent correctly
List<Message> messageHistory = event.getChannel().getHistory().retrievePast(amount + 1).complete();
messageHistory.forEach(message -> message.delete().complete());
event.reply(embedCache.getEmbed("bulkDeleteSuccess").injectValue("amount", amount), message -> message.delete().queueAfter(10, TimeUnit.SECONDS, null, new ErrorHandler().ignore(ErrorResponse.UNKNOWN_MESSAGE)));
// delete success message after 10 secs
}
Aggregations