Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade jda #1031

Merged
merged 2 commits into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion application/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -19,7 +20,8 @@
* <p>
* 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.
* <p>
* Some example commands are available in {@link org.togetherjava.tjbot.features.basic}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,9 +21,10 @@
* their respective command method. A new command can then be registered by adding it to
* {@link Features}.
* <p>
* 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.
* <p>
* 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
Expand Down Expand Up @@ -101,7 +103,13 @@ public void onButtonClick(ButtonInteractionEvent event, List<String> args) {

@SuppressWarnings("NoopMethodInAbstractClass")
@Override
public void onSelectMenuSelection(SelectMenuInteractionEvent event, List<String> args) {
public void onEntitySelectSelection(EntitySelectInteractionEvent event, List<String> args) {
// Adapter does not react by default, subclasses may change this behavior
}

@SuppressWarnings("NoopMethodInAbstractClass")
@Override
public void onStringSelectSelection(StringSelectInteractionEvent event, List<String> args) {
// Adapter does not react by default, subclasses may change this behavior
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
* <p>
* Some example commands are available in {@link org.togetherjava.tjbot.features.basic}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
* <p>
* Some example commands are available in {@link org.togetherjava.tjbot.features.basic}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,9 +23,10 @@
* of {@link #onSlashCommand(SlashCommandInteractionEvent)}. A new command can then be registered by
* adding it to {@link Features}.
* <p>
* 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.
* <p>
* 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
* <p>
* Some example commands are available in {@link org.togetherjava.tjbot.features.basic}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
* <p>
Expand Down Expand Up @@ -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<String> args);
@SuppressWarnings("NoopMethodInInterface")
default void onButtonClick(ButtonInteractionEvent event, List<String> 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.
* <p>
* 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
Expand All @@ -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<String> args);
@SuppressWarnings("NoopMethodInInterface")
default void onEntitySelectSelection(EntitySelectInteractionEvent event, List<String> 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.
* <p>
* 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.
* <p>
* 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<String> 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
Expand All @@ -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<String> args);
@SuppressWarnings("NoopMethodInInterface")
default void onModalSubmitted(ModalInteractionEvent event, List<String> 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
Expand All @@ -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)}).
* <p>
* Alternatively, if {@link BotCommandAdapter} has been extended, it also offers a handy
* {@link BotCommandAdapter#generateComponentId(String...)} method to ease the flow.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -175,11 +175,11 @@ private static boolean handleInteractableRolesSelected(IReplyCallback event,

private void sendRoleSelectionMenu(final CommandInteraction event,
final Collection<? extends Role> 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)
Expand All @@ -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<String> args) {
public void onStringSelectSelection(StringSelectInteractionEvent event, List<String> args) {
Guild guild = event.getGuild();
List<Role> selectedRoles = event.getSelectedOptions()
.stream()
Expand All @@ -220,7 +222,7 @@ public void onSelectMenuSelection(SelectMenuInteractionEvent event, List<String>
handleRoleSelection(event, guild, selectedRoles);
}

private static void handleRoleSelection(SelectMenuInteractionEvent event, Guild guild,
private static void handleRoleSelection(StringSelectInteractionEvent event, Guild guild,
Collection<Role> selectedRoles) {
Collection<Role> rolesToAdd = new ArrayList<>(selectedRoles.size());
Collection<Role> rolesToRemove = new ArrayList<>(selectedRoles.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -116,7 +116,7 @@ public void onButtonClick(ButtonInteractionEvent event, List<String> args) {
}

@Override
public void onSelectMenuSelection(SelectMenuInteractionEvent event, List<String> args) {
public void onStringSelectSelection(StringSelectInteractionEvent event, List<String> args) {
listRemoveHandler.onSelectMenuSelection(event, args);
}

Expand Down
Loading
Loading