Search in sources :

Example 31 with SimpleCommand

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

the class MoneyCmds method gamble.

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

        final RateLimiter rateLimiter = new RateLimiter(TimeUnit.SECONDS, 20, true);

        SecureRandom r = new SecureRandom();

        @Override
        public void call(GuildMessageReceivedEvent event, String content, String[] args) {
            Player player = MantaroData.db().getPlayer(event.getMember());
            if (!handleDefaultRatelimit(rateLimiter, event.getAuthor(), event))
                return;
            if (player.getMoney() <= 0) {
                event.getChannel().sendMessage(EmoteReference.ERROR2 + "You're broke. Search for some credits first!").queue();
                return;
            }
            if (player.getMoney() > GAMBLE_ABSOLUTE_MAX_MONEY) {
                event.getChannel().sendMessage(EmoteReference.ERROR + "You have too much money! Maybe transfer or buy items? Now you can also use `~>slots`" + " for all your gambling needs! Thanks for not breaking the local bank. *(Gamble limit: " + GAMBLE_ABSOLUTE_MAX_MONEY + ")*").queue();
                return;
            }
            double multiplier;
            long i;
            int luck;
            try {
                switch(content) {
                    case "all":
                    case "everything":
                        i = player.getMoney();
                        multiplier = 1.3d + (r.nextInt(1450) / 1000d);
                        luck = 21 + (int) (multiplier * 13) + r.nextInt(18);
                        break;
                    case "half":
                        i = player.getMoney() == 1 ? 1 : player.getMoney() / 2;
                        multiplier = 1.2d + (r.nextInt(1350) / 1000d);
                        luck = 19 + (int) (multiplier * 13) + r.nextInt(18);
                        break;
                    case "quarter":
                        i = player.getMoney() == 1 ? 1 : player.getMoney() / 4;
                        multiplier = 1.1d + (r.nextInt(1250) / 1000d);
                        luck = 18 + (int) (multiplier * 12) + r.nextInt(18);
                        break;
                    default:
                        i = content.endsWith("%") ? Math.round(PERCENT_FORMAT.get().parse(content).doubleValue() * player.getMoney()) : Long.parseLong(content);
                        if (i > player.getMoney() || i < 0)
                            throw new UnsupportedOperationException();
                        multiplier = 1.1d + (i / player.getMoney() * r.nextInt(1300) / 1000d);
                        luck = 17 + (int) (multiplier * 13) + r.nextInt(12);
                        break;
                }
            } catch (NumberFormatException e) {
                event.getChannel().sendMessage(EmoteReference.ERROR2 + "Please type a valid number less than or equal to your current balance or" + " `all` to gamble all your credits.").queue();
                return;
            } catch (UnsupportedOperationException e) {
                event.getChannel().sendMessage(EmoteReference.ERROR2 + "Please type a value within your balance.").queue();
                return;
            } catch (ParseException e) {
                event.getChannel().sendMessage(EmoteReference.ERROR2 + "Please type a valid percentage value.").queue();
                return;
            }
            User user = event.getAuthor();
            long gains = (long) (i * multiplier);
            gains = Math.round(gains * 0.45);
            final int finalLuck = luck;
            final long finalGains = gains;
            if (i >= Integer.MAX_VALUE / 4) {
                player.setLocked(true);
                player.save();
                event.getChannel().sendMessage(String.format("%sYou're about to bet **%d** credits (which seems to be a lot). " + "Are you sure? Type **yes** to continue and **no** otherwise.", EmoteReference.WARNING, i)).queue();
                InteractiveOperations.create(event.getChannel(), 30, new InteractiveOperation() {

                    @Override
                    public int run(GuildMessageReceivedEvent e) {
                        if (e.getAuthor().getId().equals(user.getId())) {
                            if (e.getMessage().getContentRaw().equalsIgnoreCase("yes")) {
                                proceedGamble(event, player, finalLuck, random, i, finalGains);
                                return COMPLETED;
                            } else if (e.getMessage().getContentRaw().equalsIgnoreCase("no")) {
                                e.getChannel().sendMessage(EmoteReference.ZAP + "Cancelled bet.").queue();
                                player.setLocked(false);
                                player.saveAsync();
                                return COMPLETED;
                            }
                        }
                        return IGNORED;
                    }

                    @Override
                    public void onExpire() {
                        event.getChannel().sendMessage(EmoteReference.ERROR + "Time to complete the operation has ran out.").queue();
                        player.setLocked(false);
                        player.saveAsync();
                    }
                });
                return;
            }
            proceedGamble(event, player, luck, random, i, gains);
        }

        @Override
        public MessageEmbed help(GuildMessageReceivedEvent event) {
            return helpEmbed(event, "Gamble command").setDescription("Gambles your money").addField("Usage", "~>gamble <all/half/quarter> or ~>gamble <amount>\n" + "You can also use percentages now, for example `~>gamble 35%`", false).build();
        }
    });
}
Also used : InteractiveOperation(net.kodehawa.mantarobot.core.listeners.operations.core.InteractiveOperation) Player(net.kodehawa.mantarobot.db.entities.Player) User(net.dv8tion.jda.core.entities.User) MessageEmbed(net.dv8tion.jda.core.entities.MessageEmbed) SecureRandom(java.security.SecureRandom) RateLimiter(net.kodehawa.mantarobot.utils.commands.RateLimiter) SimpleCommand(net.kodehawa.mantarobot.core.modules.commands.SimpleCommand) ParseException(java.text.ParseException) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) Subscribe(com.google.common.eventbus.Subscribe)

