Search in sources :

Example 6 with PermissionException

use of net.dv8tion.jda.core.exceptions.PermissionException in project MantaroBot by Mantaro.

the class MiscCmds method iamnotFunction.

protected static void iamnotFunction(String autoroleName, GuildMessageReceivedEvent event) {
    DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
    Map<String, String> autoroles = dbGuild.getData().getAutoroles();
    if (autoroles.containsKey(autoroleName)) {
        Role role = event.getGuild().getRoleById(autoroles.get(autoroleName));
        if (role == null) {
            event.getChannel().sendMessage(EmoteReference.ERROR + "The role that this autorole corresponded " + "to has been deleted").queue();
            // delete the non-existent autorole.
            dbGuild.getData().getAutoroles().remove(autoroleName);
            dbGuild.saveAsync();
        } else {
            if (!(event.getMember().getRoles().stream().filter(r1 -> r1.getId().equals(role.getId())).collect(Collectors.toList()).size() > 0)) {
                event.getChannel().sendMessage(EmoteReference.ERROR + "You don't have this role, silly!").queue();
                return;
            }
            try {
                event.getGuild().getController().removeRolesFromMember(event.getMember(), role).queue(aVoid -> event.getChannel().sendMessage(EmoteReference.OK + event.getMember().getEffectiveName() + ", you've " + "lost the **" + role.getName() + "** role").queue());
            } catch (PermissionException pex) {
                event.getChannel().sendMessage(String.format("%sI couldn't give you **%s. Make sure that I have permission to add roles and that my role is above **%s**", EmoteReference.ERROR, role.getName(), role.getName())).queue();
            }
        }
    } else {
        event.getChannel().sendMessage(EmoteReference.ERROR + "There isn't an autorole with the name ``" + autoroleName + "``!").queue();
    }
}
Also used : Role(net.dv8tion.jda.core.entities.Role) IntStream(java.util.stream.IntStream) Poll(net.kodehawa.mantarobot.commands.interaction.polls.Poll) Module(net.kodehawa.mantarobot.core.modules.Module) SimpleTreeCommand(net.kodehawa.mantarobot.core.modules.commands.SimpleTreeCommand) Utils(net.kodehawa.mantarobot.utils.Utils) Random(java.util.Random) DiscordUtils(net.kodehawa.mantarobot.utils.DiscordUtils) Message(net.dv8tion.jda.core.entities.Message) PermissionException(net.dv8tion.jda.core.exceptions.PermissionException) MessageBuilder(net.dv8tion.jda.core.MessageBuilder) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) ITreeCommand(net.kodehawa.mantarobot.core.modules.commands.base.ITreeCommand) JSONObject(org.json.JSONObject) Permission(net.dv8tion.jda.core.Permission) CommandRegistry(net.kodehawa.mantarobot.core.CommandRegistry) Map(java.util.Map) StringUtils(br.com.brjdevs.java.utils.texts.StringUtils) Subscribe(com.google.common.eventbus.Subscribe) SimpleCommand(net.kodehawa.mantarobot.core.modules.commands.SimpleCommand) SimpleFileDataManager(net.kodehawa.mantarobot.utils.data.SimpleFileDataManager) MessageEmbed(net.dv8tion.jda.core.entities.MessageEmbed) Role(net.dv8tion.jda.core.entities.Role) PollBuilder(net.kodehawa.mantarobot.commands.interaction.polls.PollBuilder) SubCommand(net.kodehawa.mantarobot.core.modules.commands.SubCommand) Category(net.kodehawa.mantarobot.core.modules.commands.base.Category) DBGuild(net.kodehawa.mantarobot.db.entities.DBGuild) Collectors(java.util.stream.Collectors) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) Slf4j(lombok.extern.slf4j.Slf4j) DataManager(net.kodehawa.mantarobot.utils.data.DataManager) URLEncoder(java.net.URLEncoder) List(java.util.List) CollectionUtils.random(br.com.brjdevs.java.utils.collections.CollectionUtils.random) EmoteReference(net.kodehawa.mantarobot.utils.commands.EmoteReference) MantaroData(net.kodehawa.mantarobot.data.MantaroData) Optional(java.util.Optional) PermissionException(net.dv8tion.jda.core.exceptions.PermissionException) DBGuild(net.kodehawa.mantarobot.db.entities.DBGuild)

Example 7 with PermissionException

use of net.dv8tion.jda.core.exceptions.PermissionException in project MantaroBot by Mantaro.

the class ModerationCmds method tempban.

