use a perm check for the list buttons

This commit is contained in:
Lee 2024-07-04 14:43:15 +01:00
parent 7bf468b470
commit d70a29d363

@ -44,14 +44,19 @@ public class ListSubCommand extends BatCommand implements EventListener {
@Override @Override
public void onButtonInteraction(BatGuild guild, @NonNull BatUser user, @NonNull ButtonInteractionEvent event) { public void onButtonInteraction(BatGuild guild, @NonNull BatUser user, @NonNull ButtonInteractionEvent event) {
if (guild == null) { if (guild == null || event.getMember() == null) {
return; return;
} }
// The person who clicked the button is not the person who executed the command // Not a log button
Message referencedMessage = event.getMessage().getReferencedMessage(); if (!event.getComponentId().startsWith("logs")) {
if (referencedMessage != null && !referencedMessage.getAuthor().getId().equals(user.getId())) { return;
event.reply("%s, you cannot use this button.".formatted(user.getDiscordUser().getAsMention())).setEphemeral(true).queue(); }
if (!event.getMember().hasPermission(this.getInfo().getPermissions())) {
event.reply("%s, you cannot use this button.".formatted(user.getDiscordUser().getAsMention()))
.setEphemeral(true)
.queue();
return; return;
} }
@ -61,11 +66,6 @@ public class ListSubCommand extends BatCommand implements EventListener {
return; return;
} }
// Not a log category
if (!event.getComponentId().startsWith("logs:list:")) {
return;
}
// Category // Category
String[] split = event.getComponentId().split(":"); String[] split = event.getComponentId().split(":");
if (split.length != 3) { if (split.length != 3) {