use of me.shadorc.shadbot.core.command.CommandCategory in project Shadbot by Shadorc.
the class HelpCmd method execute.
@Override
public void execute(Context context) throws MissingArgumentException, IllegalCmdArgumentException {
if (context.hasArg()) {
AbstractCommand cmd = CommandManager.getCommand(context.getArg());
if (cmd == null) {
return;
}
BotUtils.sendMessage(cmd.getHelp(context.getPrefix()), context.getChannel());
CommandStatsManager.log(CommandEnum.COMMAND_HELPED, cmd);
return;
}
EmbedBuilder embed = EmbedUtils.getDefaultEmbed().setLenient(true).withAuthorName("Shadbot Help").appendDescription(String.format("Any issues, questions or suggestions ? Join the [support server.](%s)" + "%nGet more information by using `%s%s <command>`.", Config.SUPPORT_SERVER, context.getPrefix(), this.getName()));
for (CommandCategory category : CommandCategory.values()) {
if (category.equals(CommandCategory.HIDDEN)) {
continue;
}
String commands = CommandManager.getCommands().values().stream().distinct().filter(cmd -> cmd.getCategory().equals(category) && !cmd.getPermission().isSuperior(context.getAuthorPermission()) && (context.getGuild() == null || BotUtils.isCommandAllowed(context.getGuild(), cmd))).map(cmd -> String.format("`%s%s`", context.getPrefix(), cmd.getName())).collect(Collectors.joining(" "));
embed.appendField(String.format("%s Commands", category.toString()), commands, false);
}
BotUtils.sendMessage(embed.build(), context.getChannel());
}
Aggregations