Search in sources :

Example 11 with SimpleCommand

use of net.kodehawa.mantarobot.modules.commands.SimpleCommand in project MantaroBot by Mantaro.

the class ImageCmds method rule34.

@Command
public static void rule34(CommandRegistry cr) {
    cr.register("rule34", new SimpleCommand(Category.IMAGE) {

        @Override
        protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
            if (!nsfwCheck(event, true, true))
                return;
            String noArgs = content.split(" ")[0];
            TextChannelGround.of(event).dropItemWithChance(13, 3);
            switch(noArgs) {
                case "get":
                    try {
                        String whole1 = content.replace("get ", "");
                        String[] wholeBeheaded = whole1.split(" ");
                        Rule34.get(60, image -> {
                            try {
                                int number;
                                try {
                                    number = Integer.parseInt(wholeBeheaded[0]);
                                } catch (Exception e) {
                                    number = r.nextInt(image.size());
                                }
                                String TAGS = image.get(number).getTags().replace(" ", " ,");
                                EmbedBuilder builder = new EmbedBuilder();
                                builder.setAuthor("Found image", null, "http:" + image.get(number - 1).getFile_url()).setImage("http:" + image.get(number - 1).getFile_url()).addField("Width", String.valueOf(image.get(number - 1).getWidth()), true).addField("Height", String.valueOf(image.get(number - 1).getHeight()), true).addField("Tags", "``" + (TAGS == null ? "None" : TAGS) + "``", false).setFooter("If the image doesn't load, click the title.", null);
                                event.getChannel().sendMessage(builder.build()).queue();
                            } catch (ArrayIndexOutOfBoundsException e) {
                                event.getChannel().sendMessage(EmoteReference.ERROR + "**There aren't more images or no results found**! Try with a lower number.").queue();
                            }
                        });
                    } catch (Exception exception) {
                        if (exception instanceof NumberFormatException)
                            event.getChannel().sendMessage(EmoteReference.ERROR + "Wrong argument type. Check ~>help rule34").queue(message -> message.delete().queueAfter(10, TimeUnit.SECONDS));
                    }
                    break;
                case "tags":
                    try {
                        try {
                            boolean isOldFormat = args[1].matches("^[0-9]*$");
                            if (isOldFormat) {
                                event.getChannel().sendMessage(EmoteReference.WARNING + "Now you don't need to specify the page number. Please use ~>rule34 tags <tag>").queue();
                                return;
                            }
                            String sNoArgs = content.replace("tags ", "");
                            String[] expectedNumber = sNoArgs.split(" ");
                            String tags = expectedNumber[0];
                            Rule34.onSearch(60, tags, images -> {
                                try {
                                    try {
                                        number1 = Integer.parseInt(expectedNumber[2]);
                                    } catch (Exception e) {
                                        number1 = r.nextInt(images.size() > 0 ? images.size() - 1 : images.size());
                                    }
                                    String TAGS = images.get(number).getTags() == null ? tags : images.get(number).getTags().replace(" ", " ,");
                                    EmbedBuilder builder = new EmbedBuilder();
                                    builder.setAuthor("Found image", null, "http:" + images.get(number1 - 1).getFile_url()).setImage("http:" + images.get(number1 - 1).getFile_url()).addField("Width", String.valueOf(images.get(number1 - 1).getWidth()), true).addField("Height", String.valueOf(images.get(number1 - 1).getHeight()), true).addField("Tags", "``" + (TAGS == null ? "None" : TAGS) + "``", false).setFooter("If the image doesn't load, click the title.", null);
                                    event.getChannel().sendMessage(builder.build()).queue();
                                } catch (Exception e) {
                                    e.printStackTrace();
                                    event.getChannel().sendMessage(EmoteReference.ERROR + "**There aren't more images or no results found**! Try with a lower number.").queue();
                                }
                            });
                        } catch (Exception exception) {
                            if (exception instanceof NumberFormatException)
                                event.getChannel().sendMessage(EmoteReference.ERROR + "Wrong argument type. Check ~>help rule34").queue(message -> message.delete().queueAfter(10, TimeUnit.SECONDS));
                        }
                    } catch (NullPointerException e) {
                        event.getChannel().sendMessage(EmoteReference.ERROR + "Rule34 decided to not fetch the image. Well, you can try with another number or tag.").queue();
                    }
                    break;
                default:
                    onHelp(event);
                    break;
            }
        }

        @Override
        public MessageEmbed help(GuildMessageReceivedEvent event) {
            return helpEmbed(event, "rule34.xxx commmand").setColor(Color.PINK).setDescription("**Retrieves images from the rule34 (hentai) image board.**").addField("Usage", "`~>rule34 get <imagenumber>` - **Gets an image based in parameters.**\n" + "`~>rule34 tags <tag> <imagenumber>` - **Gets an image based in the specified tag and parameters.**\n", false).addField("Parameters", "`page` - **Can be any value from 1 to the rule34 maximum page. Probably around 4000.**\n" + "`imagenumber` - **(OPTIONAL) Any number from 1 to the maximum possible images to get, specified by the first instance of the command.**\n" + "`tag` - **Any valid image tag. For example animal_ears or original.**", false).build();
        }
    });
}
Also used : SimpleCommand(net.kodehawa.mantarobot.modules.commands.SimpleCommand) Color(java.awt.Color) Arrays(java.util.Arrays) YandereImageData(net.kodehawa.mantarobot.commands.image.YandereImageData) TextChannel(net.dv8tion.jda.core.entities.TextChannel) Utils(net.kodehawa.mantarobot.utils.Utils) UnirestException(com.mashape.unirest.http.exceptions.UnirestException) Module(net.kodehawa.mantarobot.modules.Module) Wallpaper(net.kodehawa.lib.imageboards.konachan.main.entities.Wallpaper) Random(java.util.Random) ArrayList(java.util.ArrayList) Unirest(com.mashape.unirest.http.Unirest) MessageBuilder(net.dv8tion.jda.core.MessageBuilder) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) OptsCmd.registerOption(net.kodehawa.mantarobot.commands.OptsCmd.registerOption) URLCache(net.kodehawa.mantarobot.utils.cache.URLCache) JSONObject(org.json.JSONObject) DBGuild(net.kodehawa.mantarobot.data.entities.DBGuild) CommandRegistry(net.kodehawa.mantarobot.modules.CommandRegistry) Command(net.kodehawa.mantarobot.modules.Command) MessageEmbed(net.dv8tion.jda.core.entities.MessageEmbed) BidiMap(org.apache.commons.collections4.BidiMap) TextChannelGround(net.kodehawa.mantarobot.commands.currency.TextChannelGround) PostLoadEvent(net.kodehawa.mantarobot.modules.events.PostLoadEvent) DualHashBidiMap(org.apache.commons.collections4.bidimap.DualHashBidiMap) Category(net.kodehawa.mantarobot.modules.commands.base.Category) GsonDataManager(net.kodehawa.mantarobot.utils.data.GsonDataManager) Collectors(java.util.stream.Collectors) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) TimeUnit(java.util.concurrent.TimeUnit) URLEncoder(java.net.URLEncoder) List(java.util.List) CollectionUtils(br.com.brjdevs.java.utils.collections.CollectionUtils) Rule34(net.kodehawa.lib.imageboards.rule34.Rule34) GuildData(net.kodehawa.mantarobot.data.entities.helpers.GuildData) EmoteReference(net.kodehawa.mantarobot.utils.commands.EmoteReference) MantaroData(net.kodehawa.mantarobot.data.MantaroData) net.kodehawa.lib.imageboards.e621.e621(net.kodehawa.lib.imageboards.e621.e621) Konachan(net.kodehawa.lib.imageboards.konachan.Konachan) UnsupportedEncodingException(java.io.UnsupportedEncodingException) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) MessageEmbed(net.dv8tion.jda.core.entities.MessageEmbed) SimpleCommand(net.kodehawa.mantarobot.modules.commands.SimpleCommand) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) UnirestException(com.mashape.unirest.http.exceptions.UnirestException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SimpleCommand(net.kodehawa.mantarobot.modules.commands.SimpleCommand) Command(net.kodehawa.mantarobot.modules.Command)

Example 12 with SimpleCommand

use of net.kodehawa.mantarobot.modules.commands.SimpleCommand in project MantaroBot by Mantaro.

the class ModerationCmds method tempban.

@Command
public static 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 = AudioCmdUtils.parseTime(time);
            String finalReason = reason;
            String sTime = StringUtils.parseTime(l);
            receivedMessage.getMentionedUsers().forEach(user -> guild.getController().ban(user, 7).queue(success -> {
                user.openPrivateChannel().complete().sendMessage(EmoteReference.MEGA + "You were **temporarly banned** by " + event.getAuthor().getName() + "#" + event.getAuthor().getDiscriminator() + " with reason: " + finalReason + ".").queue();
                db.getData().setCases(db.getData().getCases() + 1);
                db.saveAsync();
                channel.sendMessage(EmoteReference.ZAP + "You will be missed... or not " + 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(EmoteReference.ERROR + "Error banning " + user.getName() + ": " + "(I need the permission " + ((PermissionException) error).getPermission() + ")").queue();
                } else {
                    channel.sendMessage(EmoteReference.ERROR + "I encountered an unknown error while banning " + user.getName() + ": " + "<" + error.getClass().getSimpleName() + ">: " + error.getMessage()).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 : SimpleCommand(net.kodehawa.mantarobot.modules.commands.SimpleCommand) StringUtils(net.kodehawa.mantarobot.utils.StringUtils) Utils(net.kodehawa.mantarobot.utils.Utils) Module(net.kodehawa.mantarobot.modules.Module) DiscordUtils(net.kodehawa.mantarobot.utils.DiscordUtils) AudioCmdUtils(net.kodehawa.mantarobot.commands.music.AudioCmdUtils) MantaroBot(net.kodehawa.mantarobot.MantaroBot) PermissionException(net.dv8tion.jda.core.exceptions.PermissionException) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) Permission(net.dv8tion.jda.core.Permission) DBGuild(net.kodehawa.mantarobot.data.entities.DBGuild) Map(java.util.Map) ManagedDatabase(net.kodehawa.mantarobot.data.db.ManagedDatabase) CommandRegistry(net.kodehawa.mantarobot.modules.CommandRegistry) Command(net.kodehawa.mantarobot.modules.Command) TextChannelGround(net.kodehawa.mantarobot.commands.currency.TextChannelGround) PostLoadEvent(net.kodehawa.mantarobot.modules.events.PostLoadEvent) net.dv8tion.jda.core.entities(net.dv8tion.jda.core.entities) Category(net.kodehawa.mantarobot.modules.commands.base.Category) Collectors(java.util.stream.Collectors) Slf4j(lombok.extern.slf4j.Slf4j) ModLog(net.kodehawa.mantarobot.commands.moderation.ModLog) List(java.util.List) OffsetDateTime(java.time.OffsetDateTime) GuildData(net.kodehawa.mantarobot.data.entities.helpers.GuildData) EmoteReference(net.kodehawa.mantarobot.utils.commands.EmoteReference) CommandPermission(net.kodehawa.mantarobot.modules.commands.CommandPermission) MantaroData(net.kodehawa.mantarobot.data.MantaroData) Optional(java.util.Optional) Queue(java.util.Queue) PermissionException(net.dv8tion.jda.core.exceptions.PermissionException) DBGuild(net.kodehawa.mantarobot.data.entities.DBGuild) DBGuild(net.kodehawa.mantarobot.data.entities.DBGuild) SimpleCommand(net.kodehawa.mantarobot.modules.commands.SimpleCommand) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) SimpleCommand(net.kodehawa.mantarobot.modules.commands.SimpleCommand) Command(net.kodehawa.mantarobot.modules.Command)

Example 13 with SimpleCommand

use of net.kodehawa.mantarobot.modules.commands.SimpleCommand in project MantaroBot by Mantaro.

the class InfoCmds method guildinfo.

@Command
public static void guildinfo(CommandRegistry cr) {
    cr.register("serverinfo", new SimpleCommand(Category.INFO) {

        @Override
        protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
            Guild guild = event.getGuild();
            TextChannel channel = event.getChannel();
            String roles = guild.getRoles().stream().filter(role -> !guild.getPublicRole().equals(role)).map(Role::getName).collect(Collectors.joining(", "));
            if (roles.length() > 1024)
                roles = roles.substring(0, 1024 - 4) + "...";
            channel.sendMessage(new EmbedBuilder().setAuthor("Server Information", null, guild.getIconUrl()).setColor(guild.getOwner().getColor() == null ? Color.ORANGE : guild.getOwner().getColor()).setDescription("Server information for " + guild.getName()).setThumbnail(guild.getIconUrl()).addField("Users (Online/Unique)", (int) guild.getMembers().stream().filter(u -> !u.getOnlineStatus().equals(OnlineStatus.OFFLINE)).count() + "/" + guild.getMembers().size(), true).addField("Main Channel", guild.getPublicChannel().getAsMention(), true).addField("Creation Date", guild.getCreationTime().format(DateTimeFormatter.ISO_DATE_TIME).replaceAll("[^0-9.:-]", " "), true).addField("Voice/Text Channels", guild.getVoiceChannels().size() + "/" + guild.getTextChannels().size(), true).addField("Owner", guild.getOwner().getUser().getName() + "#" + guild.getOwner().getUser().getDiscriminator(), true).addField("Region", guild.getRegion() == null ? "Unknown." : guild.getRegion().getName(), true).addField("Roles (" + guild.getRoles().size() + ")", roles, false).setFooter("Server ID: " + String.valueOf(guild.getId()), null).build()).queue();
        }

        @Override
        public MessageEmbed help(GuildMessageReceivedEvent event) {
            return helpEmbed(event, "Server Info Command").setDescription("**See your server's current stats.**").setColor(event.getGuild().getOwner().getColor() == null ? Color.ORANGE : event.getGuild().getOwner().getColor()).build();
        }
    });
    cr.registerAlias("serverinfo", "guildinfo");
}
Also used : SimpleCommand(net.kodehawa.mantarobot.modules.commands.SimpleCommand) Color(java.awt.Color) MantaroInfo(net.kodehawa.mantarobot.MantaroInfo) CommandProcessor(net.kodehawa.mantarobot.core.CommandProcessor) java.util(java.util) CommandStatsManager(net.kodehawa.mantarobot.commands.info.CommandStatsManager) Utils(net.kodehawa.mantarobot.utils.Utils) Module(net.kodehawa.mantarobot.modules.Module) MantaroShard(net.kodehawa.mantarobot.MantaroShard) StatsHelper.calculateDouble(net.kodehawa.mantarobot.commands.info.StatsHelper.calculateDouble) MantaroBot(net.kodehawa.mantarobot.MantaroBot) MessageBuilder(net.dv8tion.jda.core.MessageBuilder) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) Cursor(com.rethinkdb.net.Cursor) DBGuild(net.kodehawa.mantarobot.data.entities.DBGuild) Duration(java.time.Duration) JDA(net.dv8tion.jda.core.JDA) CommandRegistry(net.kodehawa.mantarobot.modules.CommandRegistry) ManagementFactory(java.lang.management.ManagementFactory) Command(net.kodehawa.mantarobot.modules.Command) TextChannelGround(net.kodehawa.mantarobot.commands.currency.TextChannelGround) CommandListener(net.kodehawa.mantarobot.core.listeners.command.CommandListener) GuildStatsManager(net.kodehawa.mantarobot.commands.info.GuildStatsManager) PostLoadEvent(net.kodehawa.mantarobot.modules.events.PostLoadEvent) JDAInfo(net.dv8tion.jda.core.JDAInfo) net.dv8tion.jda.core.entities(net.dv8tion.jda.core.entities) RateLimiter(net.kodehawa.mantarobot.commands.currency.RateLimiter) MantaroListener(net.kodehawa.mantarobot.core.listeners.MantaroListener) Category(net.kodehawa.mantarobot.modules.commands.base.Category) Instant(java.time.Instant) AsyncInfoMonitor(net.kodehawa.mantarobot.commands.info.AsyncInfoMonitor) Collectors(java.util.stream.Collectors) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) OnlineStatus(net.dv8tion.jda.core.OnlineStatus) TimeUnit(java.util.concurrent.TimeUnit) PlayerLibrary(com.sedmelluq.discord.lavaplayer.tools.PlayerLibrary) DurationFormatUtils(org.apache.commons.lang3.time.DurationFormatUtils) GuildData(net.kodehawa.mantarobot.data.entities.helpers.GuildData) EmoteReference(net.kodehawa.mantarobot.utils.commands.EmoteReference) DateTimeFormatter(java.time.format.DateTimeFormatter) CommandPermission(net.kodehawa.mantarobot.modules.commands.CommandPermission) MantaroData(net.kodehawa.mantarobot.data.MantaroData) HelpUtils.forType(net.kodehawa.mantarobot.commands.info.HelpUtils.forType) RethinkDB(com.rethinkdb.RethinkDB) StatsHelper.calculateInt(net.kodehawa.mantarobot.commands.info.StatsHelper.calculateInt) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) SimpleCommand(net.kodehawa.mantarobot.modules.commands.SimpleCommand) DBGuild(net.kodehawa.mantarobot.data.entities.DBGuild) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) SimpleCommand(net.kodehawa.mantarobot.modules.commands.SimpleCommand) Command(net.kodehawa.mantarobot.modules.Command)

