help menu use proper button ids
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 1m8s
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 1m8s
This commit is contained in:
parent
d70a29d363
commit
d023e21575
@ -11,7 +11,9 @@ import cc.fascinated.bat.model.BatUser;
|
|||||||
import cc.fascinated.bat.service.CommandService;
|
import cc.fascinated.bat.service.CommandService;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import net.dv8tion.jda.api.entities.Member;
|
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.MessageEmbed;
|
||||||
|
import net.dv8tion.jda.api.entities.MessageReference;
|
||||||
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
|
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
|
||||||
import net.dv8tion.jda.api.entities.emoji.Emoji;
|
import net.dv8tion.jda.api.entities.emoji.Emoji;
|
||||||
import net.dv8tion.jda.api.events.interaction.component.StringSelectInteractionEvent;
|
import net.dv8tion.jda.api.events.interaction.component.StringSelectInteractionEvent;
|
||||||
@ -50,18 +52,30 @@ public class HelpCommand extends BatCommand implements EventListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStringSelectInteraction(BatGuild guild, @NonNull BatUser user, @NonNull StringSelectInteractionEvent event) {
|
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();
|
String item = event.getSelectedOptions().get(0).getValue();
|
||||||
if (item.equalsIgnoreCase("home")) {
|
if (item.equalsIgnoreCase("home")) {
|
||||||
event.editMessageEmbeds(createHomeEmbed()).queue();
|
event.editMessageEmbeds(createHomeEmbed()).queue();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Category category = Category.getByName(item);
|
// Get the category
|
||||||
|
Category category = Category.getByName(item.split("-")[1]);
|
||||||
if (category == null) {
|
if (category == null) {
|
||||||
event.reply("Invalid category selected.").queue();
|
event.reply("Invalid category selected.")
|
||||||
|
.setEphemeral(true)
|
||||||
|
.queue();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Send the category
|
||||||
StringBuilder commands = new StringBuilder();
|
StringBuilder commands = new StringBuilder();
|
||||||
List<BatCommand> categoryCommands = commandService.getCommandsByCategory(category);
|
List<BatCommand> categoryCommands = commandService.getCommandsByCategory(category);
|
||||||
if (categoryCommands.isEmpty()) {
|
if (categoryCommands.isEmpty()) {
|
||||||
@ -88,7 +102,6 @@ public class HelpCommand extends BatCommand implements EventListener {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int subCommands = categoryCommands.stream().mapToInt(command -> command.getSubCommands().size()).sum();
|
int subCommands = categoryCommands.stream().mapToInt(command -> command.getSubCommands().size()).sum();
|
||||||
event.editMessageEmbeds(EmbedUtils.genericEmbed()
|
event.editMessageEmbeds(EmbedUtils.genericEmbed()
|
||||||
.setAuthor("%s Category".formatted(category.getName()))
|
.setAuthor("%s Category".formatted(category.getName()))
|
||||||
@ -138,9 +151,9 @@ public class HelpCommand extends BatCommand implements EventListener {
|
|||||||
*/
|
*/
|
||||||
private LayoutComponent[] createHomeActions() {
|
private LayoutComponent[] createHomeActions() {
|
||||||
List<SelectOption> options = new ArrayList<>();
|
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()) {
|
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[]{
|
return new LayoutComponent[]{
|
||||||
|
@ -53,6 +53,7 @@ public class ListSubCommand extends BatCommand implements EventListener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// No permissions
|
||||||
if (!event.getMember().hasPermission(this.getInfo().getPermissions())) {
|
if (!event.getMember().hasPermission(this.getInfo().getPermissions())) {
|
||||||
event.reply("%s, you cannot use this button.".formatted(user.getDiscordUser().getAsMention()))
|
event.reply("%s, you cannot use this button.".formatted(user.getDiscordUser().getAsMention()))
|
||||||
.setEphemeral(true)
|
.setEphemeral(true)
|
||||||
|
Loading…
Reference in New Issue
Block a user