Search in sources :

Example 11 with Command

use of net.kodehawa.mantarobot.core.modules.commands.base.Command 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 12 with Command

use of net.kodehawa.mantarobot.core.modules.commands.base.Command 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)

Aggregations

GuildMessageReceivedEvent (net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent)12 Category (net.kodehawa.mantarobot.core.modules.commands.base.Category)12 Command (net.kodehawa.mantarobot.core.modules.commands.base.Command)12 MantaroData (net.kodehawa.mantarobot.data.MantaroData)12 EmoteReference (net.kodehawa.mantarobot.utils.commands.EmoteReference)12 Subscribe (com.google.common.eventbus.Subscribe)11 TimeUnit (java.util.concurrent.TimeUnit)11 CommandRegistry (net.kodehawa.mantarobot.core.CommandRegistry)11 Module (net.kodehawa.mantarobot.core.modules.Module)11 SimpleCommand (net.kodehawa.mantarobot.core.modules.commands.SimpleCommand)11 java.util (java.util)10 SubCommand (net.kodehawa.mantarobot.core.modules.commands.SubCommand)10 TreeCommand (net.kodehawa.mantarobot.core.modules.commands.TreeCommand)10 Utils (net.kodehawa.mantarobot.utils.Utils)10 List (java.util.List)9 Collectors (java.util.stream.Collectors)9 DiscordUtils (net.kodehawa.mantarobot.utils.DiscordUtils)9 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)8 MantaroBot (net.kodehawa.mantarobot.MantaroBot)8 java.awt (java.awt)7