Example 32 with SimpleCommand

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

the class MoneyCmds method balance.

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

        @Override
        protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
            User user = event.getAuthor();
            boolean isExternal = false;
            List<Member> found = FinderUtil.findMembers(content, event.getGuild());
            if (found.isEmpty() && !content.isEmpty()) {
                event.getChannel().sendMessage(EmoteReference.ERROR + "Your search yielded no results :(").queue();
                return;
            }
            if (found.size() > 1 && !content.isEmpty()) {
                event.getChannel().sendMessage(String.format("%sToo many users found, maybe refine your search? (ex. use name#discriminator)\n" + "**Users found:** %s", EmoteReference.THINKING, found.stream().map(m -> m.getUser().getName() + "#" + m.getUser().getDiscriminator()).collect(Collectors.joining(", ")))).queue();
                return;
            }
            if (found.size() == 1) {
                user = found.get(0).getUser();
                isExternal = true;
            }
            long balance = MantaroData.db().getPlayer(user).getMoney();
            event.getChannel().sendMessage(EmoteReference.DIAMOND + (isExternal ? user.getName() + "'s balance is: **$" : "Your balance is: **$") + balance + "**").queue();
        }

        @Override
        public MessageEmbed help(GuildMessageReceivedEvent event) {
            return baseEmbed(event, "Balance command").setDescription("**Shows your current balance or another person's balance.**").build();
        }
    });
    cr.registerAlias("balance", "credits");
    cr.registerAlias("balance", "bal");
}
Also used : Items(net.kodehawa.mantarobot.commands.currency.item.Items) Badge(net.kodehawa.mantarobot.commands.currency.profile.Badge) Module(net.kodehawa.mantarobot.core.modules.Module) java.util(java.util) Command(net.kodehawa.mantarobot.core.modules.commands.base.Command) Member(net.dv8tion.jda.core.entities.Member) PlayerData(net.kodehawa.mantarobot.db.entities.helpers.PlayerData) Utils(net.kodehawa.mantarobot.utils.Utils) RateLimiter(net.kodehawa.mantarobot.utils.commands.RateLimiter) NumberFormat(java.text.NumberFormat) InteractiveOperation(net.kodehawa.mantarobot.core.listeners.operations.core.InteractiveOperation) MantaroBot(net.kodehawa.mantarobot.MantaroBot) SecureRandom(java.security.SecureRandom) RethinkDB.r(com.rethinkdb.RethinkDB.r) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) Cursor(com.rethinkdb.net.Cursor) ITreeCommand(net.kodehawa.mantarobot.core.modules.commands.base.ITreeCommand) Pair(org.apache.commons.lang3.tuple.Pair) CommandRegistry(net.kodehawa.mantarobot.core.CommandRegistry) Utils.handleDefaultRatelimit(net.kodehawa.mantarobot.utils.Utils.handleDefaultRatelimit) OptArgs(com.rethinkdb.model.OptArgs) StringUtils(br.com.brjdevs.java.utils.texts.StringUtils) Subscribe(com.google.common.eventbus.Subscribe) SimpleCommand(net.kodehawa.mantarobot.core.modules.commands.SimpleCommand) ParseException(java.text.ParseException) MessageEmbed(net.dv8tion.jda.core.entities.MessageEmbed) ItemStack(net.kodehawa.mantarobot.commands.currency.item.ItemStack) TextChannelGround(net.kodehawa.mantarobot.commands.currency.TextChannelGround) Connection(com.rethinkdb.net.Connection) Player(net.kodehawa.mantarobot.db.entities.Player) SubCommand(net.kodehawa.mantarobot.core.modules.commands.SubCommand) InteractiveOperations(net.kodehawa.mantarobot.core.listeners.operations.InteractiveOperations) Month(java.time.Month) Category(net.kodehawa.mantarobot.core.modules.commands.base.Category) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) TreeCommand(net.kodehawa.mantarobot.core.modules.commands.TreeCommand) TimeUnit(java.util.concurrent.TimeUnit) User(net.dv8tion.jda.core.entities.User) EmoteReference(net.kodehawa.mantarobot.utils.commands.EmoteReference) LocalDate(java.time.LocalDate) MantaroData(net.kodehawa.mantarobot.data.MantaroData) FinderUtil(com.jagrosh.jdautilities.utils.FinderUtil) OrderBy(com.rethinkdb.gen.ast.OrderBy) User(net.dv8tion.jda.core.entities.User) MessageEmbed(net.dv8tion.jda.core.entities.MessageEmbed) SimpleCommand(net.kodehawa.mantarobot.core.modules.commands.SimpleCommand) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) Subscribe(com.google.common.eventbus.Subscribe)

