Search in sources :

Example 61 with GuildMessageReceivedEvent

use of net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent 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 62 with GuildMessageReceivedEvent

use of net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent 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 63 with GuildMessageReceivedEvent

use of net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent 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)

Example 64 with GuildMessageReceivedEvent

use of net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent in project MantaroBot by Mantaro.

the class MusicCmds method skipahead.

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

        @Override
        protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
            if (args.length == 0) {
                onHelp(event);
                return;
            }
            GuildMusicManager manager = MantaroBot.getInstance().getAudioManager().getMusicManager(event.getGuild());
            if (manager.getAudioPlayer().getPlayingTrack() == null) {
                event.getChannel().sendMessage(EmoteReference.ERROR + "I'm not currently playing anything").queue();
                return;
            }
            if (isDJ(event.getMember())) {
                try {
                    long amt = Utils.parseTime(args[0]);
                    if (amt < 0) {
                        event.getChannel().sendMessage(EmoteReference.ERROR + "Positive integers only").queue();
                        return;
                    }
                    AudioTrack track = manager.getAudioPlayer().getPlayingTrack();
                    long position = track.getPosition();
                    if (position + amt > track.getDuration()) {
                        event.getChannel().sendMessage(EmoteReference.ERROR + "You can't skip past the duration of a song").queue();
                        return;
                    }
                    track.setPosition(position + amt);
                    event.getChannel().sendMessage(EmoteReference.CORRECT + "Skipped ahead to " + AudioUtils.getLength(position + amt) + ".").queue();
                } catch (NumberFormatException ex) {
                    event.getChannel().sendMessage(EmoteReference.ERROR + "You need to provide a valid query.").queue();
                }
            } else
                event.getChannel().sendMessage(EmoteReference.ERROR + "You need to be a music DJ to use this command!").queue();
        }

        @Override
        public MessageEmbed help(GuildMessageReceivedEvent event) {
            return helpEmbed(event, "Skip Ahead Command").addField("Description", "Fast forward the current song a specified amount of time", false).addField("Usage", "~>skipahead <time>\nTime is in this format: 1m29s (1 minute and 29s)", false).build();
        }
    });
    cr.registerAlias("skipahead", "forward");
}
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) Subscribe(com.google.common.eventbus.Subscribe)

Example 65 with GuildMessageReceivedEvent

use of net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent in project MantaroBot by Mantaro.

the class OwnerCmd method blacklist.

@Subscribe
public void blacklist(CommandRegistry cr) {
    cr.register("blacklist", new SimpleCommand(Category.OWNER, CommandPermission.OWNER) {

        @Override
        protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
            MantaroObj obj = MantaroData.db().getMantaroData();
            if (args[0].equals("guild")) {
                if (args[1].equals("add")) {
                    if (MantaroBot.getInstance().getGuildById(args[2]) == null)
                        return;
                    obj.getBlackListedGuilds().add(args[2]);
                    event.getChannel().sendMessage(EmoteReference.CORRECT + "Blacklisted Guild: " + MantaroBot.getInstance().getGuildById(args[2])).queue();
                    obj.saveAsync();
                } else if (args[1].equals("remove")) {
                    if (!obj.getBlackListedGuilds().contains(args[2]))
                        return;
                    obj.getBlackListedGuilds().remove(args[2]);
                    event.getChannel().sendMessage(EmoteReference.CORRECT + "Unblacklisted Guild: " + args[2]).queue();
                    obj.saveAsync();
                }
                return;
            }
            if (args[0].equals("user")) {
                if (args[1].equals("add")) {
                    if (MantaroBot.getInstance().getUserById(args[2]) == null)
                        return;
                    obj.getBlackListedUsers().add(args[2]);
                    event.getChannel().sendMessage(EmoteReference.CORRECT + "Blacklisted User: " + MantaroBot.getInstance().getUserById(args[2])).queue();
                    obj.saveAsync();
                } else if (args[1].equals("remove")) {
                    if (!obj.getBlackListedUsers().contains(args[2]))
                        return;
                    obj.getBlackListedUsers().remove(args[2]);
                    event.getChannel().sendMessage(EmoteReference.CORRECT + "Unblacklisted User: " + MantaroBot.getInstance().getUserById(args[2])).queue();
                    obj.saveAsync();
                }
            }
        }

        @Override
        public MessageEmbed help(GuildMessageReceivedEvent event) {
            return helpEmbed(event, "Blacklist command").setDescription("**Blacklists a user (user argument) or a guild (guild argument) by id.**").addField("Examples", "~>blacklist user add/remove 293884638101897216\n" + "~>blacklist guild add/remove 305408763915927552", false).build();
        }
    });
}
Also used : MessageEmbed(net.dv8tion.jda.core.entities.MessageEmbed) SimpleCommand(net.kodehawa.mantarobot.core.modules.commands.SimpleCommand) MantaroObj(net.kodehawa.mantarobot.db.entities.MantaroObj) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) Subscribe(com.google.common.eventbus.Subscribe)

Aggregations

GuildMessageReceivedEvent (net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent)68 Subscribe (com.google.common.eventbus.Subscribe)50 SimpleCommand (net.kodehawa.mantarobot.core.modules.commands.SimpleCommand)48 MessageEmbed (net.dv8tion.jda.core.entities.MessageEmbed)42 EmoteReference (net.kodehawa.mantarobot.utils.commands.EmoteReference)36 MantaroData (net.kodehawa.mantarobot.data.MantaroData)34 List (java.util.List)28 Category (net.kodehawa.mantarobot.core.modules.commands.base.Category)27 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)26 Utils (net.kodehawa.mantarobot.utils.Utils)26 TimeUnit (java.util.concurrent.TimeUnit)25 Collectors (java.util.stream.Collectors)25 CommandRegistry (net.kodehawa.mantarobot.core.CommandRegistry)25 Module (net.kodehawa.mantarobot.core.modules.Module)25 MantaroBot (net.kodehawa.mantarobot.MantaroBot)19 SubCommand (net.kodehawa.mantarobot.core.modules.commands.SubCommand)18 DBGuild (net.kodehawa.mantarobot.db.entities.DBGuild)18 RateLimiter (net.kodehawa.mantarobot.utils.commands.RateLimiter)18 Slf4j (lombok.extern.slf4j.Slf4j)17 Player (net.kodehawa.mantarobot.db.entities.Player)17