@Subscribe
public void tempban(CommandRegistry cr) {
    cr.register("tempban", new SimpleCommand(Category.MODERATION) {

        @Override
        protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
            String reason = content;
            Guild guild = event.getGuild();
            User author = event.getAuthor();
            TextChannel channel = event.getChannel();
            Message receivedMessage = event.getMessage();
            if (!guild.getMember(author).hasPermission(net.dv8tion.jda.core.Permission.BAN_MEMBERS)) {
                channel.sendMessage(EmoteReference.ERROR + "Cannot ban: You have no Ban Members permission.").queue();
                return;
            }
            if (event.getMessage().getMentionedUsers().isEmpty()) {
                event.getChannel().sendMessage(EmoteReference.ERROR + "You need to mention an user!").queue();
                return;
            }
            for (User user : event.getMessage().getMentionedUsers()) {
                reason = reason.replaceAll("(\\s+)?<@!?" + user.getId() + ">(\\s+)?", "");
            }
            int index = reason.indexOf("time:");
            if (index < 0) {
                event.getChannel().sendMessage(EmoteReference.ERROR + "You cannot temp ban an user without giving me the time!").queue();
                return;
            }
            String time = reason.substring(index);
            reason = reason.replace(time, "").trim();
            time = time.replaceAll("time:(\\s+)?", "");
            if (reason.isEmpty()) {
                event.getChannel().sendMessage(EmoteReference.ERROR + "You cannot temp ban someone without a reason.!").queue();
                return;
            }
            if (time.isEmpty()) {
                event.getChannel().sendMessage(EmoteReference.ERROR + "You cannot temp ban someone without giving me the time!").queue();
                return;
            }
            final DBGuild db = MantaroData.db().getGuild(event.getGuild());
            long l = Utils.parseTime(time);
            String finalReason = String.format("Temporally banned by %#s: %s", event.getAuthor(), reason);
            String sTime = StringUtils.parseTime(l);
            receivedMessage.getMentionedUsers().forEach(user -> guild.getController().ban(user, 7).queue(success -> user.openPrivateChannel().queue(privateChannel -> {
                if (!user.isBot()) {
                    privateChannel.sendMessage(String.format("%sYou were **temporarily banned** by %s#%s with reason: %s on server **%s**.", EmoteReference.MEGA, event.getAuthor().getName(), event.getAuthor().getDiscriminator(), finalReason, event.getGuild().getName())).queue();
                }
                db.getData().setCases(db.getData().getCases() + 1);
                db.saveAsync();
                channel.sendMessage(String.format("%s%s (%s got temporarly banned)", EmoteReference.ZAP, modActionQuotes[r.nextInt(modActionQuotes.length)], user.getName())).queue();
                ModLog.log(event.getMember(), user, finalReason, ModLog.ModAction.TEMP_BAN, db.getData().getCases(), sTime);
                MantaroBot.getTempBanManager().addTempban(guild.getId() + ":" + user.getId(), l + System.currentTimeMillis());
                TextChannelGround.of(event).dropItemWithChance(1, 2);
            }), error -> {
                if (error instanceof PermissionException) {
                    channel.sendMessage(String.format("%sError banning %s: (I need the permission %s)", EmoteReference.ERROR, user.getName(), ((PermissionException) error).getPermission())).queue();
                } else {
                    channel.sendMessage(String.format("%sI encountered an unknown error while banning %s", EmoteReference.ERROR, user.getName())).queue();
                    log.warn("Encountered an unexpected error while trying to ban someone.", error);
                }
            }));
        }

        @Override
        public MessageEmbed help(GuildMessageReceivedEvent event) {
            return helpEmbed(event, "Tempban Command").setDescription("**Temporarily bans an user**").addField("Usage", "`~>tempban <user> <reason> time:<time>`", false).addField("Example", "`~>tempban @Kodehawa example time:1d`", false).addField("Extended usage", "`time` - can be used with the following parameters: " + "d (days), s (second), m (minutes), h (hour). **For example time:1d1h will give a day and an hour.**", false).build();
        }
    });
}
Also used : Module(net.kodehawa.mantarobot.core.modules.Module) StringUtils(net.kodehawa.mantarobot.utils.StringUtils) net.dv8tion.jda.core.entities(net.dv8tion.jda.core.entities) Category(net.kodehawa.mantarobot.core.modules.commands.base.Category) Utils(net.kodehawa.mantarobot.utils.Utils) Random(java.util.Random) DBGuild(net.kodehawa.mantarobot.db.entities.DBGuild) MantaroBot(net.kodehawa.mantarobot.MantaroBot) PermissionException(net.dv8tion.jda.core.exceptions.PermissionException) Slf4j(lombok.extern.slf4j.Slf4j) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) ModLog(net.kodehawa.mantarobot.commands.moderation.ModLog) Permission(net.dv8tion.jda.core.Permission) CommandRegistry(net.kodehawa.mantarobot.core.CommandRegistry) EmoteReference(net.kodehawa.mantarobot.utils.commands.EmoteReference) MantaroData(net.kodehawa.mantarobot.data.MantaroData) Subscribe(com.google.common.eventbus.Subscribe) SimpleCommand(net.kodehawa.mantarobot.core.modules.commands.SimpleCommand) TextChannelGround(net.kodehawa.mantarobot.commands.currency.TextChannelGround) PermissionException(net.dv8tion.jda.core.exceptions.PermissionException) DBGuild(net.kodehawa.mantarobot.db.entities.DBGuild) DBGuild(net.kodehawa.mantarobot.db.entities.DBGuild) SimpleCommand(net.kodehawa.mantarobot.core.modules.commands.SimpleCommand) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) Subscribe(com.google.common.eventbus.Subscribe)

