Skip to content

Commit 4ff5966

Browse files
Taz03SquidXTV
andauthored
upgrade jda (#1031)
Co-authored-by: SquidXTV <squidxtv@gmail.com> --------- Co-authored-by: SquidXTV <squidxtv@gmail.com>
1 parent 21df080 commit 4ff5966

25 files changed

+164
-120
lines changed

application/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ dependencies {
4646
implementation project(':utils')
4747
implementation project(':formatter')
4848

49-
implementation 'net.dv8tion:JDA:5.0.0-alpha.20'
49+
implementation 'net.dv8tion:JDA:5.0.0-beta.21'
5050

5151
implementation 'org.apache.logging.log4j:log4j-core:2.23.0'
5252
runtimeOnly 'org.apache.logging.log4j:log4j-slf4j18-impl:2.18.0'

application/src/main/java/org/togetherjava/tjbot/features/BotCommand.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package org.togetherjava.tjbot.features;
22

33
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
4-
import net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent;
4+
import net.dv8tion.jda.api.events.interaction.component.EntitySelectInteractionEvent;
5+
import net.dv8tion.jda.api.events.interaction.component.StringSelectInteractionEvent;
56
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
67

78
import java.util.List;
@@ -19,7 +20,8 @@
1920
* <p>
2021
* After registration, the system will notify a command whenever one of its corresponding command
2122
* method, buttons ({@link #onButtonClick(ButtonInteractionEvent, List)}) or menus
22-
* ({@link #onSelectMenuSelection(SelectMenuInteractionEvent, List)}) have been triggered.
23+
* ({@link #onEntitySelectSelection(EntitySelectInteractionEvent, List)},
24+
* {@link #onStringSelectSelection(StringSelectInteractionEvent, List)}) have been triggered.
2325
* <p>
2426
* Some example commands are available in {@link org.togetherjava.tjbot.features.basic}.
2527
*/

application/src/main/java/org/togetherjava/tjbot/features/BotCommandAdapter.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import net.dv8tion.jda.api.events.interaction.ModalInteractionEvent;
44
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
55
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
6-
import net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent;
6+
import net.dv8tion.jda.api.events.interaction.component.EntitySelectInteractionEvent;
7+
import net.dv8tion.jda.api.events.interaction.component.StringSelectInteractionEvent;
78
import net.dv8tion.jda.api.interactions.commands.Command;
89
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
910
import org.jetbrains.annotations.Contract;
@@ -20,9 +21,10 @@
2021
* their respective command method. A new command can then be registered by adding it to
2122
* {@link Features}.
2223
* <p>
23-
* Further, {@link #onButtonClick(ButtonInteractionEvent, List)} and
24-
* {@link #onSelectMenuSelection(SelectMenuInteractionEvent, List)} can be overridden if desired.
25-
* The default implementation is empty, the adapter will not react to such events.
24+
* Further, {@link #onButtonClick(ButtonInteractionEvent, List)},
25+
* {@link #onEntitySelectSelection(EntitySelectInteractionEvent, List)} and
26+
* {@link #onStringSelectSelection(StringSelectInteractionEvent, List)} can be overridden if
27+
* desired. The default implementation is empty, the adapter will not react to such events.
2628
* <p>
2729
* The adapter manages some getters for you, you've to create the {@link CommandData} yourself. See
2830
* {@link #BotCommandAdapter(CommandData, CommandVisibility)}} for more info on that. Minimal
@@ -101,7 +103,13 @@ public void onButtonClick(ButtonInteractionEvent event, List<String> args) {
101103

102104
@SuppressWarnings("NoopMethodInAbstractClass")
103105
@Override
104-
public void onSelectMenuSelection(SelectMenuInteractionEvent event, List<String> args) {
106+
public void onEntitySelectSelection(EntitySelectInteractionEvent event, List<String> args) {
107+
// Adapter does not react by default, subclasses may change this behavior
108+
}
109+
110+
@SuppressWarnings("NoopMethodInAbstractClass")
111+
@Override
112+
public void onStringSelectSelection(StringSelectInteractionEvent event, List<String> args) {
105113
// Adapter does not react by default, subclasses may change this behavior
106114
}
107115

application/src/main/java/org/togetherjava/tjbot/features/MessageContextCommand.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
import net.dv8tion.jda.api.events.interaction.command.MessageContextInteractionEvent;
44
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
5-
import net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent;
5+
import net.dv8tion.jda.api.events.interaction.component.EntitySelectInteractionEvent;
6+
import net.dv8tion.jda.api.events.interaction.component.StringSelectInteractionEvent;
67
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
78
import net.dv8tion.jda.api.interactions.components.ComponentInteraction;
89
import net.dv8tion.jda.api.interactions.components.buttons.ButtonStyle;
@@ -29,7 +30,8 @@
2930
* After registration, the system will notify a command whenever one of its corresponding message
3031
* context-commands ({@link #onMessageContext(MessageContextInteractionEvent)}), buttons
3132
* ({@link #onButtonClick(ButtonInteractionEvent, List)}) or menus
32-
* ({@link #onSelectMenuSelection(SelectMenuInteractionEvent, List)}) have been triggered.
33+
* ({@link #onEntitySelectSelection(EntitySelectInteractionEvent, List)},
34+
* {@link #onStringSelectSelection(StringSelectInteractionEvent, List)}) have been triggered.
3335
* <p>
3436
* Some example commands are available in {@link org.togetherjava.tjbot.features.basic}.
3537
*/

application/src/main/java/org/togetherjava/tjbot/features/SlashCommand.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent;
44
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
55
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
6-
import net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent;
6+
import net.dv8tion.jda.api.events.interaction.component.EntitySelectInteractionEvent;
7+
import net.dv8tion.jda.api.events.interaction.component.StringSelectInteractionEvent;
78
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
89
import net.dv8tion.jda.api.interactions.commands.build.Commands;
910
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
@@ -35,7 +36,8 @@
3536
* After registration, the system will notify a command whenever one of its corresponding slash
3637
* commands ({@link #onSlashCommand(SlashCommandInteractionEvent)}), buttons
3738
* ({@link #onButtonClick(ButtonInteractionEvent, List)}) or menus
38-
* ({@link #onSelectMenuSelection(SelectMenuInteractionEvent, List)}) have been triggered.
39+
* ({@link #onEntitySelectSelection(EntitySelectInteractionEvent, List)},
40+
* {@link #onStringSelectSelection(StringSelectInteractionEvent, List)}) have been triggered.
3941
* <p>
4042
* Some example commands are available in {@link org.togetherjava.tjbot.features.basic}.
4143
*/

application/src/main/java/org/togetherjava/tjbot/features/SlashCommandAdapter.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent;
44
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
55
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
6-
import net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent;
6+
import net.dv8tion.jda.api.events.interaction.component.EntitySelectInteractionEvent;
7+
import net.dv8tion.jda.api.events.interaction.component.StringSelectInteractionEvent;
78
import net.dv8tion.jda.api.interactions.commands.CommandInteractionPayload;
89
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
910
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
@@ -22,9 +23,10 @@
2223
* of {@link #onSlashCommand(SlashCommandInteractionEvent)}. A new command can then be registered by
2324
* adding it to {@link Features}.
2425
* <p>
25-
* Further, {@link #onButtonClick(ButtonInteractionEvent, List)} and
26-
* {@link #onSelectMenuSelection(SelectMenuInteractionEvent, List)} can be overridden if desired.
27-
* The default implementation is empty, the adapter will not react to such events.
26+
* Further, {@link #onButtonClick(ButtonInteractionEvent, List)},
27+
* {@link #onEntitySelectSelection(EntitySelectInteractionEvent, List)} and
28+
* {@link #onStringSelectSelection(StringSelectInteractionEvent, List)} can be overridden if
29+
* desired. The default implementation is empty, the adapter will not react to such events.
2830
* <p>
2931
* The adapter manages all command related data itself, which can be provided during construction
3032
* (see {@link #SlashCommandAdapter(String, String, CommandVisibility)}). In order to add options,

application/src/main/java/org/togetherjava/tjbot/features/UserContextCommand.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
import net.dv8tion.jda.api.events.interaction.command.UserContextInteractionEvent;
44
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
5-
import net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent;
5+
import net.dv8tion.jda.api.events.interaction.component.EntitySelectInteractionEvent;
6+
import net.dv8tion.jda.api.events.interaction.component.StringSelectInteractionEvent;
67
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
78
import net.dv8tion.jda.api.interactions.components.ComponentInteraction;
89
import net.dv8tion.jda.api.interactions.components.buttons.ButtonStyle;
@@ -30,7 +31,8 @@
3031
* After registration, the system will notify a command whenever one of its corresponding user
3132
* context-commands ({@link #onUserContext(UserContextInteractionEvent)}), buttons
3233
* ({@link #onButtonClick(ButtonInteractionEvent, List)}) or menus
33-
* ({@link #onSelectMenuSelection(SelectMenuInteractionEvent, List)}) have been triggered.
34+
* ({@link #onStringSelectSelection(StringSelectInteractionEvent, List)},
35+
* {@link #onEntitySelectSelection(EntitySelectInteractionEvent, List)}) have been triggered.
3436
* <p>
3537
* Some example commands are available in {@link org.togetherjava.tjbot.features.basic}.
3638
*/

application/src/main/java/org/togetherjava/tjbot/features/UserInteractor.java

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import net.dv8tion.jda.api.events.interaction.ModalInteractionEvent;
44
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
55
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
6-
import net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent;
6+
import net.dv8tion.jda.api.events.interaction.component.EntitySelectInteractionEvent;
7+
import net.dv8tion.jda.api.events.interaction.component.StringSelectInteractionEvent;
78

89
import org.togetherjava.tjbot.features.componentids.ComponentId;
910
import org.togetherjava.tjbot.features.componentids.ComponentIdGenerator;
@@ -20,7 +21,6 @@
2021
* if their type is different, all the types can be seen in {@link UserInteractionType}
2122
*/
2223
public interface UserInteractor extends Feature {
23-
2424
/**
2525
* Gets the name of the interactor.
2626
* <p>
@@ -58,11 +58,14 @@ public interface UserInteractor extends Feature {
5858
* {@link SlashCommand#onSlashCommand(SlashCommandInteractionEvent)} for details on how
5959
* these are created
6060
*/
61-
void onButtonClick(ButtonInteractionEvent event, List<String> args);
61+
@SuppressWarnings("NoopMethodInInterface")
62+
default void onButtonClick(ButtonInteractionEvent event, List<String> args) {
63+
// Interface does not react by default, implementations may change this behaviour
64+
}
6265

6366
/**
64-
* Triggered by the core system when a selection menu corresponding to this implementation
65-
* (based on {@link #getName()}) has been clicked.
67+
* Triggered by the core system when an entity selection menu corresponding to this
68+
* implementation (based on {@link #getName()}) has been clicked.
6669
* <p>
6770
* This method may be called multithreaded. In particular, there are no guarantees that it will
6871
* 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 {
7679
* {@link SlashCommand#onSlashCommand(SlashCommandInteractionEvent)} for details on how
7780
* these are created
7881
*/
79-
void onSelectMenuSelection(SelectMenuInteractionEvent event, List<String> args);
82+
@SuppressWarnings("NoopMethodInInterface")
83+
default void onEntitySelectSelection(EntitySelectInteractionEvent event, List<String> args) {
84+
// Interface does not react by default, implementations may change this behaviour
85+
}
8086

87+
/**
88+
* Triggered by the core system when a string selection menu corresponding to this
89+
* implementation (based on {@link #getName()}) has been clicked.
90+
* <p>
91+
* This method may be called multithreaded. In particular, there are no guarantees that it will
92+
* be executed on the same thread repeatedly or on the same thread that other event methods have
93+
* been called on.
94+
* <p>
95+
* Details are available in the given event and the event also enables implementations to
96+
* respond to it.
97+
*
98+
* @param event the event that triggered this
99+
* @param args the arguments transported with the selection menu, see
100+
* {@link SlashCommand#onSlashCommand(SlashCommandInteractionEvent)} for details on how
101+
* these are created
102+
*/
103+
@SuppressWarnings("NoopMethodInInterface")
104+
default void onStringSelectSelection(StringSelectInteractionEvent event, List<String> args) {
105+
// Interface does not react by default, implementations may change this behaviour
106+
}
81107

82108
/**
83109
* Triggered by the core system when a modal corresponding to this implementation (based on
@@ -95,7 +121,10 @@ public interface UserInteractor extends Feature {
95121
* {@link SlashCommand#onSlashCommand(SlashCommandInteractionEvent)} for details on how
96122
* these are created
97123
*/
98-
void onModalSubmitted(ModalInteractionEvent event, List<String> args);
124+
@SuppressWarnings("NoopMethodInInterface")
125+
default void onModalSubmitted(ModalInteractionEvent event, List<String> args) {
126+
// Interface does not react by default, implementations may change this behaviour
127+
}
99128

100129
/**
101130
* 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 {
110139
* given to this method during system setup. The required {@link ComponentId} instance accepts
111140
* optional extra arguments, which, if provided, can be picked up during the corresponding event
112141
* (see {@link #onButtonClick(ButtonInteractionEvent, List)},
113-
* {@link #onSelectMenuSelection(SelectMenuInteractionEvent, List)}).
142+
* {@link #onEntitySelectSelection(EntitySelectInteractionEvent, List)},
143+
* {@link #onStringSelectSelection(StringSelectInteractionEvent, List)}).
114144
* <p>
115145
* Alternatively, if {@link BotCommandAdapter} has been extended, it also offers a handy
116146
* {@link BotCommandAdapter#generateComponentId(String...)} method to ease the flow.

application/src/main/java/org/togetherjava/tjbot/features/basic/RoleSelectCommand.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
import net.dv8tion.jda.api.entities.*;
66
import net.dv8tion.jda.api.entities.emoji.Emoji;
77
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
8-
import net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent;
8+
import net.dv8tion.jda.api.events.interaction.component.StringSelectInteractionEvent;
99
import net.dv8tion.jda.api.interactions.callbacks.IReplyCallback;
1010
import net.dv8tion.jda.api.interactions.commands.CommandInteraction;
1111
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
1212
import net.dv8tion.jda.api.interactions.commands.OptionType;
1313
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
14-
import net.dv8tion.jda.api.interactions.components.selections.SelectMenu;
1514
import net.dv8tion.jda.api.interactions.components.selections.SelectOption;
15+
import net.dv8tion.jda.api.interactions.components.selections.StringSelectMenu;
1616
import org.jetbrains.annotations.Contract;
1717
import org.slf4j.Logger;
1818
import org.slf4j.LoggerFactory;
@@ -175,11 +175,11 @@ private static boolean handleInteractableRolesSelected(IReplyCallback event,
175175

176176
private void sendRoleSelectionMenu(final CommandInteraction event,
177177
final Collection<? extends Role> selectableRoles) {
178-
SelectMenu.Builder menu =
179-
SelectMenu.create(generateComponentId(Lifespan.PERMANENT, event.getUser().getId()))
180-
.setPlaceholder("Select your roles")
181-
.setMinValues(0)
182-
.setMaxValues(selectableRoles.size());
178+
StringSelectMenu.Builder menu = StringSelectMenu
179+
.create(generateComponentId(Lifespan.PERMANENT, event.getUser().getId()))
180+
.setPlaceholder("Select your roles")
181+
.setMinValues(0)
182+
.setMaxValues(selectableRoles.size());
183183

184184
selectableRoles.stream()
185185
.map(RoleSelectCommand::mapToSelectOption)
@@ -203,8 +203,10 @@ private static SelectOption mapToSelectOption(Role role) {
203203
return option;
204204
}
205205

206+
// this should be entity select menu but im just gonna use string rn
207+
// coz i'll have to do least changes that way
206208
@Override
207-
public void onSelectMenuSelection(SelectMenuInteractionEvent event, List<String> args) {
209+
public void onStringSelectSelection(StringSelectInteractionEvent event, List<String> args) {
208210
Guild guild = event.getGuild();
209211
List<Role> selectedRoles = event.getSelectedOptions()
210212
.stream()
@@ -220,7 +222,7 @@ public void onSelectMenuSelection(SelectMenuInteractionEvent event, List<String>
220222
handleRoleSelection(event, guild, selectedRoles);
221223
}
222224

223-
private static void handleRoleSelection(SelectMenuInteractionEvent event, Guild guild,
225+
private static void handleRoleSelection(StringSelectInteractionEvent event, Guild guild,
224226
Collection<Role> selectedRoles) {
225227
Collection<Role> rolesToAdd = new ArrayList<>(selectedRoles.size());
226228
Collection<Role> rolesToRemove = new ArrayList<>(selectedRoles.size());

application/src/main/java/org/togetherjava/tjbot/features/bookmarks/BookmarksCommand.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import net.dv8tion.jda.api.entities.channel.unions.MessageChannelUnion;
55
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
66
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
7-
import net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent;
7+
import net.dv8tion.jda.api.events.interaction.component.StringSelectInteractionEvent;
88
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
99
import net.dv8tion.jda.api.interactions.commands.OptionType;
1010
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
@@ -116,7 +116,7 @@ public void onButtonClick(ButtonInteractionEvent event, List<String> args) {
116116
}
117117

118118
@Override
119-
public void onSelectMenuSelection(SelectMenuInteractionEvent event, List<String> args) {
119+
public void onStringSelectSelection(StringSelectInteractionEvent event, List<String> args) {
120120
listRemoveHandler.onSelectMenuSelection(event, args);
121121
}
122122

0 commit comments

Comments
 (0)