diff --git a/src/main/java/cc/fascinated/bat/features/base/commands/general/HelpCommand.java b/src/main/java/cc/fascinated/bat/features/base/commands/general/HelpCommand.java index d214d38..142d80f 100644 --- a/src/main/java/cc/fascinated/bat/features/base/commands/general/HelpCommand.java +++ b/src/main/java/cc/fascinated/bat/features/base/commands/general/HelpCommand.java @@ -45,7 +45,7 @@ public class HelpCommand extends BatCommand implements EventListener { @Override public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction event) { - event.replyEmbeds(createHomeEmbed()).addComponents(createHomeActions()).queue(); + event.replyEmbeds(createHomeEmbed(event.isFromGuild())).addComponents(createHomeActions(event.isFromGuild())).queue(); } @Override @@ -56,8 +56,8 @@ public class HelpCommand extends BatCommand implements EventListener { // Get the item String item = event.getSelectedOptions().get(0).getValue(); - if (item.equalsIgnoreCase("home")) { - event.editMessageEmbeds(createHomeEmbed()).queue(); + if (item.equalsIgnoreCase("help-home")) { + event.editMessageEmbeds(createHomeEmbed(event.isFromGuild())).queue(); return; } @@ -72,7 +72,7 @@ public class HelpCommand extends BatCommand implements EventListener { // Send the category StringBuilder commands = new StringBuilder(); - List categoryCommands = commandService.getCommandsByCategory(category); + List categoryCommands = commandService.getCommandsByCategory(category, event.isFromGuild()); if (categoryCommands.isEmpty()) { commands = new StringBuilder("No commands available in this category."); } else { @@ -114,10 +114,13 @@ public class HelpCommand extends BatCommand implements EventListener { * * @return The home embed */ - private MessageEmbed createHomeEmbed() { + private MessageEmbed createHomeEmbed(boolean ranInsideGuild) { StringBuilder categories = new StringBuilder(); for (Category category : Category.values()) { - long commandCount = commandService.getCommandsByCategory(category).size(); + if (commandService.getCommandsByCategory(category, ranInsideGuild).isEmpty()) { + continue; + } + long commandCount = commandService.getCommandsByCategory(category, ranInsideGuild).size(); categories.append("➜ %s - **%s Command%s**\n".formatted( category.getName(), commandCount, @@ -127,11 +130,12 @@ public class HelpCommand extends BatCommand implements EventListener { return EmbedUtils.genericEmbed() .setDescription(""" - **Welcome to the Bat Help Menu!** + **Welcome to the Bat Help Menu!**%s %s *View our [TOS](%s) and [Privacy Policy](%s) for more information.* """.formatted( + !ranInsideGuild ? "\n*guild only commands won't be shown here" : "", categories.toString(), Consts.TERMS_OF_SERVICE_URL, Consts.PRIVACY_POLICY_URL @@ -144,10 +148,13 @@ public class HelpCommand extends BatCommand implements EventListener { * * @return The layout components */ - private LayoutComponent[] createHomeActions() { + private LayoutComponent[] createHomeActions(boolean ranInsideGuild) { List options = new ArrayList<>(); options.add(SelectOption.of("Home", "help-home").withEmoji(Emoji.fromUnicode("U+1F3E0"))); for (Category category : Category.values()) { + if (commandService.getCommandsByCategory(category, ranInsideGuild).isEmpty()) { + continue; + } options.add(SelectOption.of(category.getName(), "help-" + category.getName()).withEmoji(category.getEmoji())); } diff --git a/src/main/java/cc/fascinated/bat/service/CommandService.java b/src/main/java/cc/fascinated/bat/service/CommandService.java index 2384460..091c026 100644 --- a/src/main/java/cc/fascinated/bat/service/CommandService.java +++ b/src/main/java/cc/fascinated/bat/service/CommandService.java @@ -134,10 +134,17 @@ public class CommandService extends ListenerAdapter { * Gets commands that are in a specific category * * @param category The category + * @param includeGuildCommands If guild commands should be included * @return The commands */ - public List getCommandsByCategory(Category category) { - return commands.values().stream().filter(command -> command.getInfo().getCategory() == category).toList(); + public List getCommandsByCategory(Category category, boolean includeGuildCommands) { + List commands = new ArrayList<>(); + for (BatCommand command : this.commands.values()) { + if (command.getInfo().getCategory() == category && (includeGuildCommands || !command.getInfo().isGuildOnly())) { + commands.add(command); + } + } + return commands; } /**