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);
}
}
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);
}
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;
}
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);
}
}
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");
}
}
Aggregations