help menu use proper button ids
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 1m8s

This commit is contained in:
Lee 2024-07-04 14:57:54 +01:00
parent d70a29d363
commit d023e21575
2 changed files with 19 additions and 5 deletions

View File

@ -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<BatCommand> 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<SelectOption> 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[]{

View File

@ -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)