Search in sources :

Example 11 with PermissionException

use of net.dv8tion.jda.core.exceptions.PermissionException in project Ardent by adamint.

the class FancyPlay method noArgs.

@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
    if (args.length > 1) {
        AudioManager audioManager = guild.getAudioManager();
        String url = message.getRawContent().replace(GuildUtils.getPrefix(guild) + args[0], "");
        boolean shouldDeleteMessage = shouldDeleteMessages(guild);
        boolean implement = false;
        if (!audioManager.isConnected()) {
            VoiceChannel success = joinChannel(guild, guild.getMember(user), this, audioManager, channel);
            if (success != null) {
                loadAndPlay(message, user, this, (TextChannel) channel, url, success, false, false);
                implement = true;
            }
        } else {
            loadAndPlay(message, user, this, (TextChannel) sendTo(channel, guild), url, audioManager.getConnectedChannel(), false, false);
            implement = true;
        }
        if (implement) {
            if (shouldDeleteMessage) {
                try {
                    message.delete().queue();
                } catch (PermissionException ex) {
                    guild.getOwner().getUser().openPrivateChannel().queue(privateChannel -> {
                        privateChannel.sendMessage("Auto-deleting music play messages is enabled, " + "but you need to give me the `MANAGE MESSAGES` permission so I can " + "actually delete the messages.").queue();
                    });
                }
            }
        }
    } else
        sendTranslatedMessage("You need to specify a song name or URL", channel, user);
}
Also used : PermissionException(net.dv8tion.jda.core.exceptions.PermissionException) PermissionException(net.dv8tion.jda.core.exceptions.PermissionException) GuildUtils(tk.ardentbot.utils.discord.GuildUtils) Command(tk.ardentbot.core.executor.Command) Music(tk.ardentbot.commands.music.Music) net.dv8tion.jda.core.entities(net.dv8tion.jda.core.entities) AudioManager(net.dv8tion.jda.core.managers.AudioManager) AudioManager(net.dv8tion.jda.core.managers.AudioManager)

Example 12 with PermissionException

use of net.dv8tion.jda.core.exceptions.PermissionException in project Ardent by adamint.

the class Botname method noArgs.

@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
    if (args.length == 1) {
        sendTranslatedMessage("Enter what you want me to nickname myself", channel, user);
        interactiveOperation(channel, message, howLongMessage -> {
            String howLong = howLongMessage.getRawContent();
            try {
                guild.getController().setNickname(guild.getSelfMember(), howLong).queue(aVoid -> {
                    sendTranslatedMessage("Changed my nickname!", channel, user);
                });
            } catch (Exception e) {
                new BotException(e);
            }
        });
    } else {
        String name = message.getContent().replace(GuildUtils.getPrefix(guild) + args[0] + " ", "");
        if (name.equalsIgnoreCase("reset")) {
            name = "";
        }
        try {
            guild.getController().setNickname(guild.getSelfMember(), name).queue(aVoid -> {
                try {
                    sendTranslatedMessage("Changed my nickname!", channel, user);
                } catch (Exception e) {
                    new BotException(e);
                }
            });
        } catch (PermissionException ex) {
            sendTranslatedMessage("I couldn't change my nickname, make sure I have permission to do that", channel, user);
        }
    }
}
Also used : PermissionException(net.dv8tion.jda.core.exceptions.PermissionException) BotException(tk.ardentbot.core.misc.logging.BotException) PermissionException(net.dv8tion.jda.core.exceptions.PermissionException) BotException(tk.ardentbot.core.misc.logging.BotException)

Example 13 with PermissionException

use of net.dv8tion.jda.core.exceptions.PermissionException in project Ardent by adamint.

the class SoftBan method noArgs.

