package com.bwfcwalshy.flarebot.commands.general;

import com.bwfcwalshy.flarebot.FlareBot;
import com.bwfcwalshy.flarebot.MessageUtils;
import com.bwfcwalshy.flarebot.commands.Command;
import com.bwfcwalshy.flarebot.commands.CommandType;
import sx.blah.discord.handle.obj.IChannel;
import sx.blah.discord.handle.obj.IMessage;
import sx.blah.discord.handle.obj.IUser;
import sx.blah.discord.util.EmbedBuilder;

import java.util.stream.Collectors;

public class HelpCommand implements Command {

    @Override
    public void onCommand(IUser sender, IChannel channel, IMessage message, String[] args) {
        if (args.length == 1) {
            CommandType type;
            try {
                type = CommandType.valueOf(args[0].toUpperCase());
            } catch (IllegalArgumentException ignored) {
                MessageUtils.sendMessage(MessageUtils.getEmbed(sender).withDesc("No such category!").build(), channel);
                return;
            }
            if (type != CommandType.HIDDEN) {
                EmbedBuilder embedBuilder = MessageUtils.getEmbed(sender);
                embedBuilder.withDesc("***FlareBot " + type + " commands!***");
                MessageUtils.sendMessage(embedBuilder.appendField(type.toString(), type.getCommands()
                        .stream()
                        .map(command -> get(channel) + command.getCommand() + " - " + command.getDescription() + '\n')
                        .collect(Collectors.joining("")), false).build(), channel);
            } else {
                MessageUtils.sendMessage(MessageUtils.getEmbed(sender).withDesc("No such category!").build(), channel);
            }
        } else {
            sendCommands(channel, sender);
        }
    }

    private char get(IChannel channel) {
        if (channel.getGuild() != null) {
            return FlareBot.getPrefixes().get(channel.getGuild().getID());
        }
        return FlareBot.getPrefixes().get(null);
    }

    private void sendCommands(IChannel channel, IUser sender) {
        EmbedBuilder embedBuilder = MessageUtils.getEmbed(sender);
        for (CommandType c : CommandType.getTypes()) {
            String help = c.getCommands()
                    .stream()
                    .map(command -> get(channel) + command.getCommand() + " - " + command.getDescription() + '\n')
                    .collect(Collectors.joining(""));
            embedBuilder.appendField(c.toString(), help, false);
        }
        MessageUtils.sendMessage(embedBuilder.build(), channel);
    }

    @Override
    public String getCommand() {
        return "commands";
    }

    @Override
    public String[] getAliases() {
        return new String[]{"help"};
    }

    @Override
    public String getDescription() {
        return "See a list of all commands.";
    }

    @Override
    public CommandType getType() {
        return CommandType.GENERAL;
    }

    @Override
    public String getPermission() {
        return null;
    }
}

@@ -2899,85 +2899,7 @@
    %7D
-%0A%0A    @Override%0A    public String getPermission() %7B%0A        return null;%0A    %7D
 %0A%7D%0A

Add help permission node