Search in sources :

Example 11 with SimpleCommand

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

the class MoneyCmds method slots.

@Subscribe
public void slots(CommandRegistry cr) {
    RateLimiter rateLimiter = new RateLimiter(TimeUnit.SECONDS, 35);
    String[] emotes = { "\uD83C\uDF52", "\uD83D\uDCB0", "\uD83D\uDCB2", "\uD83E\uDD55", "\uD83C\uDF7F", "\uD83C\uDF75", "\uD83C\uDFB6" };
    Random random = new SecureRandom();
    List<String> winCombinations = new ArrayList<>();
    for (String emote : emotes) {
        winCombinations.add(emote + emote + emote);
    }
    cr.register("slots", new SimpleCommand(Category.CURRENCY) {

        @Override
        protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
            Map<String, Optional<String>> opts = StringUtils.parse(args);
            long money = 50;
            // 25% raw chance of winning, completely random chance of winning on the other random iteration
            int slotsChance = 25;
            boolean isWin = false;
            boolean coinSelect = false;
            Player player = MantaroData.db().getPlayer(event.getAuthor());
            int amountN = 1;
            if (opts.containsKey("useticket")) {
                coinSelect = true;
            }
            if (opts.containsKey("amount") && opts.get("amount").isPresent()) {
                if (!coinSelect) {
                    event.getChannel().sendMessage(EmoteReference.ERROR + "You cannot specify how many tickets you're gonna use if you're not using tickets!").queue();
                    return;
                }
                String amount = opts.get("amount").get();
                if (amount.isEmpty()) {
                    event.getChannel().sendMessage(EmoteReference.ERROR + "You didn't specify the amount!").queue();
                    return;
                }
                try {
                    amountN = Integer.parseUnsignedInt(amount);
                } catch (NumberFormatException e) {
                    event.getChannel().sendMessage(EmoteReference.ERROR + "That is not a valid number!").queue();
                }
                if (player.getInventory().getAmount(Items.SLOT_COIN) < amountN) {
                    event.getChannel().sendMessage(EmoteReference.ERROR + "You don't have enough slots tickets!").queue();
                    return;
                }
                money += 58 * amountN;
            }
            if (args.length == 1 && !coinSelect) {
                try {
                    money = Math.abs(Integer.parseInt(args[0]));
                    if (money < 25) {
                        event.getChannel().sendMessage(EmoteReference.ERROR + "The minimum amount is 25!").queue();
                        return;
                    }
                    if (money > SLOTS_MAX_MONEY) {
                        event.getChannel().sendMessage(EmoteReference.WARNING + "This machine cannot dispense that much money!").queue();
                        return;
                    }
                } catch (NumberFormatException e) {
                    event.getChannel().sendMessage(EmoteReference.ERROR + "That's not a number!").queue();
                    return;
                }
            }
            if (player.getMoney() < money && !coinSelect) {
                event.getChannel().sendMessage(EmoteReference.SAD + "You don't have enough money to play the slots machine!").queue();
                return;
            }
            if (!handleDefaultRatelimit(rateLimiter, event.getAuthor(), event))
                return;
            if (coinSelect) {
                if (player.getInventory().containsItem(Items.SLOT_COIN)) {
                    player.getInventory().process(new ItemStack(Items.SLOT_COIN, -amountN));
                    player.saveAsync();
                    slotsChance = slotsChance + 10;
                } else {
                    event.getChannel().sendMessage(EmoteReference.SAD + "You wanted to use tickets but you don't have any :<").queue();
                    return;
                }
            } else {
                player.removeMoney(money);
                player.saveAsync();
            }
            StringBuilder message = new StringBuilder(String.format("%s**You used %s and rolled the slot machine!**\n\n", EmoteReference.DICE, coinSelect ? amountN + " slot ticket(s)" : money + " credits"));
            StringBuilder builder = new StringBuilder();
            for (int i = 0; i < 9; i++) {
                if (i > 1 && i % 3 == 0) {
                    builder.append("\n");
                }
                builder.append(emotes[random.nextInt(emotes.length)]);
            }
            String toSend = builder.toString();
            int gains = 0;
            String[] rows = toSend.split("\\r?\\n");
            if (random.nextInt(100) < slotsChance) {
                rows[1] = winCombinations.get(random.nextInt(winCombinations.size()));
            }
            if (winCombinations.contains(rows[1])) {
                isWin = true;
                gains = random.nextInt((int) Math.round(money * 1.76)) + 14;
            }
            rows[1] = rows[1] + " \u2b05";
            toSend = String.join("\n", rows);
            if (isWin) {
                message.append(toSend).append("\n\n").append(String.format("And you won **%d** credits and got to keep what you bet (%d credits)! Lucky! ", gains, money)).append(EmoteReference.POPPER);
                player.addMoney(gains + money);
                if ((gains + money) > SLOTS_MAX_MONEY) {
                    player.getData().addBadgeIfAbsent(Badge.LUCKY_SEVEN);
                }
                player.saveAsync();
            } else {
                message.append(toSend).append("\n\n").append("And you lost ").append(EmoteReference.SAD).append("\n").append("I hope you do better next time!");
            }
            message.append("\n");
            event.getChannel().sendMessage(message.toString()).queue();
        }

        @Override
        public MessageEmbed help(GuildMessageReceivedEvent event) {
            return helpEmbed(event, "Slots Command").setDescription("**Rolls the slot machine. Requires a default of 50 coins to roll.**").addField("Considerations", "You can gain a maximum of put credits * 1.76 coins from it.\n" + "You can use the `-useticket` argument to use a slot ticket (slightly bigger chance)", false).addField("Usage", "`~>slots` - Default one, 50 coins.\n" + "`~>slots <credits>` - Puts x credits on the slot machine. Max of " + SLOTS_MAX_MONEY + " coins.\n" + "`~>slots -useticket` - Rolls the slot machine with one slot coin.\n" + "You can specify the amount of tickets to use using `-amount` (for example `~>slots -useticket -amount 10`)", false).build();
        }
    });
}
Also used : Player(net.kodehawa.mantarobot.db.entities.Player) MessageEmbed(net.dv8tion.jda.core.entities.MessageEmbed) SecureRandom(java.security.SecureRandom) RateLimiter(net.kodehawa.mantarobot.utils.commands.RateLimiter) SecureRandom(java.security.SecureRandom) SimpleCommand(net.kodehawa.mantarobot.core.modules.commands.SimpleCommand) ItemStack(net.kodehawa.mantarobot.commands.currency.item.ItemStack) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) Subscribe(com.google.common.eventbus.Subscribe)

