Search in sources :

Example 26 with SimpleCommand

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

the class FunCmds method coinflip.

@Subscribe
public 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 + "Hold in there! The limit is 1,000 coin flips").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 (r.nextBoolean())
                    heads[0]++;
                else
                    tails[0]++;
            });
            String flips = times == 1 ? "time" : "times";
            event.getChannel().sendMessage(String.format("%s Your result from **%d** %s yielded **%d** heads and **%d** tails", EmoteReference.PENNY, times, flips, heads[0], tails[0])).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.core.modules.commands.SimpleCommand) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) Subscribe(com.google.common.eventbus.Subscribe)

Example 27 with SimpleCommand

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

the class InfoCmds method tips.

@Subscribe
public void tips(CommandRegistry cr) {
    final List<String> tips = new SimpleFileDataManager("assets/mantaro/texts/tips.txt").get();
    final Random r = new Random();
    cr.register("tips", new SimpleCommand(Category.INFO) {

        @Override
        protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
            event.getChannel().sendMessage(EmoteReference.TALKING + "Tip: " + tips.get(r.nextInt(tips.size()))).queue();
        }

        @Override
        public MessageEmbed help(GuildMessageReceivedEvent event) {
            return helpEmbed(event, "Tips Command").setDescription("**Shows tips about the bot!**").build();
        }
    });
    cr.registerAlias("tips", "bottips");
}
Also used : SimpleCommand(net.kodehawa.mantarobot.core.modules.commands.SimpleCommand) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) SimpleFileDataManager(net.kodehawa.mantarobot.utils.data.SimpleFileDataManager) Subscribe(com.google.common.eventbus.Subscribe)

Example 28 with SimpleCommand

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

the class InfoCmds method help.

