fix button interactions

This commit is contained in:
Lee 2024-07-04 15:51:50 +01:00
parent c78033f409
commit 0e781f3d9a
7 changed files with 21 additions and 3 deletions

@ -20,6 +20,9 @@ import java.util.Optional;
public class RequestListener implements EventListener { public class RequestListener 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) {
return;
}
if (!event.getComponentId().equals("drag-request-cancel")) { if (!event.getComponentId().equals("drag-request-cancel")) {
return; return;
} }

@ -19,6 +19,9 @@ import org.springframework.stereotype.Component;
public class TargetChannelListener implements EventListener { public class TargetChannelListener 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) {
return;
}
User buttonUser = event.getUser(); User buttonUser = event.getUser();
Member member = guild.getDiscordGuild().getMember(buttonUser); Member member = guild.getDiscordGuild().getMember(buttonUser);
if (member == null) return; if (member == null) return;

@ -48,6 +48,9 @@ public class CurrentSubCommand extends BatCommand implements EventListener {
@Override @SneakyThrows @Override @SneakyThrows
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) {
return;
}
if (!event.getUser().getId().equals(user.getId())) { if (!event.getUser().getId().equals(user.getId())) {
throw new BatException("%s You cannot interact with this message.".formatted(Emojis.CROSS_MARK_EMOJI)); throw new BatException("%s You cannot interact with this message.".formatted(Emojis.CROSS_MARK_EMOJI));
} }

@ -65,6 +65,9 @@ public class LinkSubCommand 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) {
return;
}
if (!event.getComponentId().equals("spotify_link")) { if (!event.getComponentId().equals("spotify_link")) {
return; return;
} }

@ -106,6 +106,9 @@ public class MovieSubCommand 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) {
return;
}
Map<String, String> params = userCommands.get(user.getId()); Map<String, String> params = userCommands.get(user.getId());
if (params == null) { if (params == null) {
return; return;

@ -103,6 +103,9 @@ public class SeriesSubCommand 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) {
return;
}
Map<String, String> params = userCommands.get(user.getId()); Map<String, String> params = userCommands.get(user.getId());
if (params == null) { if (params == null) {
return; return;

@ -141,7 +141,7 @@ public class EventService extends ListenerAdapter {
if (event.getUser().isBot()) { if (event.getUser().isBot()) {
return; return;
} }
BatGuild guild = event.getGuild() != null ? guildService.getGuild(event.getGuild().getId()) : null; BatGuild guild = event.getGuild() == null ? null : guildService.getGuild(event.getGuild().getId());
BatUser user = userService.getUser(event.getUser().getId(), event.getUser()); BatUser user = userService.getUser(event.getUser().getId(), event.getUser());
for (EventListener listener : LISTENERS) { for (EventListener listener : LISTENERS) {
@ -154,7 +154,7 @@ public class EventService extends ListenerAdapter {
if (event.getUser().isBot()) { if (event.getUser().isBot()) {
return; return;
} }
BatGuild guild = event.getGuild() != null ? guildService.getGuild(event.getGuild().getId()) : null; BatGuild guild = event.getGuild() == null ? null : guildService.getGuild(event.getGuild().getId());
BatUser user = userService.getUser(event.getUser().getId(), event.getUser()); BatUser user = userService.getUser(event.getUser().getId(), event.getUser());
try { try {
@ -172,7 +172,7 @@ public class EventService extends ListenerAdapter {
if (event.getUser().isBot()) { if (event.getUser().isBot()) {
return; return;
} }
BatGuild guild = event.getGuild() != null ? guildService.getGuild(event.getGuild().getId()) : null; BatGuild guild = event.getGuild() == null ? null : guildService.getGuild(event.getGuild().getId());
BatUser user = userService.getUser(event.getUser().getId(), event.getUser()); BatUser user = userService.getUser(event.getUser().getId(), event.getUser());
try { try {