@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
    Member userMember = guild.getMember(user);
    if (userMember.hasPermission(Permission.BAN_MEMBERS)) {
        List<User> mentioned = message.getMentionedUsers();
        try {
            User u = mentioned.get(0);
            String userString = u.toString();
            String uToSend = UserUtils.getNameWithDiscriminator(userString);
            try {
                guild.getController().ban(u, 7).queue();
                guild.getController().unban(u).queue();
                sendTranslatedMessage("Soft-banned **" + uToSend + "**", channel, user);
            } catch (PermissionException ex) {
                sendTranslatedMessage("I don't have permissions to ban!", channel, user);
            }
        } catch (Exception e) {
            new BotException(e);
        }
    } else {
        sendTranslatedMessage("You don't have the: `Ban Members` permission", channel, user);
    }
}
Also used : PermissionException(net.dv8tion.jda.core.exceptions.PermissionException) BotException(tk.ardentbot.core.misc.logging.BotException) PermissionException(net.dv8tion.jda.core.exceptions.PermissionException) BotException(tk.ardentbot.core.misc.logging.BotException)

Example 14 with PermissionException

use of net.dv8tion.jda.core.exceptions.PermissionException in project Ardent by adamint.

the class Prune method noArgs.

@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
    if (args.length == 1) {
        sendTranslatedMessage("Prune\n" + "Prune users who have been inactive a certain amount of days\n" + "\n" + "Syntax: {0}prune [amount of days]\n" + "Example usage: {0}prune 4".replace("{0}", GuildUtils.getPrefix(guild) + args[0]), channel, user);
    } else {
        if (guild.getMember(user).hasPermission(Permission.MANAGE_SERVER)) {
            try {
                int day = Integer.parseInt(args[1]);
                if (day <= 0) {
                    sendTranslatedMessage("Your number has to be at least 1!", channel, user);
                    return;
                }
                guild.getController().prune(day).queue(integer -> {
                    try {
                        sendTranslatedMessage("Successfully pruned{0} users.".replace("{0}", String.valueOf(integer)), channel, user);
                    } catch (Exception e) {
                        new BotException(e);
                    }
                });
            } catch (NumberFormatException ex) {
                sendTranslatedMessage("You did not supply a whole number.", channel, user);
            } catch (PermissionException ex) {
                sendTranslatedMessage("I don't have permissions to kick users", channel, user);
            }
        } else
            sendTranslatedMessage("You don't have permission to kick users.", channel, user);
    }
}
Also used : PermissionException(net.dv8tion.jda.core.exceptions.PermissionException) BotException(tk.ardentbot.core.misc.logging.BotException) PermissionException(net.dv8tion.jda.core.exceptions.PermissionException) BotException(tk.ardentbot.core.misc.logging.BotException)

Aggregations

PermissionException (net.dv8tion.jda.core.exceptions.PermissionException)14 net.dv8tion.jda.core.entities (net.dv8tion.jda.core.entities)6 BotException (tk.ardentbot.core.misc.logging.BotException)6 Permission (net.dv8tion.jda.core.Permission)4 SimpleDateFormat (java.text.SimpleDateFormat)3 List (java.util.List)3 Slf4j (lombok.extern.slf4j.Slf4j)3 GuildMessageReceivedEvent (net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent)3 Collectors (java.util.stream.Collectors)2 Guild (net.dv8tion.jda.core.entities.Guild)2 TextChannel (net.dv8tion.jda.core.entities.TextChannel)2 SubscribeEvent (net.dv8tion.jda.core.hooks.SubscribeEvent)2 AudioManager (net.dv8tion.jda.core.managers.AudioManager)2 MantaroBot (net.kodehawa.mantarobot.MantaroBot)2 MantaroData (net.kodehawa.mantarobot.data.MantaroData)2 ManagedDatabase (net.kodehawa.mantarobot.data.db.ManagedDatabase)2 DBGuild (net.kodehawa.mantarobot.data.entities.DBGuild)2 GuildData (net.kodehawa.mantarobot.data.entities.helpers.GuildData)2 Command (net.kodehawa.mantarobot.modules.Command)2 CommandRegistry (net.kodehawa.mantarobot.modules.CommandRegistry)2