Example 33 with SimpleCommand

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

the class MoneyCmds method daily.

@Subscribe
public void daily(CommandRegistry cr) {
    final RateLimiter rateLimiter = new RateLimiter(TimeUnit.HOURS, 24);
    Random r = new Random();
    cr.register("daily", new SimpleCommand(Category.CURRENCY) {

        @Override
        public void call(GuildMessageReceivedEvent event, String content, String[] args) {
            long money = 150L;
            User mentionedUser = null;
            List<User> mentioned = event.getMessage().getMentionedUsers();
            if (!mentioned.isEmpty())
                mentionedUser = event.getMessage().getMentionedUsers().get(0);
            if (mentionedUser != null && mentionedUser.isBot()) {
                event.getChannel().sendMessage(EmoteReference.ERROR + "You cannot transfer your daily to a bot!").queue();
                return;
            }
            Player player = mentionedUser != null ? MantaroData.db().getPlayer(event.getGuild().getMember(mentionedUser)) : MantaroData.db().getPlayer(event.getMember());
            if (player.isLocked()) {
                event.getChannel().sendMessage(EmoteReference.ERROR + (mentionedUser != null ? "That user cannot receive daily credits now." : "You cannot get daily credits now.")).queue();
                return;
            }
            if (!handleDefaultRatelimit(rateLimiter, event.getAuthor(), event))
                return;
            PlayerData playerData = player.getData();
            String streak;
            String playerId = player.getUserId();
            if (playerId.equals(event.getAuthor().getId())) {
                if (System.currentTimeMillis() - playerData.getLastDailyAt() < TimeUnit.HOURS.toMillis(50)) {
                    playerData.setDailyStreak(playerData.getDailyStreak() + 1);
                    streak = "Streak up! Current streak: `" + playerData.getDailyStreak() + "x`";
                } else {
                    if (playerData.getDailyStreak() == 0) {
                        streak = "First time claiming daily, have fun! (Come back for your streak tomorrow!)";
                    } else {
                        streak = String.format("2+ days have passed since your last daily, so your streak got reset :(\nOld streak: `%dx`", playerData.getDailyStreak());
                    }
                    playerData.setDailyStreak(1);
                }
                if (playerData.getDailyStreak() > 5) {
                    int bonus = 150;
                    if (playerData.getDailyStreak() > 15)
                        bonus += Math.min(700, Math.floor(150 * playerData.getDailyStreak() / 15));
                    streak += "\nYou won a bonus of $" + bonus + " for claiming your daily for 5 days in a row or more! (Included on the money shown!)";
                    money += bonus;
                }
                if (playerData.getDailyStreak() > 10) {
                    playerData.addBadgeIfAbsent(Badge.CLAIMER);
                }
                if (playerData.getDailyStreak() > 100) {
                    playerData.addBadgeIfAbsent(Badge.BIG_CLAIMER);
                }
            } else {
                Player authorPlayer = MantaroData.db().getPlayer(event.getAuthor());
                PlayerData authorPlayerData = authorPlayer.getData();
                if (System.currentTimeMillis() - authorPlayerData.getLastDailyAt() < TimeUnit.HOURS.toMillis(50)) {
                    authorPlayerData.setDailyStreak(authorPlayerData.getDailyStreak() + 1);
                    streak = String.format("Streak up! Current streak: `%dx`.\n*The streak was applied to your profile!*", authorPlayerData.getDailyStreak());
                } else {
                    if (authorPlayerData.getDailyStreak() == 0) {
                        streak = "First time claiming daily, have fun! (Come back for your streak tomorrow!)";
                    } else {
                        streak = String.format("2+ days have passed since your last daily, so your streak got reset :(\nOld streak: `%dx`", authorPlayerData.getDailyStreak());
                    }
                    authorPlayerData.setDailyStreak(1);
                }
                if (authorPlayerData.getDailyStreak() > 5) {
                    int bonus = 150;
                    if (authorPlayerData.getDailyStreak() > 15)
                        bonus += Math.min(700, Math.floor(150 * authorPlayerData.getDailyStreak() / 15));
                    ;
                    streak += "\n" + (mentionedUser == null ? "You" : mentionedUser.getName()) + " won a bonus of $" + bonus + " for claiming your daily for 5 days in a row or more! (Included on the money shown!)";
                    money += bonus;
                }
                if (authorPlayerData.getDailyStreak() > 10) {
                    authorPlayerData.addBadgeIfAbsent(Badge.CLAIMER);
                }
                if (authorPlayerData.getDailyStreak() > 100) {
                    playerData.addBadgeIfAbsent(Badge.BIG_CLAIMER);
                }
                authorPlayerData.setLastDailyAt(System.currentTimeMillis());
                authorPlayer.save();
            }
            if (mentionedUser != null && !mentionedUser.getId().equals(event.getAuthor().getId())) {
                money = money + r.nextInt(90);
                if (mentionedUser.getId().equals(player.getData().getMarriedWith())) {
                    if (player.getInventory().containsItem(Items.RING)) {
                        money = money + r.nextInt(70);
                    }
                }
                player.addMoney(money);
                playerData.setLastDailyAt(System.currentTimeMillis());
                player.save();
                event.getChannel().sendMessage(EmoteReference.CORRECT + "I gave your **$" + money + "** daily credits to " + mentionedUser.getName() + "\n\n" + streak).queue();
                return;
            }
            player.addMoney(money);
            playerData.setLastDailyAt(System.currentTimeMillis());
            player.save();
            event.getChannel().sendMessage(EmoteReference.CORRECT + "You got **$" + money + "** daily credits.\n\n" + streak).queue();
        }

        @Override
        public MessageEmbed help(GuildMessageReceivedEvent event) {
            return helpEmbed(event, "Daily command").setDescription("**Gives you $150 credits per day (or between 150 and 180 if you transfer it to another person)**.\n" + "This command gives a reward for claiming it every day.").build();
        }
    });
    cr.registerAlias("daily", "dailies");
}
Also used : Player(net.kodehawa.mantarobot.db.entities.Player) User(net.dv8tion.jda.core.entities.User) MessageEmbed(net.dv8tion.jda.core.entities.MessageEmbed) SecureRandom(java.security.SecureRandom) SimpleCommand(net.kodehawa.mantarobot.core.modules.commands.SimpleCommand) PlayerData(net.kodehawa.mantarobot.db.entities.helpers.PlayerData) RateLimiter(net.kodehawa.mantarobot.utils.commands.RateLimiter) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) Subscribe(com.google.common.eventbus.Subscribe)

