Search in sources :

Example 1 with CommandRegistry

use of fredboat.commandmeta.CommandRegistry in project FredBoat by Frederikam.

the class CommandsCommand method addModuleCommands.

private EmbedBuilder addModuleCommands(@Nonnull EmbedBuilder embedBuilder, @Nonnull CommandContext context, @Nonnull CommandRegistry module) {
    List<Command> commands = module.getDeduplicatedCommands().stream().filter(command -> {
        if (command instanceof ICommandRestricted) {
            if (((ICommandRestricted) command).getMinimumPerms().getLevel() >= PermissionLevel.BOT_ADMIN.getLevel()) {
                return PermsUtil.checkPerms(PermissionLevel.BOT_ADMIN, context.invoker);
            }
        }
        return true;
    }).collect(Collectors.toList());
    String prefix = context.getPrefix();
    if (commands.size() >= 6) {
        // split the commands into three even columns
        StringBuilder[] sbs = new StringBuilder[3];
        sbs[0] = new StringBuilder();
        sbs[1] = new StringBuilder();
        sbs[2] = new StringBuilder();
        int i = 0;
        for (Command c : commands) {
            if (c instanceof DestroyCommand) {
                // dont want to publicly show this one
                continue;
            }
            sbs[i++ % 3].append(prefix).append(c.name).append("\n");
        }
        return embedBuilder.addField(context.i18n(module.module.translationKey), sbs[0].toString(), true).addField("", sbs[1].toString(), true).addField("", sbs[2].toString(), true);
    } else {
        StringBuilder sb = new StringBuilder();
        for (Command c : commands) {
            sb.append(prefix).append(c.name).append("\n");
        }
        return embedBuilder.addField(context.i18n(module.module.translationKey), sb.toString(), true).addBlankField(true).addBlankField(true);
    }
}
Also used : CommandRegistry(fredboat.commandmeta.CommandRegistry) CentralMessaging(fredboat.messaging.CentralMessaging) java.util(java.util) IInfoCommand(fredboat.commandmeta.abs.IInfoCommand) Command(fredboat.commandmeta.abs.Command) ICommandRestricted(fredboat.commandmeta.abs.ICommandRestricted) CommandContext(fredboat.commandmeta.abs.CommandContext) PermissionLevel(fredboat.definitions.PermissionLevel) TextUtils(fredboat.util.TextUtils) Collectors(java.util.stream.Collectors) CommandInitializer(fredboat.commandmeta.CommandInitializer) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) Module(fredboat.definitions.Module) Context(fredboat.messaging.internal.Context) Nonnull(javax.annotation.Nonnull) DestroyCommand(fredboat.command.music.control.DestroyCommand) PermsUtil(fredboat.perms.PermsUtil) IInfoCommand(fredboat.commandmeta.abs.IInfoCommand) Command(fredboat.commandmeta.abs.Command) DestroyCommand(fredboat.command.music.control.DestroyCommand) ICommandRestricted(fredboat.commandmeta.abs.ICommandRestricted) DestroyCommand(fredboat.command.music.control.DestroyCommand)

Aggregations

DestroyCommand (fredboat.command.music.control.DestroyCommand)1 CommandInitializer (fredboat.commandmeta.CommandInitializer)1 CommandRegistry (fredboat.commandmeta.CommandRegistry)1 Command (fredboat.commandmeta.abs.Command)1 CommandContext (fredboat.commandmeta.abs.CommandContext)1 ICommandRestricted (fredboat.commandmeta.abs.ICommandRestricted)1 IInfoCommand (fredboat.commandmeta.abs.IInfoCommand)1 Module (fredboat.definitions.Module)1 PermissionLevel (fredboat.definitions.PermissionLevel)1 CentralMessaging (fredboat.messaging.CentralMessaging)1 Context (fredboat.messaging.internal.Context)1 PermsUtil (fredboat.perms.PermsUtil)1 TextUtils (fredboat.util.TextUtils)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 Nonnull (javax.annotation.Nonnull)1 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)1