Example 8 with PermissionException

use of net.dv8tion.jda.core.exceptions.PermissionException in project MantaroBot by Mantaro.

the class ModerationCmds method softban.

@Subscribe
public void softban(CommandRegistry cr) {
    cr.register("softban", new SimpleCommand(Category.MODERATION) {

        @Override
        protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
            Guild guild = event.getGuild();
            User author = event.getAuthor();
            TextChannel channel = event.getChannel();
            Message receivedMessage = event.getMessage();
            String reason = content;
            if (!guild.getMember(author).hasPermission(Permission.BAN_MEMBERS)) {
                channel.sendMessage(EmoteReference.ERROR2 + "Cannot soft ban: You don't have the Ban Members permission.").queue();
                return;
            }
            if (receivedMessage.getMentionedUsers().isEmpty()) {
                channel.sendMessage(EmoteReference.ERROR + "You must mention 1 or more users to be soft-banned!").queue();
                return;
            }
            Member selfMember = guild.getSelfMember();
            if (!selfMember.hasPermission(Permission.BAN_MEMBERS)) {
                channel.sendMessage(EmoteReference.ERROR2 + "Sorry! I don't have permission to ban members in this server!").queue();
                return;
            }
            for (User user : event.getMessage().getMentionedUsers()) {
                reason = reason.replaceAll("(\\s+)?<@!?" + user.getId() + ">(\\s+)?", "");
            }
            if (reason.isEmpty()) {
                reason = "Reason not specified";
            }
            final String finalReason = String.format("Softbanned by %#s: %s", event.getAuthor(), reason);
            receivedMessage.getMentionedUsers().forEach(user -> {
                if (!event.getGuild().getMember(event.getAuthor()).canInteract(event.getGuild().getMember(user))) {
                    event.getChannel().sendMessage(EmoteReference.ERROR + "You cannot softban an user in a higher hierarchy than you").queue();
                    return;
                }
                if (event.getAuthor().getId().equals(user.getId())) {
                    event.getChannel().sendMessage(EmoteReference.ERROR + "Why are you trying to soft-ban yourself?").queue();
                    return;
                }
                Member member = guild.getMember(user);
                if (member == null)
                    return;
                // If one of them is in a higher hierarchy than the bot, cannot ban.
                if (!selfMember.canInteract(member)) {
                    channel.sendMessage(EmoteReference.ERROR2 + "Cannot softban member: " + member.getEffectiveName() + ", they are " + "higher or the same " + "hierarchy than I am!").queue();
                    return;
                }
                final DBGuild db = MantaroData.db().getGuild(event.getGuild());
                // Proceed to ban them. Again, using queue so I don't get rate limited.
                guild.getController().ban(member, 7).reason(finalReason).queue(success -> user.openPrivateChannel().queue(privateChannel -> {
                    if (!user.isBot()) {
                        privateChannel.sendMessage(String.format("%sYou were **softbanned** by %s#%s for reason %s on server **%s**.", EmoteReference.MEGA, event.getAuthor().getName(), event.getAuthor().getDiscriminator(), finalReason, event.getGuild().getName())).queue();
                    }
                    db.getData().setCases(db.getData().getCases() + 1);
                    db.saveAsync();
                    channel.sendMessage(String.format("%s%s. **(%s got softbanned)**", EmoteReference.ZAP, modActionQuotes[r.nextInt(modActionQuotes.length)], member.getEffectiveName())).queue();
                    guild.getController().unban(member.getUser()).reason(finalReason).queue(aVoid -> {
                    }, error -> {
                        if (error instanceof PermissionException) {
                            channel.sendMessage(String.format(EmoteReference.ERROR + "Error unbanning [%s]: (No permission provided: %s)", member.getEffectiveName(), ((PermissionException) error).getPermission())).queue();
                        } else {
                            channel.sendMessage(String.format(EmoteReference.ERROR + "Unknown error while unbanning [%s]: <%s>: %s", member.getEffectiveName(), error.getClass().getSimpleName(), error.getMessage())).queue();
                            log.warn("Unexpected error while unbanning someone.", error);
                        }
                    });
                    ModLog.log(event.getMember(), user, finalReason, ModLog.ModAction.KICK, db.getData().getCases());
                    TextChannelGround.of(event).dropItemWithChance(2, 2);
                }), error -> {
                    if (error instanceof PermissionException) {
                        channel.sendMessage(String.format(EmoteReference.ERROR + "Error softbanning %s: (No permission provided: %s)", member.getEffectiveName(), ((PermissionException) error).getPermission())).queue();
                    } else {
                        channel.sendMessage(String.format(EmoteReference.ERROR + "Unknown error while softbanning %s", member.getEffectiveName())).queue();
                        log.warn("Unexpected error while soft banning someone.", error);
                    }
                });
            });
        }

        @Override
        public MessageEmbed help(GuildMessageReceivedEvent event) {
            return helpEmbed(event, "Softban").setDescription("**Softban the mentioned user and clears their messages from the past week. (You need Ban " + "Members)**").addField("Summarizing", "A soft ban is a ban & instant unban, normally used to clear " + "the user's messages but **without banning the person permanently**.", false).build();
        }
    });
}
Also used : Module(net.kodehawa.mantarobot.core.modules.Module) StringUtils(net.kodehawa.mantarobot.utils.StringUtils) net.dv8tion.jda.core.entities(net.dv8tion.jda.core.entities) Category(net.kodehawa.mantarobot.core.modules.commands.base.Category) Utils(net.kodehawa.mantarobot.utils.Utils) Random(java.util.Random) DBGuild(net.kodehawa.mantarobot.db.entities.DBGuild) MantaroBot(net.kodehawa.mantarobot.MantaroBot) PermissionException(net.dv8tion.jda.core.exceptions.PermissionException) Slf4j(lombok.extern.slf4j.Slf4j) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) ModLog(net.kodehawa.mantarobot.commands.moderation.ModLog) Permission(net.dv8tion.jda.core.Permission) CommandRegistry(net.kodehawa.mantarobot.core.CommandRegistry) EmoteReference(net.kodehawa.mantarobot.utils.commands.EmoteReference) MantaroData(net.kodehawa.mantarobot.data.MantaroData) Subscribe(com.google.common.eventbus.Subscribe) SimpleCommand(net.kodehawa.mantarobot.core.modules.commands.SimpleCommand) TextChannelGround(net.kodehawa.mantarobot.commands.currency.TextChannelGround) PermissionException(net.dv8tion.jda.core.exceptions.PermissionException) DBGuild(net.kodehawa.mantarobot.db.entities.DBGuild) DBGuild(net.kodehawa.mantarobot.db.entities.DBGuild) SimpleCommand(net.kodehawa.mantarobot.core.modules.commands.SimpleCommand) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) Subscribe(com.google.common.eventbus.Subscribe)

