From 0e781f3d9a565a91a5fa1fbeb01a501867a3be6a Mon Sep 17 00:00:00 2001 From: Liam Date: Thu, 4 Jul 2024 15:51:50 +0100 Subject: [PATCH] fix button interactions --- .../features/drag/listeners/request/RequestListener.java | 3 +++ .../drag/listeners/request/TargetChannelListener.java | 3 +++ .../bat/features/spotify/command/CurrentSubCommand.java | 3 +++ .../bat/features/spotify/command/LinkSubCommand.java | 3 +++ .../bat/features/tmdb/command/MovieSubCommand.java | 3 +++ .../bat/features/tmdb/command/SeriesSubCommand.java | 3 +++ src/main/java/cc/fascinated/bat/service/EventService.java | 6 +++--- 7 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/main/java/cc/fascinated/bat/features/drag/listeners/request/RequestListener.java b/src/main/java/cc/fascinated/bat/features/drag/listeners/request/RequestListener.java index aef6747..02aca3c 100644 --- a/src/main/java/cc/fascinated/bat/features/drag/listeners/request/RequestListener.java +++ b/src/main/java/cc/fascinated/bat/features/drag/listeners/request/RequestListener.java @@ -20,6 +20,9 @@ import java.util.Optional; public class RequestListener implements EventListener { @Override public void onButtonInteraction(BatGuild guild, @NonNull BatUser user, @NonNull ButtonInteractionEvent event) { + if (guild == null) { + return; + } if (!event.getComponentId().equals("drag-request-cancel")) { return; } diff --git a/src/main/java/cc/fascinated/bat/features/drag/listeners/request/TargetChannelListener.java b/src/main/java/cc/fascinated/bat/features/drag/listeners/request/TargetChannelListener.java index 87b0d8f..8542ecb 100644 --- a/src/main/java/cc/fascinated/bat/features/drag/listeners/request/TargetChannelListener.java +++ b/src/main/java/cc/fascinated/bat/features/drag/listeners/request/TargetChannelListener.java @@ -19,6 +19,9 @@ import org.springframework.stereotype.Component; public class TargetChannelListener implements EventListener { @Override public void onButtonInteraction(BatGuild guild, @NonNull BatUser user, @NonNull ButtonInteractionEvent event) { + if (guild == null) { + return; + } User buttonUser = event.getUser(); Member member = guild.getDiscordGuild().getMember(buttonUser); if (member == null) return; diff --git a/src/main/java/cc/fascinated/bat/features/spotify/command/CurrentSubCommand.java b/src/main/java/cc/fascinated/bat/features/spotify/command/CurrentSubCommand.java index cf74690..c3520c9 100644 --- a/src/main/java/cc/fascinated/bat/features/spotify/command/CurrentSubCommand.java +++ b/src/main/java/cc/fascinated/bat/features/spotify/command/CurrentSubCommand.java @@ -48,6 +48,9 @@ public class CurrentSubCommand extends BatCommand implements EventListener { @Override @SneakyThrows public void onButtonInteraction(BatGuild guild, @NonNull BatUser user, @NonNull ButtonInteractionEvent event) { + if (guild == null) { + return; + } if (!event.getUser().getId().equals(user.getId())) { throw new BatException("%s You cannot interact with this message.".formatted(Emojis.CROSS_MARK_EMOJI)); } diff --git a/src/main/java/cc/fascinated/bat/features/spotify/command/LinkSubCommand.java b/src/main/java/cc/fascinated/bat/features/spotify/command/LinkSubCommand.java index 2218298..6c90391 100644 --- a/src/main/java/cc/fascinated/bat/features/spotify/command/LinkSubCommand.java +++ b/src/main/java/cc/fascinated/bat/features/spotify/command/LinkSubCommand.java @@ -65,6 +65,9 @@ public class LinkSubCommand extends BatCommand implements EventListener { @Override public void onButtonInteraction(BatGuild guild, @NonNull BatUser user, @NonNull ButtonInteractionEvent event) { + if (guild == null) { + return; + } if (!event.getComponentId().equals("spotify_link")) { return; } diff --git a/src/main/java/cc/fascinated/bat/features/tmdb/command/MovieSubCommand.java b/src/main/java/cc/fascinated/bat/features/tmdb/command/MovieSubCommand.java index 6c3be71..de7b2a1 100644 --- a/src/main/java/cc/fascinated/bat/features/tmdb/command/MovieSubCommand.java +++ b/src/main/java/cc/fascinated/bat/features/tmdb/command/MovieSubCommand.java @@ -106,6 +106,9 @@ public class MovieSubCommand extends BatCommand implements EventListener { @Override public void onButtonInteraction(BatGuild guild, @NonNull BatUser user, @NonNull ButtonInteractionEvent event) { + if (guild == null) { + return; + } Map params = userCommands.get(user.getId()); if (params == null) { return; diff --git a/src/main/java/cc/fascinated/bat/features/tmdb/command/SeriesSubCommand.java b/src/main/java/cc/fascinated/bat/features/tmdb/command/SeriesSubCommand.java index 4895502..57f6724 100644 --- a/src/main/java/cc/fascinated/bat/features/tmdb/command/SeriesSubCommand.java +++ b/src/main/java/cc/fascinated/bat/features/tmdb/command/SeriesSubCommand.java @@ -103,6 +103,9 @@ public class SeriesSubCommand extends BatCommand implements EventListener { @Override public void onButtonInteraction(BatGuild guild, @NonNull BatUser user, @NonNull ButtonInteractionEvent event) { + if (guild == null) { + return; + } Map params = userCommands.get(user.getId()); if (params == null) { return; diff --git a/src/main/java/cc/fascinated/bat/service/EventService.java b/src/main/java/cc/fascinated/bat/service/EventService.java index 335dfab..aa7d67f 100644 --- a/src/main/java/cc/fascinated/bat/service/EventService.java +++ b/src/main/java/cc/fascinated/bat/service/EventService.java @@ -141,7 +141,7 @@ public class EventService extends ListenerAdapter { if (event.getUser().isBot()) { 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()); for (EventListener listener : LISTENERS) { @@ -154,7 +154,7 @@ public class EventService extends ListenerAdapter { if (event.getUser().isBot()) { 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()); try { @@ -172,7 +172,7 @@ public class EventService extends ListenerAdapter { if (event.getUser().isBot()) { 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()); try {