Search in sources :

Example 1 with Command

use of com.greatmancode.legendarybot.api.commands.Command in project legendarybot by greatman.

the class HelpCommand method execute.

@Override
public void execute(MessageReceivedEvent event, String[] args) {
    if (args.length == 1 && bot.getCommandHandler().getCommandList().containsKey(args[0])) {
        event.getAuthor().openPrivateChannel().complete().sendMessage(bot.getCommandHandler().getCommandList().get(args[0]).help(event.getGuild())).queue();
        return;
    }
    final MessageBuilder[] builder = { new MessageBuilder() };
    String prefix = bot.getGuildSettings(event.getGuild()).getSetting("PREFIX");
    if (prefix == null) {
        prefix = "!";
    }
    String finalPrefix = prefix;
    builder[0].append(bot.getTranslateManager().translate(event.getGuild(), "command.help.firstline") + "\n");
    builder[0].append(bot.getTranslateManager().translate(event.getGuild(), "command.help.secondline", prefix));
    bot.getCommandHandler().getCommandGroup().forEach((k, v) -> {
        if (builder[0].length() >= 1700) {
            event.getAuthor().openPrivateChannel().complete().sendMessage(builder[0].build()).queue();
            builder[0] = new MessageBuilder();
        }
        builder[0].append("\n__");
        builder[0].append(k);
        builder[0].append("__\n");
        v.forEach((commandName) -> {
            if (builder[0].length() >= 1700) {
                event.getAuthor().openPrivateChannel().complete().sendMessage(builder[0].build()).queue();
                builder[0] = new MessageBuilder();
            }
            Command command = bot.getCommandHandler().getCommandList().get(commandName);
            if (command.canExecute(event.getMember())) {
                builder[0].append("**");
                builder[0].append(finalPrefix);
                builder[0].append(commandName);
                builder[0].append("**: ");
                builder[0].append(command.shortDescription(event.getGuild()));
                builder[0].append("\n");
            }
        });
    });
    event.getAuthor().openPrivateChannel().complete().sendMessage(builder[0].build()).queue();
}
Also used : MessageBuilder(net.dv8tion.jda.core.MessageBuilder) PublicCommand(com.greatmancode.legendarybot.api.commands.PublicCommand) Command(com.greatmancode.legendarybot.api.commands.Command)

Aggregations

Command (com.greatmancode.legendarybot.api.commands.Command)1 PublicCommand (com.greatmancode.legendarybot.api.commands.PublicCommand)1 MessageBuilder (net.dv8tion.jda.core.MessageBuilder)1