Example 12 with SimpleCommand

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

the class MoneyCmds method loot.

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

        final RateLimiter rateLimiter = new RateLimiter(TimeUnit.MINUTES, 5, true);

        final ZoneId zoneId = ZoneId.systemDefault();

        final Random r = new Random();

        @Override
        public void call(GuildMessageReceivedEvent event, String content, String[] args) {
            Player player = MantaroData.db().getPlayer(event.getMember());
            if (player.isLocked()) {
                event.getChannel().sendMessage(EmoteReference.ERROR + "You cannot loot now.").queue();
                return;
            }
            if (!handleDefaultRatelimit(rateLimiter, event.getAuthor(), event))
                return;
            LocalDate today = LocalDate.now(zoneId);
            LocalDate eventStart = today.withMonth(Month.DECEMBER.getValue()).withDayOfMonth(23);
            // Up to the 25th
            LocalDate eventStop = eventStart.plusDays(3);
            TextChannelGround ground = TextChannelGround.of(event);
            if (today.isEqual(eventStart) || (today.isAfter(eventStart) && today.isBefore(eventStop))) {
                ground.dropItemWithChance(Items.CHRISTMAS_TREE_SPECIAL, 4);
                ground.dropItemWithChance(Items.BELL_SPECIAL, 4);
            }
            if (r.nextInt(100) == 0) {
                // 1 in 100 chance of it dropping a loot crate.
                ground.dropItem(Items.LOOT_CRATE);
                if (player.getData().addBadgeIfAbsent(Badge.LUCKY))
                    player.saveAsync();
            }
            List<ItemStack> loot = ground.collectItems();
            int moneyFound = ground.collectMoney() + Math.max(0, r.nextInt(50) - 10);
            if (MantaroData.db().getUser(event.getMember()).isPremium() && moneyFound > 0) {
                moneyFound = moneyFound + random.nextInt(moneyFound);
            }
            if (!loot.isEmpty()) {
                String s = ItemStack.toString(ItemStack.reduce(loot));
                String overflow;
                if (player.getInventory().merge(loot))
                    overflow = "But you already had too many items, so you decided to throw away the excess. ";
                else
                    overflow = "";
                if (moneyFound != 0) {
                    if (player.addMoney(moneyFound)) {
                        event.getChannel().sendMessage(String.format("%sDigging through messages, you found %s, along with **$%d credits!** %s", EmoteReference.POPPER, s, moneyFound, overflow)).queue();
                    } else {
                        event.getChannel().sendMessage(String.format("%sDigging through messages, you found %s, along with **$%d credits.** " + "%sBut you already had too many credits.", EmoteReference.POPPER, s, moneyFound, overflow)).queue();
                    }
                } else {
                    event.getChannel().sendMessage(EmoteReference.MEGA + "Digging through messages, you found " + s + ". " + overflow).queue();
                }
            } else {
                if (moneyFound != 0) {
                    if (player.addMoney(moneyFound)) {
                        event.getChannel().sendMessage(EmoteReference.POPPER + "Digging through messages, you found **$" + moneyFound + " credits!**").queue();
                    } else {
                        event.getChannel().sendMessage(String.format("%sDigging through messages, you found **$%d credits.** " + "But you already had too many credits.", EmoteReference.POPPER, moneyFound)).queue();
                    }
                } else {
                    String msg = "Digging through messages, you found nothing but dust";
                    if (r.nextInt(100) > 93) {
                        msg += "\n" + "Seems like you've got so much dust here... You might want to clean this up before it gets too messy!";
                    }
                    event.getChannel().sendMessage(EmoteReference.SAD + msg).queue();
                }
            }
            player.saveAsync();
        }

        @Override
        public MessageEmbed help(GuildMessageReceivedEvent event) {
            return helpEmbed(event, "Loot command").setDescription("**Loot the current chat for items, for usage in Mantaro's currency system.**\n" + "Currently, there are ``" + Items.ALL.length + "`` items available in chance," + "in which you have a `random chance` of getting one or more.").addField("Usage", "~>loot", false).build();
        }
    });
}
Also used : Player(net.kodehawa.mantarobot.db.entities.Player) MessageEmbed(net.dv8tion.jda.core.entities.MessageEmbed) ZoneId(java.time.ZoneId) LocalDate(java.time.LocalDate) TextChannelGround(net.kodehawa.mantarobot.commands.currency.TextChannelGround) RateLimiter(net.kodehawa.mantarobot.utils.commands.RateLimiter) SimpleCommand(net.kodehawa.mantarobot.core.modules.commands.SimpleCommand) SecureRandom(java.security.SecureRandom) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) Subscribe(com.google.common.eventbus.Subscribe)