Example 9 with PermissionException

use of net.dv8tion.jda.core.exceptions.PermissionException in project MantaroBot by Mantaro.

the class ModerationCmds method ban.

@Subscribe
public void ban(CommandRegistry cr) {
    cr.register("ban", new SimpleCommand(Category.MODERATION) {

        @Override
        protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
            Guild guild = event.getGuild();
            User author = event.getAuthor();
            TextChannel channel = event.getChannel();
            Message receivedMessage = event.getMessage();
            String reason = content;
            if (!guild.getMember(author).hasPermission(net.dv8tion.jda.core.Permission.BAN_MEMBERS)) {
                channel.sendMessage(EmoteReference.ERROR + "You can't ban: You need the `Ban Users` permission.").queue();
                return;
            }
            if (receivedMessage.getMentionedUsers().isEmpty()) {
                channel.sendMessage(EmoteReference.ERROR + "You need to mention at least one user!").queue();
                return;
            }
            for (User user : event.getMessage().getMentionedUsers()) {
                reason = reason.replaceAll("(\\s+)?<@!?" + user.getId() + ">(\\s+)?", "");
            }
            if (reason.isEmpty()) {
                reason = "Reason not specified";
            }
            final String finalReason = String.format("Banned by %#s: %s", event.getAuthor(), reason);
            receivedMessage.getMentionedUsers().forEach(user -> {
                if (!event.getGuild().getMember(event.getAuthor()).canInteract(event.getGuild().getMember(user))) {
                    event.getChannel().sendMessage(EmoteReference.ERROR + "You cannot ban an user who's higher than you in the " + "server hierarchy! Nice try " + EmoteReference.SMILE).queue();
                    return;
                }
                if (event.getAuthor().getId().equals(user.getId())) {
                    event.getChannel().sendMessage(EmoteReference.ERROR + "Why are you trying to ban yourself, silly?").queue();
                    return;
                }
                Member member = guild.getMember(user);
                if (member == null)
                    return;
                if (!guild.getSelfMember().canInteract(member)) {
                    channel.sendMessage(String.format("%sI can't ban %s; they're higher in the server hierarchy than me!", EmoteReference.ERROR, member.getEffectiveName())).queue();
                    return;
                }
                if (!guild.getSelfMember().hasPermission(net.dv8tion.jda.core.Permission.BAN_MEMBERS)) {
                    channel.sendMessage(EmoteReference.ERROR + "Sorry! I don't have permission to ban members in this server!").queue();
                    return;
                }
                final DBGuild db = MantaroData.db().getGuild(event.getGuild());
                guild.getController().ban(member, 7).reason(finalReason).queue(success -> user.openPrivateChannel().queue(privateChannel -> {
                    if (!user.isBot()) {
                        privateChannel.sendMessage(String.format("%sYou were **banned** by %s#%s on server **%s**. Reason: %s.", EmoteReference.MEGA, event.getAuthor().getName(), event.getAuthor().getDiscriminator(), event.getGuild().getName(), finalReason)).queue();
                    }
                    db.getData().setCases(db.getData().getCases() + 1);
                    db.saveAsync();
                    channel.sendMessage(String.format("%s%s (%s got banned)", EmoteReference.ZAP, modActionQuotes[r.nextInt(modActionQuotes.length)], user.getName())).queue();
                    ModLog.log(event.getMember(), user, finalReason, ModLog.ModAction.BAN, db.getData().getCases());
                    TextChannelGround.of(event).dropItemWithChance(1, 2);
                }), error -> {
                    if (error instanceof PermissionException) {
                        channel.sendMessage(String.format("%sError banning %s: (I need the permission %s)", EmoteReference.ERROR, user.getName(), ((PermissionException) error).getPermission())).queue();
                    } else {
                        channel.sendMessage(String.format("%sI encountered an unknown error while banning %s", EmoteReference.ERROR, member.getEffectiveName())).queue();
                        log.warn("Encountered an unexpected error while trying to ban someone.", error);
                    }
                });
            });
        }

        @Override
        public MessageEmbed help(GuildMessageReceivedEvent event) {
            return helpEmbed(event, "Ban").setDescription("**Bans the mentioned users. (You need Ban Members)**").addField("Usage", "`~>ban <@user> <reason>` - **Bans the specified user**", false).build();
        }
    });
}
Also used : Module(net.kodehawa.mantarobot.core.modules.Module) StringUtils(net.kodehawa.mantarobot.utils.StringUtils) net.dv8tion.jda.core.entities(net.dv8tion.jda.core.entities) Category(net.kodehawa.mantarobot.core.modules.commands.base.Category) Utils(net.kodehawa.mantarobot.utils.Utils) Random(java.util.Random) DBGuild(net.kodehawa.mantarobot.db.entities.DBGuild) MantaroBot(net.kodehawa.mantarobot.MantaroBot) PermissionException(net.dv8tion.jda.core.exceptions.PermissionException) Slf4j(lombok.extern.slf4j.Slf4j) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) ModLog(net.kodehawa.mantarobot.commands.moderation.ModLog) Permission(net.dv8tion.jda.core.Permission) CommandRegistry(net.kodehawa.mantarobot.core.CommandRegistry) EmoteReference(net.kodehawa.mantarobot.utils.commands.EmoteReference) MantaroData(net.kodehawa.mantarobot.data.MantaroData) Subscribe(com.google.common.eventbus.Subscribe) SimpleCommand(net.kodehawa.mantarobot.core.modules.commands.SimpleCommand) TextChannelGround(net.kodehawa.mantarobot.commands.currency.TextChannelGround) PermissionException(net.dv8tion.jda.core.exceptions.PermissionException) DBGuild(net.kodehawa.mantarobot.db.entities.DBGuild) DBGuild(net.kodehawa.mantarobot.db.entities.DBGuild) SimpleCommand(net.kodehawa.mantarobot.core.modules.commands.SimpleCommand) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) Subscribe(com.google.common.eventbus.Subscribe)

