Search in sources :

Example 1 with Command

use of fredboat.commandmeta.abs.Command in project FredBoat by Frederikam.

the class DisableCommandsCommand method onInvoke.

@Override
public void onInvoke(@Nonnull CommandContext context) {
    if (context.hasArguments()) {
        Command command = CommandRegistry.findCommand(context.args[0]);
        if (command == null) {
            context.reply("This command doesn't exist!");
            return;
        }
        if (command.name.equals("enable") || command.name.equals("disable")) {
            context.reply("Let's not disable this :wink:");
            return;
        }
        if (CommandManager.disabledCommands.contains(command)) {
            context.reply("This command is already disabled!");
            return;
        }
        CommandManager.disabledCommands.add(command);
        context.reply(":ok_hand: Command `" + command.name + "` disabled!");
    } else {
        HelpCommand.sendFormattedCommandHelp(context);
    }
}
Also used : Command(fredboat.commandmeta.abs.Command) HelpCommand(fredboat.command.info.HelpCommand)

Example 2 with Command

use of fredboat.commandmeta.abs.Command in project FredBoat by Frederikam.

the class HelpCommand method sendFormattedCommandHelp.

private static void sendFormattedCommandHelp(CommandContext context, String trigger) {
    Command command = CommandRegistry.findCommand(trigger);
    if (command == null) {
        String out = "`" + TextUtils.escapeMarkdown(context.getPrefix()) + trigger + "`: " + context.i18n("helpUnknownCommand");
        out += "\n" + context.i18nFormat("helpCommandsPromotion", "`" + TextUtils.escapeMarkdown(context.getPrefix()) + CommandInitializer.COMMANDS_COMM_NAME + "`");
        context.replyWithName(out);
        return;
    }
    String out = getFormattedCommandHelp(context, command, trigger);
    if (command instanceof ICommandRestricted && ((ICommandRestricted) command).getMinimumPerms() == PermissionLevel.BOT_OWNER)
        out += "\n#" + context.i18n("helpCommandOwnerRestricted");
    out = TextUtils.asCodeBlock(out, "md");
    out = context.i18n("helpProperUsage") + out;
    context.replyWithName(out);
}
Also used : SelectCommand(fredboat.command.music.control.SelectCommand) Command(fredboat.commandmeta.abs.Command) IInfoCommand(fredboat.commandmeta.abs.IInfoCommand) PrefixCommand(fredboat.command.config.PrefixCommand) ICommandRestricted(fredboat.commandmeta.abs.ICommandRestricted)

Example 3 with Command

use of fredboat.commandmeta.abs.Command in project FredBoat by Frederikam.

the class MusicHelpCommand method getSortedMusicComms.

private static List<String> getSortedMusicComms(Context context) {
    List<Command> musicCommands = CommandRegistry.getCommandModule(Module.MUSIC).getDeduplicatedCommands();
    // dont explicitly show the youtube and soundcloud commands in this list, since they are just castrated versions
    // of the play command, which is "good enough" for this list
    musicCommands = musicCommands.stream().filter(command -> !(command instanceof PlayCommand && (command.name.equals(CommandInitializer.YOUTUBE_COMM_NAME) || command.name.equals(CommandInitializer.SOUNDCLOUD_COMM_NAME)))).filter(command -> !(command instanceof DestroyCommand)).collect(Collectors.toList());
    musicCommands.sort(new MusicCommandsComparator());
    List<String> musicComms = new ArrayList<>();
    for (Command command : musicCommands) {
        String formattedHelp = HelpCommand.getFormattedCommandHelp(context, command, command.name);
        musicComms.add(formattedHelp);
    }
    return musicComms;
}
Also used : CommandRegistry(fredboat.commandmeta.CommandRegistry) Launcher(fredboat.main.Launcher) Arrays(java.util.Arrays) TextChannel(net.dv8tion.jda.core.entities.TextChannel) SeekCommand(fredboat.command.music.seeking.SeekCommand) Command(fredboat.commandmeta.abs.Command) CommandContext(fredboat.commandmeta.abs.CommandContext) PermissionLevel(fredboat.definitions.PermissionLevel) RestartCommand(fredboat.command.music.seeking.RestartCommand) TextUtils(fredboat.util.TextUtils) ArrayList(java.util.ArrayList) RewindCommand(fredboat.command.music.seeking.RewindCommand) Permission(net.dv8tion.jda.core.Permission) Module(fredboat.definitions.Module) Nonnull(javax.annotation.Nonnull) fredboat.command.music.control(fredboat.command.music.control) CentralMessaging(fredboat.messaging.CentralMessaging) IInfoCommand(fredboat.commandmeta.abs.IInfoCommand) fredboat.command.music.info(fredboat.command.music.info) Collectors(java.util.stream.Collectors) CommandInitializer(fredboat.commandmeta.CommandInitializer) ForwardCommand(fredboat.command.music.seeking.ForwardCommand) List(java.util.List) Context(fredboat.messaging.internal.Context) Emojis(fredboat.util.Emojis) Comparator(java.util.Comparator) PermsUtil(fredboat.perms.PermsUtil) SeekCommand(fredboat.command.music.seeking.SeekCommand) Command(fredboat.commandmeta.abs.Command) RestartCommand(fredboat.command.music.seeking.RestartCommand) RewindCommand(fredboat.command.music.seeking.RewindCommand) IInfoCommand(fredboat.commandmeta.abs.IInfoCommand) ForwardCommand(fredboat.command.music.seeking.ForwardCommand) ArrayList(java.util.ArrayList)

