use of net.dv8tion.jda.api.exceptions.ErrorHandler in project mc-discord-bridge by Selicre.
the class DiscordBotImpl method updateChannels.
private void updateChannels() {
nextTopicUpdateTime = Instant.now().plus(TIME_BETWEEN_TOPIC_UPDATES);
topicNeedsUpdating = false;
TextChannel chatChannel = discord.getTextChannelById(config.channelId);
if (chatChannel != null && config.updateTopic) {
String topic = config.getTopicName(getPlayerNames());
chatChannel.getManager().setTopic(topic).queue(null, new ErrorHandler().handle(ErrorResponse.MISSING_PERMISSIONS, c -> {
LogManager.getLogger().warn("Missing permissions to change channel info!");
// Don't try again
config.updateTopic = false;
}));
}
GuildChannel renameChannel = discord.getGuildChannelById(config.renameChannelId);
int playerCount = server.getCurrentPlayerCount();
if (renameChannel != null) {
renameChannel.getManager().setName(config.getRenameChannelName(playerCount)).queue();
}
}
use of net.dv8tion.jda.api.exceptions.ErrorHandler in project Wylx by Wylx-Bot.
the class Helper method selfDestructingMsg.
/**
* Create a self-destructing message which deletes itself after timeout
* @param msg Message to send
* @param timeout Time until message is deleted
*/
public static void selfDestructingMsg(MessageAction msg, Duration timeout) {
msg.queue(message -> {
var errorHandler = new ErrorHandler().ignore(ErrorResponse.UNKNOWN_MESSAGE);
message.delete().queueAfter(timeout.toSeconds(), TimeUnit.SECONDS, null, errorHandler);
});
}
use of net.dv8tion.jda.api.exceptions.ErrorHandler in project SkyBot by DuncteBot.
the class CommandManager method dispatchCommand.
public void dispatchCommand(@Nonnull ICommand cmd, String invoke, List<String> args, GuildMessageReceivedEvent event) {
this.commandThread.submit(() -> {
MDC.put("command.invoke", invoke);
MDC.put("command.args", args.toString());
MDC.put("user.tag", event.getAuthor().getAsTag());
MDC.put("user.id", event.getAuthor().getId());
MDC.put("guild", event.getGuild().toString());
setJDAContext(event.getJDA());
final TextChannel channel = event.getChannel();
if (!channel.canTalk()) {
return;
}
// Suppress errors from when we can't type in the channel
channel.sendTyping().queue(null, new ErrorHandler().ignore(UNKNOWN_CHANNEL, MISSING_ACCESS));
try {
if (cmd.isCustom()) {
runCustomCommand(cmd, invoke, args, event);
} else {
runNormalCommand(cmd, invoke, args, event);
}
} catch (Throwable ex) {
Sentry.captureException(ex);
LOGGER.error("Error while parsing command", ex);
sendMsg(MessageConfig.Builder.fromEvent(event).setMessage("Something went wrong whilst executing the command, my developers have been informed of this\n" + ex.getMessage()).build());
}
});
}
use of net.dv8tion.jda.api.exceptions.ErrorHandler in project SkyBot by DuncteBot.
the class MessageListener method blacklistedWordCheck.
private boolean blacklistedWordCheck(DunctebotGuild dbG, Message messageToCheck, Member member, List<String> blacklist) {
if (member.hasPermission(Permission.KICK_MEMBERS)) {
return false;
}
final String raw = messageToCheck.getContentRaw().toLowerCase();
for (final String foundWord : blacklist) {
if (Pattern.compile("\\b" + foundWord + "\\b").matcher(raw).find()) {
messageToCheck.delete().reason(String.format("Contains blacklisted word: \"%s\"", foundWord)).queue();
modLog(String.format("Deleted message from %#s in %s for containing the blacklisted word \"%s\"", messageToCheck.getAuthor(), messageToCheck.getChannel(), foundWord), dbG);
sendMsg(new MessageConfig.Builder().setChannel((TextChannel) messageToCheck.getChannel()).setMessageFormat("%s the word \"%s\" is blacklisted on this server", messageToCheck.getMember(), foundWord).setSuccessAction((m) -> m.delete().queueAfter(5, TimeUnit.SECONDS, null, new ErrorHandler().ignore(UNKNOWN_MESSAGE))).build());
return true;
}
}
return false;
}
use of net.dv8tion.jda.api.exceptions.ErrorHandler in project SkyBot by DuncteBot.
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));
}
});
}
}
}
Aggregations