Example 10 with PermissionException

use of net.dv8tion.jda.core.exceptions.PermissionException in project MantaroBot by Mantaro.

the class MantaroListener method logEdit.

private void logEdit(GuildMessageUpdateEvent event) {
    try {
        String hour = df.format(new Date(System.currentTimeMillis()));
        String logChannel = MantaroData.db().getGuild(event.getGuild()).getData().getGuildLogChannel();
        if (logChannel != null) {
            TextChannel tc = event.getGuild().getTextChannelById(logChannel);
            if (tc == null)
                return;
            User author = event.getAuthor();
            CachedMessage editedMessage = CommandListener.getMessageCache().get(event.getMessage().getId(), Optional::empty).orElse(null);
            if (editedMessage != null && !editedMessage.getContent().isEmpty() && !event.getChannel().getId().equals(logChannel)) {
                if (MantaroData.db().getGuild(event.getGuild()).getData().getLogExcludedChannels().contains(event.getChannel().getId())) {
                    return;
                }
                if (MantaroData.db().getGuild(event.getGuild()).getData().getModlogBlacklistedPeople().contains(editedMessage.getAuthor().getId())) {
                    return;
                }
                tc.sendMessage(String.format(EmoteReference.WARNING + "`[%s]` Message created by **%s#%s** in channel **%s** was modified.\n```diff\n-%s\n+%s```", hour, author.getName(), author.getDiscriminator(), event.getChannel().getName(), editedMessage.getContent().replace("```", ""), event.getMessage().getContentDisplay().replace("```", ""))).queue();
                CommandListener.getMessageCache().put(event.getMessage().getId(), Optional.of(new CachedMessage(event.getAuthor().getIdLong(), event.getMessage().getContentDisplay())));
                logTotal++;
            }
        }
    } catch (Exception e) {
        if (!(e instanceof NullPointerException) && !(e instanceof IllegalArgumentException) && !(e instanceof CacheLoader.InvalidCacheLoadException) && !(e instanceof PermissionException)) {
            log.warn("Unexpected error while logging a edit.", e);
        }
    }
}
Also used : PermissionException(net.dv8tion.jda.core.exceptions.PermissionException) DBUser(net.kodehawa.mantarobot.db.entities.DBUser) CacheLoader(com.google.common.cache.CacheLoader) Date(java.util.Date) PermissionException(net.dv8tion.jda.core.exceptions.PermissionException) ExecutionException(java.util.concurrent.ExecutionException) CachedMessage(net.kodehawa.mantarobot.core.listeners.entities.CachedMessage)