Example 4 with Command

use of fredboat.commandmeta.abs.Command in project FredBoat by Frederikam.

the class EnableCommandsCommand method onInvoke.

@Override
public void onInvoke(@Nonnull CommandContext context) {
    if (context.hasArguments()) {
        Command command = CommandRegistry.findCommand(context.args[0]);
        if (command == null) {
            context.reply("This command doesn't exist!");
            return;
        }
        if (CommandManager.disabledCommands.contains(command)) {
            CommandManager.disabledCommands.remove(command);
            context.reply(":ok_hand: Command `" + command.name + "` enabled!");
            return;
        }
        context.reply("This command is not disabled!");
    } else {
        HelpCommand.sendFormattedCommandHelp(context);
    }
}
Also used : Command(fredboat.commandmeta.abs.Command) HelpCommand(fredboat.command.info.HelpCommand)

Example 5 with Command

use of fredboat.commandmeta.abs.Command in project FredBoat by Frederikam.

the class CommandInitializerTest method testHelpStrings.

/**
 * Make sure all commands initialized in the bot provide help
 */
// @Test disabled until spring refactoring is sorted out
public void testHelpStrings() {
    CommandInitializer.initCommands(null, null, null, null, null, null, null);
    for (String c : CommandRegistry.getAllRegisteredCommandsAndAliases()) {
        Command com = CommandRegistry.findCommand(c);
        Assertions.assertNotNull(com, "Command looked up by " + c + " is null");
        String help = com.help(new FakeContext(null, null, null));
        Assertions.assertNotNull(help, () -> com.getClass().getName() + ".help() returns null");
        Assertions.assertNotEquals("", help, () -> com.getClass().getName() + ".help() returns an empty string");
    }
}
Also used : Command(fredboat.commandmeta.abs.Command) FakeContext(fredboat.test.FakeContext)

Aggregations

Command (fredboat.commandmeta.abs.Command)9 CommandContext (fredboat.commandmeta.abs.CommandContext)4 ICommandRestricted (fredboat.commandmeta.abs.ICommandRestricted)4 IInfoCommand (fredboat.commandmeta.abs.IInfoCommand)4 CommandInitializer (fredboat.commandmeta.CommandInitializer)3 CommandRegistry (fredboat.commandmeta.CommandRegistry)3 Module (fredboat.definitions.Module)3 PermissionLevel (fredboat.definitions.PermissionLevel)3 CentralMessaging (fredboat.messaging.CentralMessaging)3 Context (fredboat.messaging.internal.Context)3 PermsUtil (fredboat.perms.PermsUtil)3 TextUtils (fredboat.util.TextUtils)3 Collectors (java.util.stream.Collectors)3 Nonnull (javax.annotation.Nonnull)3 PrefixCommand (fredboat.command.config.PrefixCommand)2 HelpCommand (fredboat.command.info.HelpCommand)2 DestroyCommand (fredboat.command.music.control.DestroyCommand)2 java.util (java.util)2 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)2 TextChannel (net.dv8tion.jda.core.entities.TextChannel)2