diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/SlashCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/SlashCommand.java index c8644c1147..42dbc1c7a1 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/SlashCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/SlashCommand.java @@ -5,6 +5,7 @@ import net.dv8tion.jda.api.events.interaction.ButtonClickEvent; import net.dv8tion.jda.api.events.interaction.SelectionMenuEvent; import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; +import net.dv8tion.jda.api.hooks.EventListener; import net.dv8tion.jda.api.interactions.commands.build.CommandData; import net.dv8tion.jda.api.interactions.components.ButtonStyle; import net.dv8tion.jda.api.interactions.components.ComponentInteraction; @@ -36,7 +37,7 @@ *
* Some example commands are available in {@link org.togetherjava.tjbot.commands.basic}. */ -public interface SlashCommand { +public interface SlashCommand extends EventListener { /** * Gets the name of the command. diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/SlashCommandAdapter.java b/application/src/main/java/org/togetherjava/tjbot/commands/SlashCommandAdapter.java index 9b461b50fe..6bde9b319f 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/SlashCommandAdapter.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/SlashCommandAdapter.java @@ -4,6 +4,7 @@ import net.dv8tion.jda.api.events.interaction.ButtonClickEvent; import net.dv8tion.jda.api.events.interaction.SelectionMenuEvent; import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; +import net.dv8tion.jda.api.hooks.ListenerAdapter; import net.dv8tion.jda.api.interactions.commands.build.CommandData; import org.jetbrains.annotations.NotNull; import org.togetherjava.tjbot.commands.componentids.ComponentId; @@ -56,7 +57,7 @@ *
* and registration of an instance of that class in {@link Commands}. */ -public abstract class SlashCommandAdapter implements SlashCommand { +public abstract class SlashCommandAdapter extends ListenerAdapter implements SlashCommand { private final String name; private final String description; private final SlashCommandVisibility visibility; diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/free/FreeCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/free/FreeCommand.java index 707b3e24c8..984578b4bd 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/free/FreeCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/free/FreeCommand.java @@ -6,11 +6,9 @@ import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.entities.MessageEmbed; import net.dv8tion.jda.api.entities.TextChannel; -import net.dv8tion.jda.api.events.GenericEvent; import net.dv8tion.jda.api.events.ReadyEvent; import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent; -import net.dv8tion.jda.api.hooks.EventListener; import net.dv8tion.jda.api.requests.RestAction; import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; @@ -54,7 +52,7 @@ * channel may be one of the monitored channels however it is recommended that a different channel * is used. */ -public final class FreeCommand extends SlashCommandAdapter implements EventListener { +public final class FreeCommand extends SlashCommandAdapter { private static final Logger logger = LoggerFactory.getLogger(FreeCommand.class); private static final String STATUS_TITLE = "**__CHANNEL STATUS__**\n\n"; @@ -122,7 +120,7 @@ public void onReady(@NotNull final ReadyEvent event) { *
* If this is called on from a channel that was not configured for monitoring (see
* {@link FreeCommandConfig}) the user will receive an ephemeral message stating such.
- *
+ *
* @param event the event that triggered this
* @throws IllegalStateException if this method is called for a Global Slash Command
*/
@@ -285,31 +283,31 @@ private void checkBusyStatusAllChannels(@NotNull JDA jda) {
*
* @param event the generic event that includes the 'onGuildMessageReceived'.
*/
+
+
@Override
- public void onEvent(@NotNull GenericEvent event) {
- if (event instanceof GuildMessageReceivedEvent guildEvent) {
- if (guildEvent.isWebhookMessage() || guildEvent.getAuthor().isBot()) {
- return;
- }
- if (!channelMonitor.isMonitoringChannel(guildEvent.getChannel().getIdLong())) {
- logger.debug(
- "Channel is not being monitored, ignoring message received in {} from {}",
- guildEvent.getChannel().getName(), guildEvent.getAuthor());
- return;
- }
- if (channelMonitor.isChannelBusy(guildEvent.getChannel().getIdLong())) {
- logger.debug(
- "Channel status is currently busy, ignoring message received in {} from {}",
- guildEvent.getChannel().getName(), guildEvent.getAuthor());
- return;
- }
- channelMonitor.setChannelBusy(guildEvent.getChannel().getIdLong(),
- guildEvent.getAuthor().getIdLong());
- displayStatus(channelMonitor.getStatusChannelFor(guildEvent.getGuild()));
- guildEvent.getMessage().reply(UserStrings.NEW_QUESTION.message()).queue();
+ public void onGuildMessageReceived(@NotNull GuildMessageReceivedEvent event) {
+ if (event.isWebhookMessage() || event.getAuthor().isBot()) {
+ return;
}
+ if (!channelMonitor.isMonitoringChannel(event.getChannel().getIdLong())) {
+ logger.debug("Channel is not being monitored, ignoring message received in {} from {}",
+ event.getChannel().getName(), event.getAuthor());
+ return;
+ }
+ if (channelMonitor.isChannelBusy(event.getChannel().getIdLong())) {
+ logger.debug(
+ "Channel status is currently busy, ignoring message received in {} from {}",
+ event.getChannel().getName(), event.getAuthor());
+ return;
+ }
+ channelMonitor.setChannelBusy(event.getChannel().getIdLong(),
+ event.getAuthor().getIdLong());
+ displayStatus(channelMonitor.getStatusChannelFor(event.getGuild()));
+ event.getMessage().reply(UserStrings.NEW_QUESTION.message()).queue();
}
+
private @NotNull Optional