Aggregations

PermissionException (net.dv8tion.jda.core.exceptions.PermissionException)21 Permission (net.dv8tion.jda.core.Permission)8 net.dv8tion.jda.core.entities (net.dv8tion.jda.core.entities)8 DBGuild (net.kodehawa.mantarobot.db.entities.DBGuild)7 Slf4j (lombok.extern.slf4j.Slf4j)6 GuildMessageReceivedEvent (net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent)6 BotException (tk.ardentbot.core.misc.logging.BotException)6 Subscribe (com.google.common.eventbus.Subscribe)5 Random (java.util.Random)5 CommandRegistry (net.kodehawa.mantarobot.core.CommandRegistry)5 MantaroData (net.kodehawa.mantarobot.data.MantaroData)5 EmoteReference (net.kodehawa.mantarobot.utils.commands.EmoteReference)5 List (java.util.List)4 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)4 Module (net.kodehawa.mantarobot.core.modules.Module)4 SimpleCommand (net.kodehawa.mantarobot.core.modules.commands.SimpleCommand)4 Category (net.kodehawa.mantarobot.core.modules.commands.base.Category)4 Utils (net.kodehawa.mantarobot.utils.Utils)4 Date (java.util.Date)3 Message (net.dv8tion.jda.core.entities.Message)3