Example 34 with SimpleCommand

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

the class MusicCmds method forceskip.

@Subscribe
public void forceskip(CommandRegistry cr) {
    cr.register("forceskip", new SimpleCommand(Category.MUSIC, CommandPermission.ADMIN) {

        @Override
        protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
            if (!isInConditionTo(event))
                return;
            TrackScheduler scheduler = MantaroBot.getInstance().getAudioManager().getMusicManager(event.getGuild()).getTrackScheduler();
            event.getChannel().sendMessage(EmoteReference.CORRECT + "An Admin or Bot Commander decided to skip the current song.").queue();
            scheduler.nextTrack(true, true);
        }

        @Override
        public MessageEmbed help(GuildMessageReceivedEvent event) {
            return helpEmbed(event, "Force skip").setDescription("Well, administrators should be able to forceskip, shouldn't they?\n" + "`~>skip` has the same effect if you're a DJ.").build();
        }
    });
    cr.registerAlias("forceskip", "fs");
}
Also used : SimpleCommand(net.kodehawa.mantarobot.core.modules.commands.SimpleCommand) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) TrackScheduler(net.kodehawa.mantarobot.commands.music.requester.TrackScheduler) Subscribe(com.google.common.eventbus.Subscribe)

Example 35 with SimpleCommand

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