@Subscribe
public void help(CommandRegistry cr) {
    Random r = new Random();
    List<String> jokes = Collections.unmodifiableList(Arrays.asList("Yo damn I heard you like help, because you just issued the help command to get the help about the help command.", "Congratulations, you managed to use the help command.", "Helps you to help yourself.", "Help Inception.", "A help helping helping helping help.", "I wonder if this is what you are looking for..."));
    cr.register("help", new SimpleCommand(Category.INFO) {

        @Override
        protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
            if (content.isEmpty()) {
                DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
                String defaultPrefix = MantaroData.config().get().prefix[0], guildPrefix = dbGuild.getData().getGuildCustomPrefix();
                String prefix = guildPrefix == null ? defaultPrefix : guildPrefix;
                GuildData guildData = dbGuild.getData();
                EmbedBuilder embed = baseEmbed(event, "Mantaro Help").setColor(Color.PINK).setDescription("Command list. For a detailed guide on the usage of Mantaro, please check the [wiki](https://github.com/Mantaro/MantaroBot/wiki).\n" + "If you have issues or inquiries while using Mantaro, please join the [support server](https://is.gd/mantaroguild)\n" + "[We need your help to keep Mantaro online! Click here for more info.](https://www.patreon.com/mantaro)\n" + (guildData.getDisabledCommands().isEmpty() ? "" : "\nOnly showing non-disabled commands. Total disabled commands: " + guildData.getDisabledCommands().size()) + (guildData.getChannelSpecificDisabledCommands().get(event.getChannel().getId()) == null || guildData.getChannelSpecificDisabledCommands().get(event.getChannel().getId()).isEmpty() ? "" : "\nOnly showing non-disabled commands. Total channel-specific disabled commands: " + guildData.getChannelSpecificDisabledCommands().get(event.getChannel().getId()).size())).setFooter(String.format("To check command usage, type %shelp <command> // -> Commands: " + DefaultCommandProcessor.REGISTRY.commands().values().stream().filter(c -> c.category() != null).count(), prefix), null);
                Arrays.stream(Category.values()).filter(c -> c != Category.CURRENCY || !MantaroData.config().get().isPremiumBot()).filter(c -> c != Category.OWNER || CommandPermission.OWNER.test(event.getMember())).forEach(c -> embed.addField(c + " Commands:", forType(event.getChannel(), guildData, c), false));
                event.getChannel().sendMessage(embed.build()).queue();
            } else {
                Command command = DefaultCommandProcessor.REGISTRY.commands().get(content);
                if (command != null) {
                    final MessageEmbed help = command.help(event);
                    if (help != null) {
                        event.getChannel().sendMessage(help).queue();
                    } else {
                        event.getChannel().sendMessage(EmoteReference.ERROR + "There's no extended help set for this command.").queue();
                    }
                } else {
                    event.getChannel().sendMessage(EmoteReference.ERROR + "A command with this name doesn't exist").queue();
                }
            }
        }

        @Override
        public MessageEmbed help(GuildMessageReceivedEvent event) {
            return helpEmbed(event, "Help Command").setColor(Color.PINK).setDescription("**" + jokes.get(r.nextInt(jokes.size())) + "**").addField("Usage", "`~>help` - **Returns a list of commands that you can use**.\n" + "`~>help <command>` - **Return information about the command specified**.", false).build();
        }
    });
    cr.registerAlias("help", "commands");
    // why not
    cr.registerAlias("help", "halp");
}
Also used : MantaroInfo(net.kodehawa.mantarobot.MantaroInfo) Module(net.kodehawa.mantarobot.core.modules.Module) java.util(java.util) DefaultCommandProcessor(net.kodehawa.mantarobot.core.processor.DefaultCommandProcessor) Command(net.kodehawa.mantarobot.core.modules.commands.base.Command) Utils(net.kodehawa.mantarobot.utils.Utils) DiscordUtils(net.kodehawa.mantarobot.utils.DiscordUtils) MantaroBot(net.kodehawa.mantarobot.MantaroBot) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) Permission(net.dv8tion.jda.core.Permission) CommandRegistry(net.kodehawa.mantarobot.core.CommandRegistry) SnowflakeCacheView(net.dv8tion.jda.core.utils.cache.SnowflakeCacheView) Subscribe(com.google.common.eventbus.Subscribe) SimpleCommand(net.kodehawa.mantarobot.core.modules.commands.SimpleCommand) net.kodehawa.mantarobot.commands.info.stats.manager(net.kodehawa.mantarobot.commands.info.stats.manager) SimpleFileDataManager(net.kodehawa.mantarobot.utils.data.SimpleFileDataManager) ManagementFactory(java.lang.management.ManagementFactory) TextChannelGround(net.kodehawa.mantarobot.commands.currency.TextChannelGround) CommandListener(net.kodehawa.mantarobot.core.listeners.command.CommandListener) SubCommand(net.kodehawa.mantarobot.core.modules.commands.SubCommand) net.dv8tion.jda.core.entities(net.dv8tion.jda.core.entities) Category(net.kodehawa.mantarobot.core.modules.commands.base.Category) AsyncInfoMonitor(net.kodehawa.mantarobot.commands.info.AsyncInfoMonitor) DBGuild(net.kodehawa.mantarobot.db.entities.DBGuild) Collectors(java.util.stream.Collectors) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) OnlineStatus(net.dv8tion.jda.core.OnlineStatus) TreeCommand(net.kodehawa.mantarobot.core.modules.commands.TreeCommand) java.awt(java.awt) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) CommandPermission(net.kodehawa.mantarobot.core.modules.commands.base.CommandPermission) StatsHelper.calculateInt(net.kodehawa.mantarobot.commands.info.stats.StatsHelper.calculateInt) BLUE_SMALL_MARKER(net.kodehawa.mantarobot.utils.commands.EmoteReference.BLUE_SMALL_MARKER) GuildData(net.kodehawa.mantarobot.db.entities.helpers.GuildData) EmoteReference(net.kodehawa.mantarobot.utils.commands.EmoteReference) DateTimeFormatter(java.time.format.DateTimeFormatter) MantaroData(net.kodehawa.mantarobot.data.MantaroData) HelpUtils.forType(net.kodehawa.mantarobot.commands.info.HelpUtils.forType) StatsHelper.calculateDouble(net.kodehawa.mantarobot.commands.info.stats.StatsHelper.calculateDouble) GuildData(net.kodehawa.mantarobot.db.entities.helpers.GuildData) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) 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) SubCommand(net.kodehawa.mantarobot.core.modules.commands.SubCommand) TreeCommand(net.kodehawa.mantarobot.core.modules.commands.TreeCommand) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) Subscribe(com.google.common.eventbus.Subscribe)

Example 29 with SimpleCommand

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

the class MiscCmds method randomFact.

@Subscribe
public void randomFact(CommandRegistry cr) {
    cr.register("randomfact", new SimpleCommand(Category.MISC) {

        @Override
        protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
            event.getChannel().sendMessage(EmoteReference.TALKING + facts.get().get(rand.nextInt(facts.get().size() - 1))).queue();
        }

        @Override
        public MessageEmbed help(GuildMessageReceivedEvent event) {
            return helpEmbed(event, "Random Fact").setDescription("**Sends a random fact.**").build();
        }
    });
    cr.registerAlias("randomfact", "rf");
}
Also used : 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 30 with SimpleCommand

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

the class MiscCmds method eightBall.

@Subscribe
public 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");
                String json = Utils.wgetResty(String.format("https://8ball.delegator.com/magic/JSON/%1s", textEncoded), event);
                answer = new JSONObject(json).getJSONObject("magic").getString("answer");
            } catch (Exception exception) {
                event.getChannel().sendMessage(EmoteReference.ERROR + "I ran into an error while fetching 8ball results.").queue();
                return;
            }
            event.getChannel().sendMessage("\uD83D\uDCAC " + 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.core.modules.commands.SimpleCommand) JSONObject(org.json.JSONObject) 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