diff --git a/application/build.gradle b/application/build.gradle index a92f80e921..8ad0429d9d 100644 --- a/application/build.gradle +++ b/application/build.gradle @@ -46,7 +46,7 @@ dependencies { implementation project(':utils') implementation project(':formatter') - implementation 'net.dv8tion:JDA:5.0.0-alpha.20' + implementation 'net.dv8tion:JDA:5.0.0-beta.21' implementation 'org.apache.logging.log4j:log4j-core:2.23.0' runtimeOnly 'org.apache.logging.log4j:log4j-slf4j18-impl:2.18.0' diff --git a/application/src/main/java/org/togetherjava/tjbot/features/BotCommand.java b/application/src/main/java/org/togetherjava/tjbot/features/BotCommand.java index 7c0cf3af19..c99ac0360a 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/BotCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/BotCommand.java @@ -1,7 +1,8 @@ package org.togetherjava.tjbot.features; import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; -import net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent; +import net.dv8tion.jda.api.events.interaction.component.EntitySelectInteractionEvent; +import net.dv8tion.jda.api.events.interaction.component.StringSelectInteractionEvent; import net.dv8tion.jda.api.interactions.commands.build.CommandData; import java.util.List; @@ -19,7 +20,8 @@ *

* After registration, the system will notify a command whenever one of its corresponding command * method, buttons ({@link #onButtonClick(ButtonInteractionEvent, List)}) or menus - * ({@link #onSelectMenuSelection(SelectMenuInteractionEvent, List)}) have been triggered. + * ({@link #onEntitySelectSelection(EntitySelectInteractionEvent, List)}, + * {@link #onStringSelectSelection(StringSelectInteractionEvent, List)}) have been triggered. *

* Some example commands are available in {@link org.togetherjava.tjbot.features.basic}. */ diff --git a/application/src/main/java/org/togetherjava/tjbot/features/BotCommandAdapter.java b/application/src/main/java/org/togetherjava/tjbot/features/BotCommandAdapter.java index 421ff745d5..471222df2a 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/BotCommandAdapter.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/BotCommandAdapter.java @@ -3,7 +3,8 @@ import net.dv8tion.jda.api.events.interaction.ModalInteractionEvent; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; -import net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent; +import net.dv8tion.jda.api.events.interaction.component.EntitySelectInteractionEvent; +import net.dv8tion.jda.api.events.interaction.component.StringSelectInteractionEvent; import net.dv8tion.jda.api.interactions.commands.Command; import net.dv8tion.jda.api.interactions.commands.build.CommandData; import org.jetbrains.annotations.Contract; @@ -20,9 +21,10 @@ * their respective command method. A new command can then be registered by adding it to * {@link Features}. *

- * Further, {@link #onButtonClick(ButtonInteractionEvent, List)} and - * {@link #onSelectMenuSelection(SelectMenuInteractionEvent, List)} can be overridden if desired. - * The default implementation is empty, the adapter will not react to such events. + * Further, {@link #onButtonClick(ButtonInteractionEvent, List)}, + * {@link #onEntitySelectSelection(EntitySelectInteractionEvent, List)} and + * {@link #onStringSelectSelection(StringSelectInteractionEvent, List)} can be overridden if + * desired. The default implementation is empty, the adapter will not react to such events. *

* The adapter manages some getters for you, you've to create the {@link CommandData} yourself. See * {@link #BotCommandAdapter(CommandData, CommandVisibility)}} for more info on that. Minimal @@ -101,7 +103,13 @@ public void onButtonClick(ButtonInteractionEvent event, List args) { @SuppressWarnings("NoopMethodInAbstractClass") @Override - public void onSelectMenuSelection(SelectMenuInteractionEvent event, List args) { + public void onEntitySelectSelection(EntitySelectInteractionEvent event, List args) { + // Adapter does not react by default, subclasses may change this behavior + } + + @SuppressWarnings("NoopMethodInAbstractClass") + @Override + public void onStringSelectSelection(StringSelectInteractionEvent event, List args) { // Adapter does not react by default, subclasses may change this behavior } diff --git a/application/src/main/java/org/togetherjava/tjbot/features/MessageContextCommand.java b/application/src/main/java/org/togetherjava/tjbot/features/MessageContextCommand.java index 2a499176fe..83d9df594f 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/MessageContextCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/MessageContextCommand.java @@ -2,7 +2,8 @@ import net.dv8tion.jda.api.events.interaction.command.MessageContextInteractionEvent; import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; -import net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent; +import net.dv8tion.jda.api.events.interaction.component.EntitySelectInteractionEvent; +import net.dv8tion.jda.api.events.interaction.component.StringSelectInteractionEvent; import net.dv8tion.jda.api.interactions.commands.build.CommandData; import net.dv8tion.jda.api.interactions.components.ComponentInteraction; import net.dv8tion.jda.api.interactions.components.buttons.ButtonStyle; @@ -29,7 +30,8 @@ * After registration, the system will notify a command whenever one of its corresponding message * context-commands ({@link #onMessageContext(MessageContextInteractionEvent)}), buttons * ({@link #onButtonClick(ButtonInteractionEvent, List)}) or menus - * ({@link #onSelectMenuSelection(SelectMenuInteractionEvent, List)}) have been triggered. + * ({@link #onEntitySelectSelection(EntitySelectInteractionEvent, List)}, + * {@link #onStringSelectSelection(StringSelectInteractionEvent, List)}) have been triggered. *

* Some example commands are available in {@link org.togetherjava.tjbot.features.basic}. */ diff --git a/application/src/main/java/org/togetherjava/tjbot/features/SlashCommand.java b/application/src/main/java/org/togetherjava/tjbot/features/SlashCommand.java index 0fdb69f20a..87cd91e187 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/SlashCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/SlashCommand.java @@ -3,7 +3,8 @@ import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; -import net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent; +import net.dv8tion.jda.api.events.interaction.component.EntitySelectInteractionEvent; +import net.dv8tion.jda.api.events.interaction.component.StringSelectInteractionEvent; import net.dv8tion.jda.api.interactions.commands.build.CommandData; import net.dv8tion.jda.api.interactions.commands.build.Commands; import net.dv8tion.jda.api.interactions.commands.build.OptionData; @@ -35,7 +36,8 @@ * After registration, the system will notify a command whenever one of its corresponding slash * commands ({@link #onSlashCommand(SlashCommandInteractionEvent)}), buttons * ({@link #onButtonClick(ButtonInteractionEvent, List)}) or menus - * ({@link #onSelectMenuSelection(SelectMenuInteractionEvent, List)}) have been triggered. + * ({@link #onEntitySelectSelection(EntitySelectInteractionEvent, List)}, + * {@link #onStringSelectSelection(StringSelectInteractionEvent, List)}) have been triggered. *

* Some example commands are available in {@link org.togetherjava.tjbot.features.basic}. */ diff --git a/application/src/main/java/org/togetherjava/tjbot/features/SlashCommandAdapter.java b/application/src/main/java/org/togetherjava/tjbot/features/SlashCommandAdapter.java index 43c5a01020..f5ef769f75 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/SlashCommandAdapter.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/SlashCommandAdapter.java @@ -3,7 +3,8 @@ import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; -import net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent; +import net.dv8tion.jda.api.events.interaction.component.EntitySelectInteractionEvent; +import net.dv8tion.jda.api.events.interaction.component.StringSelectInteractionEvent; import net.dv8tion.jda.api.interactions.commands.CommandInteractionPayload; import net.dv8tion.jda.api.interactions.commands.OptionMapping; import net.dv8tion.jda.api.interactions.commands.build.CommandData; @@ -22,9 +23,10 @@ * of {@link #onSlashCommand(SlashCommandInteractionEvent)}. A new command can then be registered by * adding it to {@link Features}. *

- * Further, {@link #onButtonClick(ButtonInteractionEvent, List)} and - * {@link #onSelectMenuSelection(SelectMenuInteractionEvent, List)} can be overridden if desired. - * The default implementation is empty, the adapter will not react to such events. + * Further, {@link #onButtonClick(ButtonInteractionEvent, List)}, + * {@link #onEntitySelectSelection(EntitySelectInteractionEvent, List)} and + * {@link #onStringSelectSelection(StringSelectInteractionEvent, List)} can be overridden if + * desired. The default implementation is empty, the adapter will not react to such events. *

* The adapter manages all command related data itself, which can be provided during construction * (see {@link #SlashCommandAdapter(String, String, CommandVisibility)}). In order to add options, diff --git a/application/src/main/java/org/togetherjava/tjbot/features/UserContextCommand.java b/application/src/main/java/org/togetherjava/tjbot/features/UserContextCommand.java index 57aa3f7949..144c81dbe0 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/UserContextCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/UserContextCommand.java @@ -2,7 +2,8 @@ import net.dv8tion.jda.api.events.interaction.command.UserContextInteractionEvent; import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; -import net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent; +import net.dv8tion.jda.api.events.interaction.component.EntitySelectInteractionEvent; +import net.dv8tion.jda.api.events.interaction.component.StringSelectInteractionEvent; import net.dv8tion.jda.api.interactions.commands.build.CommandData; import net.dv8tion.jda.api.interactions.components.ComponentInteraction; import net.dv8tion.jda.api.interactions.components.buttons.ButtonStyle; @@ -30,7 +31,8 @@ * After registration, the system will notify a command whenever one of its corresponding user * context-commands ({@link #onUserContext(UserContextInteractionEvent)}), buttons * ({@link #onButtonClick(ButtonInteractionEvent, List)}) or menus - * ({@link #onSelectMenuSelection(SelectMenuInteractionEvent, List)}) have been triggered. + * ({@link #onStringSelectSelection(StringSelectInteractionEvent, List)}, + * {@link #onEntitySelectSelection(EntitySelectInteractionEvent, List)}) have been triggered. *

* Some example commands are available in {@link org.togetherjava.tjbot.features.basic}. */ diff --git a/application/src/main/java/org/togetherjava/tjbot/features/UserInteractor.java b/application/src/main/java/org/togetherjava/tjbot/features/UserInteractor.java index 6adaf1d0e7..c18c8b1dfc 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/UserInteractor.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/UserInteractor.java @@ -3,7 +3,8 @@ import net.dv8tion.jda.api.events.interaction.ModalInteractionEvent; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; -import net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent; +import net.dv8tion.jda.api.events.interaction.component.EntitySelectInteractionEvent; +import net.dv8tion.jda.api.events.interaction.component.StringSelectInteractionEvent; import org.togetherjava.tjbot.features.componentids.ComponentId; import org.togetherjava.tjbot.features.componentids.ComponentIdGenerator; @@ -20,7 +21,6 @@ * if their type is different, all the types can be seen in {@link UserInteractionType} */ public interface UserInteractor extends Feature { - /** * Gets the name of the interactor. *

@@ -58,11 +58,14 @@ public interface UserInteractor extends Feature { * {@link SlashCommand#onSlashCommand(SlashCommandInteractionEvent)} for details on how * these are created */ - void onButtonClick(ButtonInteractionEvent event, List args); + @SuppressWarnings("NoopMethodInInterface") + default void onButtonClick(ButtonInteractionEvent event, List args) { + // Interface does not react by default, implementations may change this behaviour + } /** - * Triggered by the core system when a selection menu corresponding to this implementation - * (based on {@link #getName()}) has been clicked. + * Triggered by the core system when an entity selection menu corresponding to this + * implementation (based on {@link #getName()}) has been clicked. *

* This method may be called multithreaded. In particular, there are no guarantees that it will * be executed on the same thread repeatedly or on the same thread that other event methods have @@ -76,8 +79,31 @@ public interface UserInteractor extends Feature { * {@link SlashCommand#onSlashCommand(SlashCommandInteractionEvent)} for details on how * these are created */ - void onSelectMenuSelection(SelectMenuInteractionEvent event, List args); + @SuppressWarnings("NoopMethodInInterface") + default void onEntitySelectSelection(EntitySelectInteractionEvent event, List args) { + // Interface does not react by default, implementations may change this behaviour + } + /** + * Triggered by the core system when a string selection menu corresponding to this + * implementation (based on {@link #getName()}) has been clicked. + *

+ * This method may be called multithreaded. In particular, there are no guarantees that it will + * be executed on the same thread repeatedly or on the same thread that other event methods have + * been called on. + *

+ * Details are available in the given event and the event also enables implementations to + * respond to it. + * + * @param event the event that triggered this + * @param args the arguments transported with the selection menu, see + * {@link SlashCommand#onSlashCommand(SlashCommandInteractionEvent)} for details on how + * these are created + */ + @SuppressWarnings("NoopMethodInInterface") + default void onStringSelectSelection(StringSelectInteractionEvent event, List args) { + // Interface does not react by default, implementations may change this behaviour + } /** * Triggered by the core system when a modal corresponding to this implementation (based on @@ -95,7 +121,10 @@ public interface UserInteractor extends Feature { * {@link SlashCommand#onSlashCommand(SlashCommandInteractionEvent)} for details on how * these are created */ - void onModalSubmitted(ModalInteractionEvent event, List args); + @SuppressWarnings("NoopMethodInInterface") + default void onModalSubmitted(ModalInteractionEvent event, List args) { + // Interface does not react by default, implementations may change this behaviour + } /** * Triggered by the core system during its setup phase. It will provide the command a component @@ -110,7 +139,8 @@ public interface UserInteractor extends Feature { * given to this method during system setup. The required {@link ComponentId} instance accepts * optional extra arguments, which, if provided, can be picked up during the corresponding event * (see {@link #onButtonClick(ButtonInteractionEvent, List)}, - * {@link #onSelectMenuSelection(SelectMenuInteractionEvent, List)}). + * {@link #onEntitySelectSelection(EntitySelectInteractionEvent, List)}, + * {@link #onStringSelectSelection(StringSelectInteractionEvent, List)}). *

* Alternatively, if {@link BotCommandAdapter} has been extended, it also offers a handy * {@link BotCommandAdapter#generateComponentId(String...)} method to ease the flow. diff --git a/application/src/main/java/org/togetherjava/tjbot/features/basic/RoleSelectCommand.java b/application/src/main/java/org/togetherjava/tjbot/features/basic/RoleSelectCommand.java index ae33bb7503..7cf0dd5b69 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/basic/RoleSelectCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/basic/RoleSelectCommand.java @@ -5,14 +5,14 @@ import net.dv8tion.jda.api.entities.*; import net.dv8tion.jda.api.entities.emoji.Emoji; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; -import net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent; +import net.dv8tion.jda.api.events.interaction.component.StringSelectInteractionEvent; import net.dv8tion.jda.api.interactions.callbacks.IReplyCallback; import net.dv8tion.jda.api.interactions.commands.CommandInteraction; import net.dv8tion.jda.api.interactions.commands.OptionMapping; import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.build.OptionData; -import net.dv8tion.jda.api.interactions.components.selections.SelectMenu; import net.dv8tion.jda.api.interactions.components.selections.SelectOption; +import net.dv8tion.jda.api.interactions.components.selections.StringSelectMenu; import org.jetbrains.annotations.Contract; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -175,11 +175,11 @@ private static boolean handleInteractableRolesSelected(IReplyCallback event, private void sendRoleSelectionMenu(final CommandInteraction event, final Collection selectableRoles) { - SelectMenu.Builder menu = - SelectMenu.create(generateComponentId(Lifespan.PERMANENT, event.getUser().getId())) - .setPlaceholder("Select your roles") - .setMinValues(0) - .setMaxValues(selectableRoles.size()); + StringSelectMenu.Builder menu = StringSelectMenu + .create(generateComponentId(Lifespan.PERMANENT, event.getUser().getId())) + .setPlaceholder("Select your roles") + .setMinValues(0) + .setMaxValues(selectableRoles.size()); selectableRoles.stream() .map(RoleSelectCommand::mapToSelectOption) @@ -203,8 +203,10 @@ private static SelectOption mapToSelectOption(Role role) { return option; } + // this should be entity select menu but im just gonna use string rn + // coz i'll have to do least changes that way @Override - public void onSelectMenuSelection(SelectMenuInteractionEvent event, List args) { + public void onStringSelectSelection(StringSelectInteractionEvent event, List args) { Guild guild = event.getGuild(); List selectedRoles = event.getSelectedOptions() .stream() @@ -220,7 +222,7 @@ public void onSelectMenuSelection(SelectMenuInteractionEvent event, List handleRoleSelection(event, guild, selectedRoles); } - private static void handleRoleSelection(SelectMenuInteractionEvent event, Guild guild, + private static void handleRoleSelection(StringSelectInteractionEvent event, Guild guild, Collection selectedRoles) { Collection rolesToAdd = new ArrayList<>(selectedRoles.size()); Collection rolesToRemove = new ArrayList<>(selectedRoles.size()); diff --git a/application/src/main/java/org/togetherjava/tjbot/features/bookmarks/BookmarksCommand.java b/application/src/main/java/org/togetherjava/tjbot/features/bookmarks/BookmarksCommand.java index d391ac299f..8122dc5172 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/bookmarks/BookmarksCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/bookmarks/BookmarksCommand.java @@ -4,7 +4,7 @@ import net.dv8tion.jda.api.entities.channel.unions.MessageChannelUnion; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; -import net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent; +import net.dv8tion.jda.api.events.interaction.component.StringSelectInteractionEvent; import net.dv8tion.jda.api.interactions.commands.OptionMapping; import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.build.OptionData; @@ -116,7 +116,7 @@ public void onButtonClick(ButtonInteractionEvent event, List args) { } @Override - public void onSelectMenuSelection(SelectMenuInteractionEvent event, List args) { + public void onStringSelectSelection(StringSelectInteractionEvent event, List args) { listRemoveHandler.onSelectMenuSelection(event, args); } diff --git a/application/src/main/java/org/togetherjava/tjbot/features/bookmarks/BookmarksListRemoveHandler.java b/application/src/main/java/org/togetherjava/tjbot/features/bookmarks/BookmarksListRemoveHandler.java index 909b9b7f57..4832e1ef4f 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/bookmarks/BookmarksListRemoveHandler.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/bookmarks/BookmarksListRemoveHandler.java @@ -7,13 +7,14 @@ import net.dv8tion.jda.api.entities.emoji.Emoji; import net.dv8tion.jda.api.events.interaction.command.GenericCommandInteractionEvent; import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; -import net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent; +import net.dv8tion.jda.api.events.interaction.component.StringSelectInteractionEvent; import net.dv8tion.jda.api.interactions.components.ActionRow; import net.dv8tion.jda.api.interactions.components.ComponentInteraction; import net.dv8tion.jda.api.interactions.components.LayoutComponent; import net.dv8tion.jda.api.interactions.components.buttons.Button; import net.dv8tion.jda.api.interactions.components.selections.SelectMenu; import net.dv8tion.jda.api.interactions.components.selections.SelectOption; +import net.dv8tion.jda.api.interactions.components.selections.StringSelectMenu; import org.togetherjava.tjbot.db.generated.tables.records.BookmarksRecord; import org.togetherjava.tjbot.features.utils.MessageUtils; @@ -157,7 +158,7 @@ private void removeSelectedBookmarks(List bookmarks, bookmarksSystem.removeBookmarks(userID, request.bookmarkIdsToRemove); } - void onSelectMenuSelection(SelectMenuInteractionEvent event, List args) { + void onSelectMenuSelection(StringSelectInteractionEvent event, List args) { Request request = Request.fromArgs(args); if (request.type != RequestType.REMOVE) { @@ -244,7 +245,7 @@ private List generateRemoveComponents(JDA jda, }).toList(); String selectMenuRemoveId = generateRemoveComponentId.apply(SELECT_MENU_REMOVE_NAME); - SelectMenu selectMenuRemove = SelectMenu.create(selectMenuRemoveId) + SelectMenu selectMenuRemove = StringSelectMenu.create(selectMenuRemoveId) .setPlaceholder("Select bookmarks to delete") .addOptions(selectMenuRemoveOptions) .setDefaultValues(bookmarksToRemoveChannelIDs.stream().map(String::valueOf).toList()) diff --git a/application/src/main/java/org/togetherjava/tjbot/features/chatgpt/ChatGptCommand.java b/application/src/main/java/org/togetherjava/tjbot/features/chatgpt/ChatGptCommand.java index 38bb5fc400..d58c7d8377 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/chatgpt/ChatGptCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/chatgpt/ChatGptCommand.java @@ -6,9 +6,9 @@ import net.dv8tion.jda.api.entities.SelfUser; import net.dv8tion.jda.api.events.interaction.ModalInteractionEvent; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; -import net.dv8tion.jda.api.interactions.components.Modal; import net.dv8tion.jda.api.interactions.components.text.TextInput; import net.dv8tion.jda.api.interactions.components.text.TextInputStyle; +import net.dv8tion.jda.api.interactions.modals.Modal; import org.togetherjava.tjbot.features.CommandVisibility; import org.togetherjava.tjbot.features.SlashCommandAdapter; diff --git a/application/src/main/java/org/togetherjava/tjbot/features/code/CodeMessageHandler.java b/application/src/main/java/org/togetherjava/tjbot/features/code/CodeMessageHandler.java index 916cef8bb6..e64a7f727e 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/code/CodeMessageHandler.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/code/CodeMessageHandler.java @@ -3,9 +3,7 @@ import com.github.benmanes.caffeine.cache.Cache; import com.github.benmanes.caffeine.cache.Caffeine; import net.dv8tion.jda.api.entities.Message; -import net.dv8tion.jda.api.events.interaction.ModalInteractionEvent; import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; -import net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent; import net.dv8tion.jda.api.events.message.MessageDeleteEvent; import net.dv8tion.jda.api.events.message.MessageUpdateEvent; import net.dv8tion.jda.api.interactions.components.buttons.Button; @@ -93,16 +91,6 @@ public UserInteractionType getInteractionType() { return UserInteractionType.OTHER; } - @Override - public void onSelectMenuSelection(SelectMenuInteractionEvent event, List args) { - throw new UnsupportedOperationException("Not used"); - } - - @Override - public void onModalSubmitted(ModalInteractionEvent event, List args) { - throw new UnsupportedOperationException("Not used"); - } - @Override public void acceptComponentIdGenerator(ComponentIdGenerator generator) { componentIdInteractor.acceptComponentIdGenerator(generator); diff --git a/application/src/main/java/org/togetherjava/tjbot/features/filesharing/FileSharingMessageListener.java b/application/src/main/java/org/togetherjava/tjbot/features/filesharing/FileSharingMessageListener.java index 9a3524fbea..3ba6910961 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/filesharing/FileSharingMessageListener.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/filesharing/FileSharingMessageListener.java @@ -6,9 +6,7 @@ import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.entities.channel.ChannelType; import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel; -import net.dv8tion.jda.api.events.interaction.ModalInteractionEvent; import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; -import net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.interactions.components.buttons.Button; import org.kohsuke.github.GHGist; @@ -218,14 +216,4 @@ public void acceptComponentIdGenerator(ComponentIdGenerator generator) { public UserInteractionType getInteractionType() { return UserInteractionType.OTHER; } - - @Override - public void onSelectMenuSelection(SelectMenuInteractionEvent event, List args) { - throw new UnsupportedOperationException("Not used"); - } - - @Override - public void onModalSubmitted(ModalInteractionEvent event, List args) { - throw new UnsupportedOperationException("Not used"); - } } diff --git a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadCreatedListener.java b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadCreatedListener.java index 42ef619e53..f048723d09 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadCreatedListener.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadCreatedListener.java @@ -10,9 +10,7 @@ import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel; import net.dv8tion.jda.api.entities.channel.forums.ForumTag; import net.dv8tion.jda.api.events.channel.ChannelCreateEvent; -import net.dv8tion.jda.api.events.interaction.ModalInteractionEvent; import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; -import net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; import net.dv8tion.jda.api.requests.RestAction; @@ -39,7 +37,6 @@ */ public final class HelpThreadCreatedListener extends ListenerAdapter implements EventReceiver, UserInteractor { - private final HelpSystemHelper helper; private final Cache threadIdToCreatedAtCache = Caffeine.newBuilder() @@ -194,16 +191,6 @@ public void onButtonClick(ButtonInteractionEvent event, List args) { } - @Override - public void onSelectMenuSelection(SelectMenuInteractionEvent event, List args) { - throw new UnsupportedOperationException("Not used"); - } - - @Override - public void onModalSubmitted(ModalInteractionEvent event, List args) { - throw new UnsupportedOperationException("Not used"); - } - private boolean isPostAuthor(Member interactionUser, Message message) { if (message.getEmbeds().isEmpty()) { return false; diff --git a/application/src/main/java/org/togetherjava/tjbot/features/jshell/JShellCommand.java b/application/src/main/java/org/togetherjava/tjbot/features/jshell/JShellCommand.java index b0eae75704..fbadddc9f2 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/jshell/JShellCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/jshell/JShellCommand.java @@ -11,9 +11,9 @@ import net.dv8tion.jda.api.interactions.commands.OptionMapping; import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.build.SubcommandData; -import net.dv8tion.jda.api.interactions.components.Modal; import net.dv8tion.jda.api.interactions.components.text.TextInput; import net.dv8tion.jda.api.interactions.components.text.TextInputStyle; +import net.dv8tion.jda.api.interactions.modals.Modal; import net.dv8tion.jda.api.interactions.modals.ModalMapping; import net.dv8tion.jda.api.utils.FileUpload; diff --git a/application/src/main/java/org/togetherjava/tjbot/features/moderation/ReportCommand.java b/application/src/main/java/org/togetherjava/tjbot/features/moderation/ReportCommand.java index 4951ddbaee..e56f56be60 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/moderation/ReportCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/moderation/ReportCommand.java @@ -9,10 +9,10 @@ import net.dv8tion.jda.api.events.interaction.command.MessageContextInteractionEvent; import net.dv8tion.jda.api.interactions.InteractionHook; import net.dv8tion.jda.api.interactions.commands.build.Commands; -import net.dv8tion.jda.api.interactions.components.Modal; import net.dv8tion.jda.api.interactions.components.buttons.Button; import net.dv8tion.jda.api.interactions.components.text.TextInput; import net.dv8tion.jda.api.interactions.components.text.TextInputStyle; +import net.dv8tion.jda.api.interactions.modals.Modal; import net.dv8tion.jda.api.requests.restaction.MessageCreateAction; import net.dv8tion.jda.api.utils.Result; import org.slf4j.Logger; diff --git a/application/src/main/java/org/togetherjava/tjbot/features/moderation/TransferQuestionCommand.java b/application/src/main/java/org/togetherjava/tjbot/features/moderation/TransferQuestionCommand.java index ff17e64f0d..aadf9ab61a 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/moderation/TransferQuestionCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/moderation/TransferQuestionCommand.java @@ -16,10 +16,10 @@ import net.dv8tion.jda.api.events.interaction.command.MessageContextInteractionEvent; import net.dv8tion.jda.api.exceptions.ErrorResponseException; import net.dv8tion.jda.api.interactions.commands.build.Commands; -import net.dv8tion.jda.api.interactions.components.Modal; import net.dv8tion.jda.api.interactions.components.text.TextInput; import net.dv8tion.jda.api.interactions.components.text.TextInput.Builder; import net.dv8tion.jda.api.interactions.components.text.TextInputStyle; +import net.dv8tion.jda.api.interactions.modals.Modal; import net.dv8tion.jda.api.requests.ErrorResponse; import net.dv8tion.jda.api.requests.RestAction; import net.dv8tion.jda.api.requests.restaction.WebhookMessageCreateAction; diff --git a/application/src/main/java/org/togetherjava/tjbot/features/moderation/modmail/ModMailCommand.java b/application/src/main/java/org/togetherjava/tjbot/features/moderation/modmail/ModMailCommand.java index e821ccec2a..7737f0ae0c 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/moderation/modmail/ModMailCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/moderation/modmail/ModMailCommand.java @@ -14,9 +14,9 @@ import net.dv8tion.jda.api.interactions.commands.Command; import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.build.OptionData; -import net.dv8tion.jda.api.interactions.components.Modal; import net.dv8tion.jda.api.interactions.components.text.TextInput; import net.dv8tion.jda.api.interactions.components.text.TextInputStyle; +import net.dv8tion.jda.api.interactions.modals.Modal; import net.dv8tion.jda.api.requests.restaction.MessageCreateAction; import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; diff --git a/application/src/main/java/org/togetherjava/tjbot/features/moderation/scam/ScamBlocker.java b/application/src/main/java/org/togetherjava/tjbot/features/moderation/scam/ScamBlocker.java index 8d6af465d6..f60dc91b41 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/moderation/scam/ScamBlocker.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/moderation/scam/ScamBlocker.java @@ -5,9 +5,7 @@ import net.dv8tion.jda.api.entities.*; import net.dv8tion.jda.api.entities.channel.concrete.PrivateChannel; import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; -import net.dv8tion.jda.api.events.interaction.ModalInteractionEvent; import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; -import net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.exceptions.ErrorHandler; import net.dv8tion.jda.api.interactions.components.buttons.Button; @@ -99,16 +97,6 @@ public UserInteractionType getInteractionType() { return UserInteractionType.OTHER; } - @Override - public void onSelectMenuSelection(SelectMenuInteractionEvent event, List args) { - throw new UnsupportedOperationException("Not used"); - } - - @Override - public void onModalSubmitted(ModalInteractionEvent event, List args) { - throw new UnsupportedOperationException("Not used"); - } - @Override public void acceptComponentIdGenerator(ComponentIdGenerator generator) { componentIdInteractor.acceptComponentIdGenerator(generator); diff --git a/application/src/main/java/org/togetherjava/tjbot/features/system/BotCore.java b/application/src/main/java/org/togetherjava/tjbot/features/system/BotCore.java index efa539db49..83f7496496 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/system/BotCore.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/system/BotCore.java @@ -8,7 +8,8 @@ import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; import net.dv8tion.jda.api.events.interaction.command.UserContextInteractionEvent; import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; -import net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent; +import net.dv8tion.jda.api.events.interaction.component.EntitySelectInteractionEvent; +import net.dv8tion.jda.api.events.interaction.component.StringSelectInteractionEvent; import net.dv8tion.jda.api.events.message.MessageDeleteEvent; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.events.message.MessageUpdateEvent; @@ -248,7 +249,7 @@ public void onCommandAutoCompleteInteraction(final CommandAutoCompleteInteractio String name = event.getName(); logger.debug("Received auto completion from command '{}' (#{}) on guild '{}'", - event.getCommandPath(), event.getId(), event.getGuild()); + event.getFullCommandName(), event.getId(), event.getGuild()); COMMAND_SERVICE.execute( () -> requireUserInteractor(UserInteractionType.SLASH_COMMAND.getPrefixedName(name), SlashCommand.class).onAutoComplete(event)); @@ -263,11 +264,19 @@ public void onButtonInteraction(ButtonInteractionEvent event) { } @Override - public void onSelectMenuInteraction(SelectMenuInteractionEvent event) { - logger.debug("Received selection menu event '{}' (#{}) on guild '{}'", + public void onEntitySelectInteraction(EntitySelectInteractionEvent event) { + logger.debug("Received entity selection menu event '{}' (#{}) on guild '{}'", event.getComponentId(), event.getId(), event.getGuild()); COMMAND_SERVICE - .execute(() -> forwardComponentCommand(event, UserInteractor::onSelectMenuSelection)); + .execute(() -> forwardComponentCommand(event, UserInteractor::onEntitySelectSelection)); + } + + @Override + public void onStringSelectInteraction(StringSelectInteractionEvent event) { + logger.debug("Received string selection menu event '{}' (#{}) on guild '{}'", + event.getComponentId(), event.getId(), event.getGuild()); + COMMAND_SERVICE + .execute(() -> forwardComponentCommand(event, UserInteractor::onStringSelectSelection)); } @Override diff --git a/application/src/test/java/org/togetherjava/tjbot/jda/JdaTester.java b/application/src/test/java/org/togetherjava/tjbot/jda/JdaTester.java index 145e02f37b..944a978f51 100644 --- a/application/src/test/java/org/togetherjava/tjbot/jda/JdaTester.java +++ b/application/src/test/java/org/togetherjava/tjbot/jda/JdaTester.java @@ -1,6 +1,5 @@ package org.togetherjava.tjbot.jda; -import net.dv8tion.jda.api.AccountType; import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.*; @@ -20,9 +19,7 @@ import net.dv8tion.jda.api.interactions.callbacks.IReplyCallback; import net.dv8tion.jda.api.interactions.components.ItemComponent; import net.dv8tion.jda.api.interactions.components.LayoutComponent; -import net.dv8tion.jda.api.requests.ErrorResponse; -import net.dv8tion.jda.api.requests.Response; -import net.dv8tion.jda.api.requests.RestAction; +import net.dv8tion.jda.api.requests.*; import net.dv8tion.jda.api.requests.restaction.CacheRestAction; import net.dv8tion.jda.api.requests.restaction.interactions.ReplyCallbackAction; import net.dv8tion.jda.api.utils.AttachmentProxy; @@ -107,6 +104,7 @@ public final class JdaTester { private final JDAImpl jda; private final MemberImpl member; private final GuildImpl guild; + private final RestRateLimiter rateLimiter; private final ReplyCallbackActionImpl replyAction; private final AuditableRestActionImpl auditableRestAction; private final MessageCreateActionImpl messageCreateAction; @@ -137,6 +135,9 @@ public JdaTester() { UserImpl user = spy(new UserImpl(USER_ID, jda)); user.setName("John Doe Tester"); guild = spy(new GuildImpl(jda, GUILD_ID)); + rateLimiter = + new SequentialRestRateLimiter(new RestRateLimiter.RateLimitConfig(RATE_LIMIT_POOL, + RestRateLimiter.GlobalRateLimit.create(), true)); Member selfMember = spy(new MemberImpl(guild, selfUser)); member = spy(new MemberImpl(guild, user)); textChannel = spy(new TextChannelImpl(TEXT_CHANNEL_ID, guild)); @@ -172,8 +173,8 @@ public JdaTester() { when(jda.getGatewayPool()).thenReturn(GATEWAY_POOL); when(jda.getRateLimitPool()).thenReturn(RATE_LIMIT_POOL); when(jda.getSessionController()).thenReturn(new ConcurrentSessionController()); - doReturn(new Requester(jda, new AuthorizationConfig(TEST_TOKEN))).when(jda).getRequester(); - when(jda.getAccountType()).thenReturn(AccountType.BOT); + doReturn(new Requester(jda, new AuthorizationConfig(TEST_TOKEN), new RestConfig(), + rateLimiter)).when(jda).getRequester(); replyAction = mock(ReplyCallbackActionImpl.class); when(replyAction.setEphemeral(anyBoolean())).thenReturn(replyAction); @@ -191,6 +192,7 @@ public JdaTester() { doReturn(webhookMessageEditAction).when(webhookMessageEditAction) .setActionRow(any(ItemComponent.class)); + when(guild.getGuildChannelById(anyLong())).thenReturn(textChannel); doReturn(everyoneRole).when(guild).getPublicRole(); doReturn(selfMember).when(guild).getMember(selfUser); doReturn(member).when(guild).getMember(not(eq(selfUser))); diff --git a/application/src/test/java/org/togetherjava/tjbot/jda/SlashCommandInteractionEventBuilder.java b/application/src/test/java/org/togetherjava/tjbot/jda/SlashCommandInteractionEventBuilder.java index f926ecf69e..62ed9a81cd 100644 --- a/application/src/test/java/org/togetherjava/tjbot/jda/SlashCommandInteractionEventBuilder.java +++ b/application/src/test/java/org/togetherjava/tjbot/jda/SlashCommandInteractionEventBuilder.java @@ -13,6 +13,7 @@ import net.dv8tion.jda.internal.interactions.command.SlashCommandInteractionImpl; import org.togetherjava.tjbot.features.SlashCommand; +import org.togetherjava.tjbot.jda.payloads.PayloadChannel; import org.togetherjava.tjbot.jda.payloads.PayloadMember; import org.togetherjava.tjbot.jda.payloads.PayloadUser; import org.togetherjava.tjbot.jda.payloads.slashcommand.*; @@ -270,6 +271,7 @@ private PayloadSlashCommand createEvent() { "Test-User", "3452"); PayloadMember member = new PayloadMember(null, null, "2021-09-07T18:25:16.615000+00:00", "1099511627775", List.of(), false, false, false, null, false, user); + PayloadChannel channel = new PayloadChannel(channelId, 1); List options; if (subcommand == null) { @@ -281,8 +283,8 @@ private PayloadSlashCommand createEvent() { PayloadSlashCommandData data = new PayloadSlashCommandData(command.getName(), "1", 1, options, extractResolvedOrNull(nameToOption)); - return new PayloadSlashCommand(guildId, "897425767397466123", 2, 1, channelId, - applicationId, token, member, data); + return new PayloadSlashCommand(guildId, "897425767397466123", 2, 1, applicationId, token, + member, channel, data); } @Nullable diff --git a/application/src/test/java/org/togetherjava/tjbot/jda/payloads/PayloadChannel.java b/application/src/test/java/org/togetherjava/tjbot/jda/payloads/PayloadChannel.java new file mode 100644 index 0000000000..eacc425df8 --- /dev/null +++ b/application/src/test/java/org/togetherjava/tjbot/jda/payloads/PayloadChannel.java @@ -0,0 +1,28 @@ +package org.togetherjava.tjbot.jda.payloads; + +public final class PayloadChannel { + + private String id; + private int type; + + public PayloadChannel(String id, int type) { + this.id = id; + this.type = type; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public int getType() { + return type; + } + + public void setType(int type) { + this.type = type; + } +} diff --git a/application/src/test/java/org/togetherjava/tjbot/jda/payloads/slashcommand/PayloadSlashCommand.java b/application/src/test/java/org/togetherjava/tjbot/jda/payloads/slashcommand/PayloadSlashCommand.java index 6d64e967ec..8108d2026d 100644 --- a/application/src/test/java/org/togetherjava/tjbot/jda/payloads/slashcommand/PayloadSlashCommand.java +++ b/application/src/test/java/org/togetherjava/tjbot/jda/payloads/slashcommand/PayloadSlashCommand.java @@ -2,6 +2,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; +import org.togetherjava.tjbot.jda.payloads.PayloadChannel; import org.togetherjava.tjbot.jda.payloads.PayloadMember; public final class PayloadSlashCommand { @@ -10,25 +11,24 @@ public final class PayloadSlashCommand { private String id; private int type; private int version; - @JsonProperty("channel_id") - private String channelId; @JsonProperty("application_id") private String applicationId; private String token; private PayloadMember member; + private PayloadChannel channel; private PayloadSlashCommandData data; - public PayloadSlashCommand(String guildId, String id, int type, int version, String channelId, - String applicationId, String token, PayloadMember member, + public PayloadSlashCommand(String guildId, String id, int type, int version, + String applicationId, String token, PayloadMember member, PayloadChannel channel, PayloadSlashCommandData data) { this.guildId = guildId; this.id = id; this.type = type; this.version = version; - this.channelId = channelId; this.applicationId = applicationId; this.token = token; this.member = member; + this.channel = channel; this.data = data; } @@ -64,14 +64,6 @@ public void setVersion(int version) { this.version = version; } - public String getChannelId() { - return channelId; - } - - public void setChannelId(String channelId) { - this.channelId = channelId; - } - public String getApplicationId() { return applicationId; } @@ -96,6 +88,14 @@ public void setMember(PayloadMember member) { this.member = member; } + public PayloadChannel getChannel() { + return channel; + } + + public void setChannel(PayloadChannel channel) { + this.channel = channel; + } + public PayloadSlashCommandData getData() { return data; } @@ -103,4 +103,5 @@ public PayloadSlashCommandData getData() { public void setData(PayloadSlashCommandData data) { this.data = data; } + }