Example 14 with SimpleCommand

use of net.kodehawa.mantarobot.modules.commands.SimpleCommand in project MantaroBot by Mantaro.

the class InfoCmds method ping.

@Command
public static void ping(CommandRegistry cr) {
    RateLimiter rateLimiter = new RateLimiter(TimeUnit.SECONDS, 5);
    cr.register("ping", new SimpleCommand(Category.INFO) {

        @Override
        protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
            if (!rateLimiter.process(event.getMember())) {
                event.getChannel().sendMessage(EmoteReference.ERROR + "Yikes! Seems like you're going too fast.").queue();
                return;
            }
            long start = System.currentTimeMillis();
            event.getChannel().sendTyping().queue(v -> {
                long ping = System.currentTimeMillis() - start;
                event.getChannel().sendMessage(EmoteReference.MEGA + "My ping: " + ping + " ms - " + ratePing(ping) + "  `Websocket:" + event.getJDA().getPing() + "ms`").queue();
                TextChannelGround.of(event).dropItemWithChance(5, 5);
            });
        }

        @Override
        public MessageEmbed help(GuildMessageReceivedEvent event) {
            return helpEmbed(event, "Ping Command").setDescription("**Plays Ping-Pong with Discord and prints out the result.**").build();
        }
    });
}
Also used : SimpleCommand(net.kodehawa.mantarobot.modules.commands.SimpleCommand) Color(java.awt.Color) MantaroInfo(net.kodehawa.mantarobot.MantaroInfo) CommandProcessor(net.kodehawa.mantarobot.core.CommandProcessor) java.util(java.util) CommandStatsManager(net.kodehawa.mantarobot.commands.info.CommandStatsManager) Utils(net.kodehawa.mantarobot.utils.Utils) Module(net.kodehawa.mantarobot.modules.Module) MantaroShard(net.kodehawa.mantarobot.MantaroShard) StatsHelper.calculateDouble(net.kodehawa.mantarobot.commands.info.StatsHelper.calculateDouble) MantaroBot(net.kodehawa.mantarobot.MantaroBot) MessageBuilder(net.dv8tion.jda.core.MessageBuilder) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) Cursor(com.rethinkdb.net.Cursor) DBGuild(net.kodehawa.mantarobot.data.entities.DBGuild) Duration(java.time.Duration) JDA(net.dv8tion.jda.core.JDA) CommandRegistry(net.kodehawa.mantarobot.modules.CommandRegistry) ManagementFactory(java.lang.management.ManagementFactory) Command(net.kodehawa.mantarobot.modules.Command) TextChannelGround(net.kodehawa.mantarobot.commands.currency.TextChannelGround) CommandListener(net.kodehawa.mantarobot.core.listeners.command.CommandListener) GuildStatsManager(net.kodehawa.mantarobot.commands.info.GuildStatsManager) PostLoadEvent(net.kodehawa.mantarobot.modules.events.PostLoadEvent) JDAInfo(net.dv8tion.jda.core.JDAInfo) net.dv8tion.jda.core.entities(net.dv8tion.jda.core.entities) RateLimiter(net.kodehawa.mantarobot.commands.currency.RateLimiter) MantaroListener(net.kodehawa.mantarobot.core.listeners.MantaroListener) Category(net.kodehawa.mantarobot.modules.commands.base.Category) Instant(java.time.Instant) AsyncInfoMonitor(net.kodehawa.mantarobot.commands.info.AsyncInfoMonitor) Collectors(java.util.stream.Collectors) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) OnlineStatus(net.dv8tion.jda.core.OnlineStatus) TimeUnit(java.util.concurrent.TimeUnit) PlayerLibrary(com.sedmelluq.discord.lavaplayer.tools.PlayerLibrary) DurationFormatUtils(org.apache.commons.lang3.time.DurationFormatUtils) GuildData(net.kodehawa.mantarobot.data.entities.helpers.GuildData) EmoteReference(net.kodehawa.mantarobot.utils.commands.EmoteReference) DateTimeFormatter(java.time.format.DateTimeFormatter) CommandPermission(net.kodehawa.mantarobot.modules.commands.CommandPermission) MantaroData(net.kodehawa.mantarobot.data.MantaroData) HelpUtils.forType(net.kodehawa.mantarobot.commands.info.HelpUtils.forType) RethinkDB(com.rethinkdb.RethinkDB) StatsHelper.calculateInt(net.kodehawa.mantarobot.commands.info.StatsHelper.calculateInt) SimpleCommand(net.kodehawa.mantarobot.modules.commands.SimpleCommand) RateLimiter(net.kodehawa.mantarobot.commands.currency.RateLimiter) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) SimpleCommand(net.kodehawa.mantarobot.modules.commands.SimpleCommand) Command(net.kodehawa.mantarobot.modules.Command)

