Search in sources :

Example 26 with SimpleCommand

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

the class MoneyCmds method daily.

@Command
public static void daily(CommandRegistry cr) {
    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) {
            String id = event.getAuthor().getId();
            long money = 150L;
            User mentionedUser = null;
            try {
                mentionedUser = event.getMessage().getMentionedUsers().get(0);
            } catch (IndexOutOfBoundsException ignored) {
            }
            Player player;
            if (!rateLimiter.process(id)) {
                event.getChannel().sendMessage(EmoteReference.STOPWATCH + "Halt! You can only do this once every 24 hours.\n**You'll be able to use this command again in " + Utils.getVerboseTime(rateLimiter.tryAgainIn(id)) + ".**").queue();
                return;
            }
            if (mentionedUser != null && !mentionedUser.getId().equals(event.getAuthor().getId())) {
                money = money + r.nextInt(2);
                player = MantaroData.db().getPlayer(event.getGuild().getMember(mentionedUser));
                if (player.getInventory().containsItem(Items.COMPANION))
                    money = Math.round(money + (money * 0.10));
                if (mentionedUser.getId().equals(player.getData().getMarriedWith()) && player.getData().getMarriedSince() != null && Long.parseLong(player.getData().anniversary()) - player.getData().getMarriedSince() > TimeUnit.DAYS.toMillis(1)) {
                    money = money + r.nextInt(20);
                    if (player.getInventory().containsItem(Items.RING_2)) {
                        money = money + r.nextInt(10);
                    }
                }
                player.addMoney(money);
                player.save();
                event.getChannel().sendMessage(EmoteReference.CORRECT + "I gave your **$" + money + "** daily credits to " + mentionedUser.getName()).queue();
                return;
            }
            player = MantaroData.db().getPlayer(event.getMember());
            player.addMoney(money);
            player.save();
            event.getChannel().sendMessage(EmoteReference.CORRECT + "You got **$" + money + "** daily credits.").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)**.").build();
        }
    });
}
Also used : Player(net.kodehawa.mantarobot.data.entities.Player) User(net.dv8tion.jda.core.entities.User) MessageEmbed(net.dv8tion.jda.core.entities.MessageEmbed) 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 27 with SimpleCommand

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

the class MusicCmds method forceskip.

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

        @Override
        protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
            if (!event.getMember().getVoiceState().inVoiceChannel() || !event.getMember().getVoiceState().getChannel().equals(event.getGuild().getAudioManager().getConnectedChannel())) {
                event.getChannel().sendMessage(EmoteReference.ERROR + "You aren't connected to the voice channel I'm in!").queue();
                return;
            }
            TrackScheduler scheduler = MantaroBot.getInstance().getAudioManager().getMusicManager(event.getGuild()).getTrackScheduler();
            event.getChannel().sendMessage(EmoteReference.CORRECT + "An admin decided to skip the current song.").queue();
            scheduler.next(true);
        }

        @Override
        public MessageEmbed help(GuildMessageReceivedEvent event) {
            return helpEmbed(event, "Force skip").setDescription("Well, administrators should be able to forceskip, shouldn't they?").build();
        }
    });
    cr.registerAlias("forceskip", "fs");
}
Also used : SimpleCommand(net.kodehawa.mantarobot.modules.commands.SimpleCommand) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) TrackScheduler(net.kodehawa.mantarobot.commands.music.TrackScheduler) SimpleCommand(net.kodehawa.mantarobot.modules.commands.SimpleCommand) Command(net.kodehawa.mantarobot.modules.Command)

Example 28 with SimpleCommand

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

the class MiscCmds method eightBall.

@Command
public static void eightBall(CommandRegistry cr) {
    cr.register("8ball", new SimpleCommand(Category.MISC) {

        @Override
        protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
            if (content.isEmpty()) {
                onError(event);
                return;
            }
            String textEncoded;
            String answer;
            try {
                textEncoded = URLEncoder.encode(content, "UTF-8");
                answer = Unirest.get(String.format("https://8ball.delegator.com/magic/JSON/%1s", textEncoded)).asJson().getBody().getObject().getJSONObject("magic").getString("answer");
            } catch (Exception exception) {
                event.getChannel().sendMessage(EmoteReference.ERROR + "I ran into an error while fetching 8ball results. My owners " + "have been notified and will resolve this soon.").queue();
                log.warn("Error while processing answer", exception);
                return;
            }
            event.getChannel().sendMessage("💬 " + answer + ".").queue();
        }

        @Override
        public MessageEmbed help(GuildMessageReceivedEvent event) {
            return helpEmbed(event, "8ball").setDescription("**Retrieves an answer from the almighty 8ball.**").addField("Usage", "`~>8ball <question>` - **Retrieves an answer from 8ball based on the question or sentence provided.**", false).build();
        }
    });
    cr.registerAlias("8ball", "8b");
}
Also used : MessageEmbed(net.dv8tion.jda.core.entities.MessageEmbed) SimpleCommand(net.kodehawa.mantarobot.modules.commands.SimpleCommand) 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)

Example 29 with SimpleCommand

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

the class FunCmds method coinflip.

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

        @Override
        protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
            int times;
            if (args.length == 0 || content.length() == 0)
                times = 1;
            else {
                try {
                    times = Integer.parseInt(args[0]);
                    if (times > 1000) {
                        event.getChannel().sendMessage(EmoteReference.ERROR + "Whoah there! The limit is 1,000 coinflips").queue();
                        return;
                    }
                } catch (NumberFormatException nfe) {
                    event.getChannel().sendMessage(EmoteReference.ERROR + "You need to specify an Integer for the amount of " + "repetitions").queue();
                    return;
                }
            }
            final int[] heads = { 0 };
            final int[] tails = { 0 };
            doTimes(times, () -> {
                if (new Random().nextBoolean())
                    heads[0]++;
                else
                    tails[0]++;
            });
            String flips = times == 1 ? "time" : "times";
            event.getChannel().sendMessage(EmoteReference.PENNY + " Your result from **" + times + "** " + flips + " yielded " + "**" + heads[0] + "** heads and **" + tails[0] + "** tails").queue();
        }

        @Override
        public MessageEmbed help(GuildMessageReceivedEvent event) {
            return helpEmbed(event, "Coinflip command").setDescription("**Flips a coin with a defined number of repetitions**").addField("Usage", "`~>coinflip <number of times>` - **Flips a coin x number of times**", false).build();
        }
    });
}
Also used : MessageEmbed(net.dv8tion.jda.core.entities.MessageEmbed) SimpleCommand(net.kodehawa.mantarobot.modules.commands.SimpleCommand) Random(java.util.Random) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) 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