Example 13 with SimpleCommand

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

the class MusicCmds method queue.

@Subscribe
public 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 (!isInConditionTo(event)) {
                    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().stop();
                    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).addField("Considerations", "If music is playing at 2x speed please do `~>opts musicspeedup fix`", false).build();
        }
    });
    cr.registerAlias("queue", "q");
}
Also used : SimpleCommand(net.kodehawa.mantarobot.core.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) Subscribe(com.google.common.eventbus.Subscribe)

Example 14 with SimpleCommand

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

the class MusicCmds method nextSong.

@Subscribe
public void nextSong(CommandRegistry cr) {
    cr.register("ns", new SimpleCommand(Category.MUSIC) {

        @Override
        protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
            GuildMusicManager musicManager = MantaroBot.getInstance().getAudioManager().getMusicManager(event.getGuild());
            TrackScheduler scheduler = musicManager.getTrackScheduler();
            AudioTrack next = scheduler.getQueue().peek();
            if (next == null) {
                event.getChannel().sendMessage(EmoteReference.TALKING + "Ow, there isn't any song next").queue();
            } else {
                event.getChannel().sendMessage(EmoteReference.MEGA + "Next song in queue: **" + next.getInfo().title + "** (" + Utils.getDurationMinutes(next.getDuration()) + ")" + " | *Total songs in queue: " + scheduler.getQueue().size() + "*").queue();
            }
        }

        @Override
        public MessageEmbed help(GuildMessageReceivedEvent event) {
            return helpEmbed(event, "Next Song Command").addField("Description", "**Shows the next song in queue!**", false).build();
        }
    });
    cr.registerAlias("ns", "nextsong");
}
Also used : SimpleCommand(net.kodehawa.mantarobot.core.modules.commands.SimpleCommand) GuildMusicManager(net.kodehawa.mantarobot.commands.music.GuildMusicManager) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) TrackScheduler(net.kodehawa.mantarobot.commands.music.requester.TrackScheduler) Subscribe(com.google.common.eventbus.Subscribe)