the class MusicCmds method repeat.

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

        @Override
        protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
            if (!isInConditionTo(event)) {
                return;
            }
            GuildMusicManager musicManager = MantaroBot.getInstance().getAudioManager().getMusicManager(event.getGuild());
            try {
                switch(args[0].toLowerCase()) {
                    case "queue":
                        if (musicManager.getTrackScheduler().getRepeatMode() == TrackScheduler.Repeat.QUEUE) {
                            musicManager.getTrackScheduler().setRepeatMode(null);
                            event.getChannel().sendMessage(EmoteReference.CORRECT + "Continuing with the current queue.").queue();
                        } else {
                            musicManager.getTrackScheduler().setRepeatMode(TrackScheduler.Repeat.QUEUE);
                            event.getChannel().sendMessage(EmoteReference.CORRECT + "Repeating the current queue.").queue();
                        }
                        break;
                }
            } catch (Exception e) {
                if (musicManager.getTrackScheduler().getRepeatMode() == TrackScheduler.Repeat.SONG) {
                    musicManager.getTrackScheduler().setRepeatMode(null);
                    event.getChannel().sendMessage(EmoteReference.CORRECT + "Continuing with the normal queue.").queue();
                } else {
                    musicManager.getTrackScheduler().setRepeatMode(TrackScheduler.Repeat.SONG);
                    event.getChannel().sendMessage(EmoteReference.CORRECT + "Repeating the current song.").queue();
                }
            }
            TextChannelGround.of(event).dropItemWithChance(0, 10);
        }

        @Override
        public MessageEmbed help(GuildMessageReceivedEvent event) {
            return helpEmbed(event, "Repeat command").setDescription("**Repeats a song.**").addField("Usage", "`~>repeat` - **Toggles repeat**\n" + "`~>repeat queue` - **Repeats the entire queue**.", false).addField("Warning", "Might not work correctly if I leave the voice channel after you have disabled repeat. *To fix, just " + "add a song to the queue*", true).build();
        }
    });
}
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)

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