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 786a06d..8fb032a 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 @@ -11,7 +11,9 @@ import cc.fascinated.bat.model.BatUser; import cc.fascinated.bat.service.CommandService; import lombok.NonNull; import net.dv8tion.jda.api.entities.Member; +import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.entities.MessageEmbed; +import net.dv8tion.jda.api.entities.MessageReference; import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; import net.dv8tion.jda.api.entities.emoji.Emoji; import net.dv8tion.jda.api.events.interaction.component.StringSelectInteractionEvent; @@ -50,18 +52,30 @@ public class HelpCommand extends BatCommand implements EventListener { @Override public void onStringSelectInteraction(BatGuild guild, @NonNull BatUser user, @NonNull StringSelectInteractionEvent event) { + if (guild == null || event.getMember() == null) { + return; + } + if (!event.getComponentId().startsWith("help")) { + return; + } + + // Get the item String item = event.getSelectedOptions().get(0).getValue(); if (item.equalsIgnoreCase("home")) { event.editMessageEmbeds(createHomeEmbed()).queue(); return; } - Category category = Category.getByName(item); + // Get the category + Category category = Category.getByName(item.split("-")[1]); if (category == null) { - event.reply("Invalid category selected.").queue(); + event.reply("Invalid category selected.") + .setEphemeral(true) + .queue(); return; } + // Send the category StringBuilder commands = new StringBuilder(); List categoryCommands = commandService.getCommandsByCategory(category); if (categoryCommands.isEmpty()) { @@ -88,7 +102,6 @@ public class HelpCommand extends BatCommand implements EventListener { )); } } - int subCommands = categoryCommands.stream().mapToInt(command -> command.getSubCommands().size()).sum(); event.editMessageEmbeds(EmbedUtils.genericEmbed() .setAuthor("%s Category".formatted(category.getName())) @@ -138,9 +151,9 @@ 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.add(SelectOption.of("Home", "help-home").withEmoji(Emoji.fromUnicode("U+1F3E0"))); for (Category category : Category.values()) { - options.add(SelectOption.of(category.getName(), category.getName()).withEmoji(category.getEmoji())); + options.add(SelectOption.of(category.getName(), "help-" + category.getName()).withEmoji(category.getEmoji())); } return new LayoutComponent[]{ diff --git a/src/main/java/cc/fascinated/bat/features/logging/command/ListSubCommand.java b/src/main/java/cc/fascinated/bat/features/logging/command/ListSubCommand.java index 862615e..1eae20e 100644 --- a/src/main/java/cc/fascinated/bat/features/logging/command/ListSubCommand.java +++ b/src/main/java/cc/fascinated/bat/features/logging/command/ListSubCommand.java @@ -53,6 +53,7 @@ public class ListSubCommand extends BatCommand implements EventListener { return; } + // No permissions if (!event.getMember().hasPermission(this.getInfo().getPermissions())) { event.reply("%s, you cannot use this button.".formatted(user.getDiscordUser().getAsMention())) .setEphemeral(true)