Example 15 with SimpleCommand

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

the class MuteCmds method mute.

@Subscribe
public void mute(CommandRegistry registry) {
    Command mute = registry.register("mute", new SimpleCommand(Category.MODERATION) {

        @Override
        protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
            if (!event.getMember().hasPermission(Permission.KICK_MEMBERS) || !event.getMember().hasPermission(Permission.BAN_MEMBERS)) {
                event.getChannel().sendMessage(EmoteReference.ERROR + "You need to have either ban or kick members permission to mute!").queue();
                return;
            }
            ManagedDatabase db = MantaroData.db();
            DBGuild dbGuild = db.getGuild(event.getGuild());
            GuildData guildData = dbGuild.getData();
            String reason = "Not specified";
            Map<String, Optional<String>> opts = br.com.brjdevs.java.utils.texts.StringUtils.parse(args);
            if (guildData.getMutedRole() == null) {
                event.getChannel().sendMessage(EmoteReference.ERROR + "The mute role is not set in this server, you can set it by doing `~>opts muterole set <role>`").queue();
                return;
            }
            Role mutedRole = event.getGuild().getRoleById(guildData.getMutedRole());
            if (mutedRole == null) {
                event.getChannel().sendMessage(EmoteReference.ERROR + "The previously configured mute role on this server is now non-existent!").queue();
                return;
            }
            if (args.length > 1) {
                reason = StringUtils.splitArgs(content, 2)[1];
            }
            if (event.getMessage().getMentionedUsers().isEmpty()) {
                event.getChannel().sendMessage(EmoteReference.ERROR + "You need to mention at least one user to mute.").queue();
                return;
            }
            if (!event.getGuild().getSelfMember().hasPermission(event.getChannel(), Permission.MANAGE_ROLES)) {
                event.getChannel().sendMessage(EmoteReference.ERROR + "I don't have permissions to administrate roles on this server!").queue();
                return;
            }
            // Regex from: Fabricio20
            final String finalReason = timePattern.matcher(reason).replaceAll("");
            MantaroObj data = db.getMantaroData();
            event.getMessage().getMentionedUsers().forEach(user -> {
                Member m = event.getGuild().getMember(user);
                long time = guildData.getSetModTimeout() > 0 ? System.currentTimeMillis() + guildData.getSetModTimeout() : 0L;
                if (opts.containsKey("time")) {
                    if (!opts.get("time").isPresent() || opts.get("time").get().isEmpty()) {
                        event.getChannel().sendMessage(EmoteReference.WARNING + "You wanted time but didn't specify for how long!").queue();
                        return;
                    }
                    time = System.currentTimeMillis() + Utils.parseTime(opts.get("time").get());
                    if (time > System.currentTimeMillis() + TimeUnit.DAYS.toMillis(10)) {
                        // smh smh smfh god fuck rethinkdb just
                        // dont
                        event.getChannel().sendMessage(EmoteReference.ERROR + "Too long...").queue();
                        // smh
                        return;
                    }
                    if (time < 0) {
                        event.getChannel().sendMessage("You cannot mute someone for negative time!").queue();
                        return;
                    }
                    data.getMutes().put(user.getIdLong(), Pair.of(event.getGuild().getId(), time));
                    data.save();
                    dbGuild.save();
                } else {
                    if (time > 0) {
                        if (time > System.currentTimeMillis() + TimeUnit.DAYS.toMillis(10)) {
                            event.getChannel().sendMessage(EmoteReference.ERROR + "The default mute timeout length is too long (Maximum: 10 days)...").queue();
                            return;
                        }
                        data.getMutes().put(user.getIdLong(), Pair.of(event.getGuild().getId(), time));
                        data.save();
                        dbGuild.save();
                    } else {
                        event.getChannel().sendMessage(EmoteReference.ERROR + "You didn't specify any time!").queue();
                        return;
                    }
                }
                if (m.getRoles().contains(mutedRole)) {
                    event.getChannel().sendMessage(EmoteReference.WARNING + "This user already has a mute role assigned. Please do `~>unmute` to unmute them.").queue();
                    return;
                }
                if (!event.getGuild().getSelfMember().canInteract(m)) {
                    event.getChannel().sendMessage(EmoteReference.ERROR + "I cannot assign the mute role to this user because they're in a higher hierarchy than me, or the role is in a higher hierarchy!").queue();
                    return;
                }
                if (!event.getMember().canInteract(m)) {
                    event.getChannel().sendMessage(EmoteReference.ERROR + "I cannot assign the mute role to this user because they're in a higher hierarchy than me, or the role is in a higher hierarchy than you!").queue();
                    return;
                }
                final DBGuild dbg = db.getGuild(event.getGuild());
                event.getGuild().getController().addSingleRoleToMember(m, mutedRole).reason(String.format("Muted by %#s for %s: %s", event.getAuthor(), Utils.formatDuration(time - System.currentTimeMillis()), finalReason)).queue();
                event.getChannel().sendMessage(EmoteReference.CORRECT + "Added mute role to **" + m.getEffectiveName() + (time > 0 ? "** for around " + Utils.getHumanizedTime(time - System.currentTimeMillis()) : "**")).queue();
                dbg.getData().setCases(dbg.getData().getCases() + 1);
                dbg.saveAsync();
                ModLog.log(event.getMember(), user, finalReason, ModLog.ModAction.MUTE, dbg.getData().getCases());
            });
        }

        @Override
        public MessageEmbed help(GuildMessageReceivedEvent event) {
            return helpEmbed(event, "Mute").setDescription("**Mutes the specified users**").addField("Usage", "`~>mute <user> <reason> [-time <time>]` - Mutes the specified users.", false).addField("Parameters", "`users` - The users to mute. Needs to be mentions.\n" + "`[-time <time>]` - The time to mute an user for. For example `~>mute @Natan#1289 wew, nice -time 1m20s` will mute Natan for 1 minute and 20 seconds.", false).addField("Considerations", "To unmute an user, do `~>unmute`.", 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 mute for one day and one hour.**", false).build();
        }
    });
    mute.addOption("defaultmutetimeout:set", new Option("Default mute timeout", "Sets the default mute timeout for ~>mute.\n" + "This command will set the timeout of ~>mute to a fixed value **unless you specify another time in the command**\n" + "**Example:** `~>opts defaultmutetimeout set 1m20s`\n" + "**Considerations:** Time is in 1m20s or 1h10m3s format, for example.", OptionType.GUILD).setAction(((event, args) -> {
        if (args.length == 0) {
            event.getChannel().sendMessage(EmoteReference.ERROR + "You have to specify a timeout in the format of 1m20s, for example.").queue();
            return;
        }
        if (!(args[0]).matches("(?:(\\d+)h)?(?:(\\d+)m)?(?:(\\d+)s)?")) {
            event.getChannel().sendMessage(EmoteReference.ERROR + "Wrong time format. You have to specify a timeout in the format of 1m20s, for example.").queue();
            return;
        }
        long timeoutToSet = Utils.parseTime(args[0]);
        long time = System.currentTimeMillis() + timeoutToSet;
        if (time > System.currentTimeMillis() + TimeUnit.DAYS.toMillis(10)) {
            event.getChannel().sendMessage(EmoteReference.ERROR + "Too long...").queue();
            return;
        }
        if (time < 0) {
            event.getChannel().sendMessage("You cannot mute someone for negative time!").queue();
            return;
        }
        DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
        GuildData guildData = dbGuild.getData();
        guildData.setSetModTimeout(timeoutToSet);
        dbGuild.save();
        event.getChannel().sendMessage(EmoteReference.CORRECT + "Successfully set mod action timeout to `" + args[0] + "` (" + timeoutToSet + "ms)").queue();
    })).setShortDescription("Sets the default timeout for the ~>mute command"));
    mute.addOption("defaultmutetimeout:reset", new Option("Default mute timeout reset", "Resets the default mute timeout which was set previously with `defaultmusictimeout set`", OptionType.GUILD).setAction((event -> {
        DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
        GuildData guildData = dbGuild.getData();
        guildData.setSetModTimeout(0L);
        dbGuild.save();
        event.getChannel().sendMessage(EmoteReference.CORRECT + "Successfully reset timeout.").queue();
    })).setShortDescription("Resets the default mute timeout."));
    mute.addOption("muterole:set", new Option("Mute role set", "Sets this guilds mute role to apply on the ~>mute command.\n" + "To use this command you need to specify a role name. *In case the name contains spaces, the name should" + " be wrapped in quotation marks", OptionType.COMMAND).setAction((event, args) -> {
        if (args.length < 1) {
            OptsCmd.onHelp(event);
            return;
        }
        String roleName = String.join(" ", args);
        DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
        GuildData guildData = dbGuild.getData();
        List<Role> roleList = event.getGuild().getRolesByName(roleName, true);
        if (roleList.size() == 0) {
            event.getChannel().sendMessage(EmoteReference.ERROR + "I didn't find a role with that name!").queue();
        } else if (roleList.size() == 1) {
            Role role = roleList.get(0);
            guildData.setMutedRole(role.getId());
            dbGuild.saveAsync();
            event.getChannel().sendMessage(EmoteReference.OK + "Set mute role to **" + roleName + "**").queue();
        } else {
            DiscordUtils.selectList(event, roleList, role -> String.format("%s (ID: %s)  | Position: %s", role.getName(), role.getId(), role.getPosition()), s -> OptsCmd.getOpts().baseEmbed(event, "Select the Mute Role:").setDescription(s).build(), role -> {
                guildData.setMutedRole(role.getId());
                dbGuild.saveAsync();
                event.getChannel().sendMessage(EmoteReference.OK + "Set mute role to **" + roleName + "**").queue();
            });
        }
    }).setShortDescription("Sets this guilds mute role to apply on the ~>mute command"));
    mute.addOption("muterole:unbind", new Option("Mute Role unbind", "Resets the current value set for the mute role", OptionType.GENERAL).setAction(event -> {
        DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
        GuildData guildData = dbGuild.getData();
        guildData.setMutedRole(null);
        dbGuild.saveAsync();
        event.getChannel().sendMessage(EmoteReference.OK + "Correctly reset the mute role.").queue();
    }).setShortDescription("Resets the current value set for the mute role."));
}
Also used : Module(net.kodehawa.mantarobot.core.modules.Module) Command(net.kodehawa.mantarobot.core.modules.commands.base.Command) StringUtils(net.kodehawa.mantarobot.utils.StringUtils) Member(net.dv8tion.jda.core.entities.Member) Pair(net.kodehawa.mantarobot.utils.Pair) Utils(net.kodehawa.mantarobot.utils.Utils) DiscordUtils(net.kodehawa.mantarobot.utils.DiscordUtils) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) Permission(net.dv8tion.jda.core.Permission) CommandRegistry(net.kodehawa.mantarobot.core.CommandRegistry) Map(java.util.Map) Subscribe(com.google.common.eventbus.Subscribe) SimpleCommand(net.kodehawa.mantarobot.core.modules.commands.SimpleCommand) OptionType(net.kodehawa.mantarobot.options.core.OptionType) MessageEmbed(net.dv8tion.jda.core.entities.MessageEmbed) Role(net.dv8tion.jda.core.entities.Role) Category(net.kodehawa.mantarobot.core.modules.commands.base.Category) DBGuild(net.kodehawa.mantarobot.db.entities.DBGuild) TimeUnit(java.util.concurrent.TimeUnit) Option(net.kodehawa.mantarobot.options.core.Option) ModLog(net.kodehawa.mantarobot.commands.moderation.ModLog) List(java.util.List) ManagedDatabase(net.kodehawa.mantarobot.db.ManagedDatabase) CommandPermission(net.kodehawa.mantarobot.core.modules.commands.base.CommandPermission) MantaroObj(net.kodehawa.mantarobot.db.entities.MantaroObj) GuildData(net.kodehawa.mantarobot.db.entities.helpers.GuildData) EmoteReference(net.kodehawa.mantarobot.utils.commands.EmoteReference) MantaroData(net.kodehawa.mantarobot.data.MantaroData) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) GuildData(net.kodehawa.mantarobot.db.entities.helpers.GuildData) MessageEmbed(net.dv8tion.jda.core.entities.MessageEmbed) MantaroObj(net.kodehawa.mantarobot.db.entities.MantaroObj) Role(net.dv8tion.jda.core.entities.Role) DBGuild(net.kodehawa.mantarobot.db.entities.DBGuild) SimpleCommand(net.kodehawa.mantarobot.core.modules.commands.SimpleCommand) Command(net.kodehawa.mantarobot.core.modules.commands.base.Command) SimpleCommand(net.kodehawa.mantarobot.core.modules.commands.SimpleCommand) Option(net.kodehawa.mantarobot.options.core.Option) ManagedDatabase(net.kodehawa.mantarobot.db.ManagedDatabase) Map(java.util.Map) Member(net.dv8tion.jda.core.entities.Member) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) Subscribe(com.google.common.eventbus.Subscribe)

