Search in sources :

Example 1 with Command

use of me.shadorc.shadbot.core.command.annotation.Command in project Shadbot by Shadorc.

the class HelpCmd method execute.

@Override
public void execute(Context context) throws MissingArgumentException, IllegalCmdArgumentException {
    if (context.hasArg()) {
        AbstractCommand cmd = CommandManager.getCommand(context.getArg());
        if (cmd == null) {
            return;
        }
        BotUtils.sendMessage(cmd.getHelp(context.getPrefix()), context.getChannel());
        CommandStatsManager.log(CommandEnum.COMMAND_HELPED, cmd);
        return;
    }
    EmbedBuilder embed = EmbedUtils.getDefaultEmbed().setLenient(true).withAuthorName("Shadbot Help").appendDescription(String.format("Any issues, questions or suggestions ? Join the [support server.](%s)" + "%nGet more information by using `%s%s <command>`.", Config.SUPPORT_SERVER, context.getPrefix(), this.getName()));
    for (CommandCategory category : CommandCategory.values()) {
        if (category.equals(CommandCategory.HIDDEN)) {
            continue;
        }
        String commands = CommandManager.getCommands().values().stream().distinct().filter(cmd -> cmd.getCategory().equals(category) && !cmd.getPermission().isSuperior(context.getAuthorPermission()) && (context.getGuild() == null || BotUtils.isCommandAllowed(context.getGuild(), cmd))).map(cmd -> String.format("`%s%s`", context.getPrefix(), cmd.getName())).collect(Collectors.joining(" "));
        embed.appendField(String.format("%s Commands", category.toString()), commands, false);
    }
    BotUtils.sendMessage(embed.build(), context.getChannel());
}
Also used : RateLimited(me.shadorc.shadbot.core.command.annotation.RateLimited) HelpBuilder(me.shadorc.shadbot.utils.embed.HelpBuilder) CommandCategory(me.shadorc.shadbot.core.command.CommandCategory) CommandManager(me.shadorc.shadbot.core.command.CommandManager) EmbedObject(sx.blah.discord.api.internal.json.objects.EmbedObject) Collectors(java.util.stream.Collectors) BotUtils(me.shadorc.shadbot.utils.BotUtils) CommandStatsManager(me.shadorc.shadbot.data.stats.CommandStatsManager) MissingArgumentException(me.shadorc.shadbot.exception.MissingArgumentException) IllegalCmdArgumentException(me.shadorc.shadbot.exception.IllegalCmdArgumentException) Command(me.shadorc.shadbot.core.command.annotation.Command) EmbedBuilder(sx.blah.discord.util.EmbedBuilder) Context(me.shadorc.shadbot.core.command.Context) AbstractCommand(me.shadorc.shadbot.core.command.AbstractCommand) CommandEnum(me.shadorc.shadbot.data.stats.CommandStatsManager.CommandEnum) EmbedUtils(me.shadorc.shadbot.utils.embed.EmbedUtils) Config(me.shadorc.shadbot.Config) EmbedBuilder(sx.blah.discord.util.EmbedBuilder) AbstractCommand(me.shadorc.shadbot.core.command.AbstractCommand) CommandCategory(me.shadorc.shadbot.core.command.CommandCategory)

Aggregations

Collectors (java.util.stream.Collectors)1 Config (me.shadorc.shadbot.Config)1 AbstractCommand (me.shadorc.shadbot.core.command.AbstractCommand)1 CommandCategory (me.shadorc.shadbot.core.command.CommandCategory)1 CommandManager (me.shadorc.shadbot.core.command.CommandManager)1 Context (me.shadorc.shadbot.core.command.Context)1 Command (me.shadorc.shadbot.core.command.annotation.Command)1 RateLimited (me.shadorc.shadbot.core.command.annotation.RateLimited)1 CommandStatsManager (me.shadorc.shadbot.data.stats.CommandStatsManager)1 CommandEnum (me.shadorc.shadbot.data.stats.CommandStatsManager.CommandEnum)1 IllegalCmdArgumentException (me.shadorc.shadbot.exception.IllegalCmdArgumentException)1 MissingArgumentException (me.shadorc.shadbot.exception.MissingArgumentException)1 BotUtils (me.shadorc.shadbot.utils.BotUtils)1 EmbedUtils (me.shadorc.shadbot.utils.embed.EmbedUtils)1 HelpBuilder (me.shadorc.shadbot.utils.embed.HelpBuilder)1 EmbedObject (sx.blah.discord.api.internal.json.objects.EmbedObject)1 EmbedBuilder (sx.blah.discord.util.EmbedBuilder)1