Example 15 with SimpleCommand

use of net.kodehawa.mantarobot.modules.commands.SimpleCommand in project MantaroBot by Mantaro.

the class MusicCmds method queue.

@Command
public static void queue(CommandRegistry cr) {
    cr.register("queue", new SimpleCommand(Category.MUSIC) {

        @Override
        protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
            GuildMusicManager musicManager = MantaroBot.getInstance().getAudioManager().getMusicManager(event.getGuild());
            int page = 0;
            try {
                page = Math.max(Integer.parseInt(args[0]), 1);
            } catch (Exception ignored) {
            }
            if (content.startsWith("clear")) {
                if (!event.getMember().getVoiceState().inVoiceChannel() || !event.getMember().getVoiceState().getChannel().equals(event.getGuild().getAudioManager().getConnectedChannel())) {
                    sendNotConnectedToMyChannel(event.getChannel());
                    return;
                }
                if (isDJ(event.getMember())) {
                    event.getChannel().sendMessage(EmoteReference.CORRECT + "The server DJ has decided to clear the queue!").queue();
                    int TEMP_QUEUE_LENGTH = musicManager.getTrackScheduler().getQueue().size();
                    MantaroBot.getInstance().getAudioManager().getMusicManager(event.getGuild()).getTrackScheduler().getQueue().clear();
                    event.getChannel().sendMessage(EmoteReference.CORRECT + "Removed **" + TEMP_QUEUE_LENGTH + " songs** from the queue" + ".").queue();
                    MantaroBot.getInstance().getAudioManager().getMusicManager(event.getGuild()).getTrackScheduler().next(true);
                    return;
                }
                event.getChannel().sendMessage(EmoteReference.ERROR + "Either you're not connected to the VC or you're not the DJ.").queue();
                return;
            }
            embedForQueue(page, event, musicManager);
            TextChannelGround.of(event).dropItemWithChance(0, 10);
        }

        @Override
        public MessageEmbed help(GuildMessageReceivedEvent event) {
            return helpEmbed(event, "Queue Command").setDescription("**Either returns the current queue playing on the server or clears it.**").addField("Usage:", "`~>queue` - **Shows the queue**\n" + "`~>queue clear` - **Clears the queue**", false).build();
        }
    });
    cr.registerAlias("queue", "q");
}
Also used : SimpleCommand(net.kodehawa.mantarobot.modules.commands.SimpleCommand) GuildMusicManager(net.kodehawa.mantarobot.commands.music.GuildMusicManager) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) PermissionException(net.dv8tion.jda.core.exceptions.PermissionException) SimpleCommand(net.kodehawa.mantarobot.modules.commands.SimpleCommand) Command(net.kodehawa.mantarobot.modules.Command)