Aggregations

Subscribe (com.google.common.eventbus.Subscribe)39 SimpleCommand (net.kodehawa.mantarobot.core.modules.commands.SimpleCommand)39 GuildMessageReceivedEvent (net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent)37 MessageEmbed (net.dv8tion.jda.core.entities.MessageEmbed)25 EmoteReference (net.kodehawa.mantarobot.utils.commands.EmoteReference)17 MantaroData (net.kodehawa.mantarobot.data.MantaroData)16 CommandRegistry (net.kodehawa.mantarobot.core.CommandRegistry)15 Module (net.kodehawa.mantarobot.core.modules.Module)15 Category (net.kodehawa.mantarobot.core.modules.commands.base.Category)15 List (java.util.List)14 Utils (net.kodehawa.mantarobot.utils.Utils)14 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)12 DBGuild (net.kodehawa.mantarobot.db.entities.DBGuild)12 TimeUnit (java.util.concurrent.TimeUnit)11 Player (net.kodehawa.mantarobot.db.entities.Player)11 DiscordUtils (net.kodehawa.mantarobot.utils.DiscordUtils)11 MantaroBot (net.kodehawa.mantarobot.MantaroBot)10 RateLimiter (net.kodehawa.mantarobot.utils.commands.RateLimiter)10 Collectors (java.util.stream.Collectors)9 User (net.dv8tion.jda.core.entities.User)9