make the help command better
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 36s

This commit is contained in:
Lee
2024-06-27 16:24:08 +01:00
parent a7c3e2d745
commit 50b921c66d
7 changed files with 41 additions and 6 deletions

View File

@ -2,6 +2,7 @@ package cc.fascinated.bat.command.impl;
import cc.fascinated.bat.Consts;
import cc.fascinated.bat.command.BatCommand;
import cc.fascinated.bat.command.BatSubCommand;
import cc.fascinated.bat.command.Category;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.event.EventListener;
@ -13,6 +14,7 @@ import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
import net.dv8tion.jda.api.events.interaction.component.StringSelectInteractionEvent;
import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction;
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData;
import net.dv8tion.jda.api.interactions.components.ActionRow;
import net.dv8tion.jda.api.interactions.components.buttons.Button;
import net.dv8tion.jda.api.interactions.components.buttons.ButtonStyle;
@ -22,6 +24,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
/**
* @author Fascinated (fascinated7)
@ -72,8 +76,26 @@ public class HelpCommand extends BatCommand implements EventListener {
}
String commands = "";
for (BatCommand command : commandService.getCommands().values()) {
if (command.getCategory() == category) {
List<BatCommand> categoryCommands = commandService.getCommands().values().stream()
.filter(command -> command.getCategory() == category)
.toList();
if (categoryCommands.isEmpty()) {
commands = "No commands available in this category.";
} else {
for (BatCommand command : categoryCommands) {
if (!command.getSubCommands().isEmpty()) {
for (Map.Entry<String, BatSubCommand> entry : command.getSubCommands().entrySet()) {
BatSubCommand subCommand = entry.getValue();
SubcommandData commandData = subCommand.getCommandData();
commands += "</%s %s:%s> - %s\n".formatted(
command.getName(),
commandData.getName(),
subCommand.getCommandSnowflake(),
commandData.getDescription()
);
}
continue;
}
commands += "</%s:%s> - %s\n".formatted(
command.getName(),
command.getCommandSnowflake(),