Aggregations

GuildMessageReceivedEvent (net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent)29 Command (net.kodehawa.mantarobot.modules.Command)29 SimpleCommand (net.kodehawa.mantarobot.modules.commands.SimpleCommand)29 MessageEmbed (net.dv8tion.jda.core.entities.MessageEmbed)22 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)13 MantaroData (net.kodehawa.mantarobot.data.MantaroData)12 CommandRegistry (net.kodehawa.mantarobot.modules.CommandRegistry)12 Module (net.kodehawa.mantarobot.modules.Module)12 Category (net.kodehawa.mantarobot.modules.commands.base.Category)12 EmoteReference (net.kodehawa.mantarobot.utils.commands.EmoteReference)12 Color (java.awt.Color)9 Collectors (java.util.stream.Collectors)9 TextChannelGround (net.kodehawa.mantarobot.commands.currency.TextChannelGround)9 PostLoadEvent (net.kodehawa.mantarobot.modules.events.PostLoadEvent)9 Utils (net.kodehawa.mantarobot.utils.Utils)9 TimeUnit (java.util.concurrent.TimeUnit)8 RateLimiter (net.kodehawa.mantarobot.commands.currency.RateLimiter)8 DBGuild (net.kodehawa.mantarobot.data.entities.DBGuild)8 MantaroBot (net.kodehawa.mantarobot.MantaroBot)7 GuildData (net.kodehawa.mantarobot.data.entities.helpers.GuildData)7