From ff5b83f5310925aef070aa50d80cd586e1fbbb89 Mon Sep 17 00:00:00 2001 From: Liam Date: Thu, 27 Jun 2024 21:21:56 +0100 Subject: [PATCH] fix help command --- .../cc/fascinated/bat/command/Category.java | 18 ++++++++++++++++++ .../bat/command/impl/HelpCommand.java | 4 ++-- .../fascinated/bat/service/CommandService.java | 3 +-- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/main/java/cc/fascinated/bat/command/Category.java b/src/main/java/cc/fascinated/bat/command/Category.java index 4889c4f..9d188ff 100644 --- a/src/main/java/cc/fascinated/bat/command/Category.java +++ b/src/main/java/cc/fascinated/bat/command/Category.java @@ -4,6 +4,9 @@ import lombok.AllArgsConstructor; import lombok.Getter; import net.dv8tion.jda.api.entities.emoji.Emoji; +import java.util.Arrays; +import java.util.List; + /** * @author Fascinated (fascinated7) */ @@ -31,6 +34,12 @@ public enum Category { */ private final boolean hidden; + /** + * Gets a category by its name + * + * @param name the name of the category + * @return the category + */ public static Category getByName(String name) { for (Category category : Category.values()) { if (category.getName().equalsIgnoreCase(name)) { @@ -39,4 +48,13 @@ public enum Category { } return null; } + + /** + * Gets all the visible categories + * + * @return the visible categories + */ + public static List getCategories() { + return Arrays.stream(Category.values()).filter(category -> !category.isHidden()).toList(); + } } diff --git a/src/main/java/cc/fascinated/bat/command/impl/HelpCommand.java b/src/main/java/cc/fascinated/bat/command/impl/HelpCommand.java index db8e880..de68216 100644 --- a/src/main/java/cc/fascinated/bat/command/impl/HelpCommand.java +++ b/src/main/java/cc/fascinated/bat/command/impl/HelpCommand.java @@ -110,7 +110,7 @@ public class HelpCommand extends BatCommand implements EventListener { */ private MessageEmbed createHomeEmbed() { String categories = ""; - for (Category category : Category.values()) { + for (Category category : Category.getCategories()) { long commandCount = commandService.getCommandsByCategory(category, true).size(); categories += "➜ %s - **%s Command%s**\n".formatted( category.getName(), @@ -132,7 +132,7 @@ public class HelpCommand extends BatCommand implements EventListener { private LayoutComponent[] createHomeActions() { List options = new ArrayList<>(); options.add(SelectOption.of("Home", "home").withEmoji(Emoji.fromUnicode("U+1F3E0"))); - options.addAll(Arrays.stream(Category.values()).map(category -> + options.addAll(Category.getCategories().stream().map(category -> SelectOption.of(category.getName(), category.getName()).withEmoji(category.getEmoji())) .toList()); diff --git a/src/main/java/cc/fascinated/bat/service/CommandService.java b/src/main/java/cc/fascinated/bat/service/CommandService.java index 10bdf97..71c244c 100644 --- a/src/main/java/cc/fascinated/bat/service/CommandService.java +++ b/src/main/java/cc/fascinated/bat/service/CommandService.java @@ -81,7 +81,6 @@ public class CommandService extends ListenerAdapter { log.info("Unregistered hidden command \"{}\" from Discord", command.getName()); return; } - if (commands.containsKey(command.getName())) { return; } @@ -118,7 +117,7 @@ public class CommandService extends ListenerAdapter { * @return The commands */ public List getCommandsByCategory(Category category, boolean hideHiddenCategories) { - return commands.values().stream().filter(command -> command.getCategory() == category && (hideHiddenCategories && category.isHidden())).toList(); + return commands.values().stream().filter(command -> command.getCategory() == category && (hideHiddenCategories && !category.isHidden())).toList(); } @Override