Skip to content

Commit f323f98

Browse files
committed
Update JDA to alpha 5
1 parent 935316b commit f323f98

34 files changed

+257
-249
lines changed

application/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jib {
3232
}
3333
container {
3434
mainClass = 'org.togetherjava.tjbot.BootstrapLauncher'
35-
setCreationTime(java.time.Instant.now().toString())
35+
setCreationTime(Instant.now().toString())
3636
}
3737
}
3838

@@ -45,7 +45,7 @@ shadowJar {
4545
dependencies {
4646
implementation project(':database')
4747

48-
implementation 'net.dv8tion:JDA:5.0.0-alpha.4'
48+
implementation 'net.dv8tion:JDA:5.0.0-alpha.5'
4949

5050
implementation 'org.apache.logging.log4j:log4j-core:2.16.0'
5151
runtimeOnly 'org.apache.logging.log4j:log4j-slf4j18-impl:2.16.0'

application/src/main/java/org/togetherjava/tjbot/Application.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* Main class of the application. Use {@link #main(String[])} to start an instance of it.
2121
* <p>
2222
* New commands can be created by implementing
23-
* {@link net.dv8tion.jda.api.events.interaction.SlashCommandEvent} or extending
23+
* {@link net.dv8tion.jda.api.events.interaction.SlashCommandInteractionEvent} or extending
2424
* {@link org.togetherjava.tjbot.commands.SlashCommandAdapter}. They can then be registered in
2525
* {@link Features}.
2626
*/
@@ -105,4 +105,4 @@ private static void onShutdown() {
105105
logger.info("Bot has been stopped");
106106
}
107107

108-
}
108+
}

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

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package org.togetherjava.tjbot.commands;
22

33
import net.dv8tion.jda.api.entities.Emoji;
4-
import net.dv8tion.jda.api.events.interaction.ButtonClickEvent;
5-
import net.dv8tion.jda.api.events.interaction.SelectionMenuEvent;
6-
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
4+
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
5+
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
6+
import net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent;
77
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
8-
import net.dv8tion.jda.api.interactions.components.ButtonStyle;
8+
import net.dv8tion.jda.api.interactions.commands.build.Commands;
9+
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
910
import net.dv8tion.jda.api.interactions.components.ComponentInteraction;
11+
import net.dv8tion.jda.api.interactions.components.buttons.ButtonStyle;
1012
import org.jetbrains.annotations.NotNull;
1113
import org.togetherjava.tjbot.commands.componentids.ComponentId;
1214
import org.togetherjava.tjbot.commands.componentids.ComponentIdGenerator;
@@ -28,9 +30,9 @@
2830
* is then to be returned by {@link #getData()} where the system will then pick it up from.
2931
* <p>
3032
* After registration, the system will notify a command whenever one of its corresponding slash
31-
* commands ({@link #onSlashCommand(SlashCommandEvent)}), buttons
32-
* ({@link #onButtonClick(ButtonClickEvent, List)}) or menus
33-
* ({@link #onSelectionMenu(SelectionMenuEvent, List)}) have been triggered.
33+
* commands ({@link #onSlashCommand(SlashCommandInteractionEvent)}), buttons
34+
* ({@link #onButtonClick(ButtonInteractionEvent, List)}) or menus
35+
* ({@link #onSelectionMenu(SelectMenuInteractionEvent, List)}) have been triggered.
3436
* <p>
3537
* <p>
3638
* Some example commands are available in {@link org.togetherjava.tjbot.commands.basic}.
@@ -40,7 +42,7 @@ public interface SlashCommand extends Feature {
4042
/**
4143
* Gets the name of the command.
4244
* <p>
43-
* Requirements for this are documented in {@link CommandData#CommandData(String, String)}.
45+
* Requirements for this are documented in {@link Commands#slash(String, String)}.
4446
* <p>
4547
* <p>
4648
* After registration of the command, the name must not change anymore.
@@ -53,7 +55,7 @@ public interface SlashCommand extends Feature {
5355
/**
5456
* Gets the description of the command.
5557
* <p>
56-
* Requirements for this are documented in {@link CommandData#CommandData(String, String)}.
58+
* Requirements for this are documented in {@link Commands#slash(String, String)}.
5759
* <p>
5860
* <p>
5961
* After registration of the command, the description must not change anymore.
@@ -79,7 +81,7 @@ public interface SlashCommand extends Feature {
7981
* The data can be used to configure the settings for this command, i.e. adding options,
8082
* subcommands, menus and more.
8183
* <p>
82-
* See {@link CommandData} for details on how to create and configure instances of it.
84+
* See {@link SlashCommandData} for details on how to create and configure instances of it.
8385
* <p>
8486
* <p>
8587
* This method may be called multiple times, implementations must not create new data each time
@@ -89,7 +91,7 @@ public interface SlashCommand extends Feature {
8991
* @return the command data of this command
9092
*/
9193
@NotNull
92-
CommandData getData();
94+
SlashCommandData getData();
9395

9496
/**
9597
* Triggered by the core system when a slash command corresponding to this implementation (based
@@ -104,7 +106,7 @@ public interface SlashCommand extends Feature {
104106
* <p>
105107
* Buttons or menus have to be created with a component ID (see
106108
* {@link ComponentInteraction#getComponentId()},
107-
* {@link net.dv8tion.jda.api.interactions.components.Button#of(ButtonStyle, String, Emoji)}) in
109+
* {@link net.dv8tion.jda.api.interactions.components.buttons.Button#of(ButtonStyle, String, Emoji)}) in
108110
* a very specific format, otherwise the core system will fail to identify the command that
109111
* corresponded to the button or menu click event and is unable to route it back.
110112
* <p>
@@ -115,8 +117,8 @@ public interface SlashCommand extends Feature {
115117
* given to {@link #acceptComponentIdGenerator(ComponentIdGenerator)} during system setup. The
116118
* required {@link ComponentId} instance accepts optional extra arguments, which, if provided,
117119
* can be picked up during the corresponding event (see
118-
* {@link #onButtonClick(ButtonClickEvent, List)},
119-
* {@link #onSelectionMenu(SelectionMenuEvent, List)}).
120+
* {@link #onButtonClick(ButtonInteractionEvent, List)},
121+
* {@link #onSelectionMenu(SelectMenuInteractionEvent, List)}).
120122
* <p>
121123
* Alternatively, if {@link SlashCommandAdapter} has been extended, it also offers a handy
122124
* {@link SlashCommandAdapter#generateComponentId(String...)} method to ease the flow.
@@ -129,7 +131,7 @@ public interface SlashCommand extends Feature {
129131
*
130132
* @param event the event that triggered this
131133
*/
132-
void onSlashCommand(@NotNull SlashCommandEvent event);
134+
void onSlashCommand(@NotNull SlashCommandInteractionEvent event);
133135

134136
/**
135137
* Triggered by the core system when a button corresponding to this implementation (based on
@@ -147,9 +149,9 @@ public interface SlashCommand extends Feature {
147149
*
148150
* @param event the event that triggered this
149151
* @param args the arguments transported with the button, see
150-
* {@link #onSlashCommand(SlashCommandEvent)} for details on how these are created
152+
* {@link #onSlashCommand(SlashCommandInteractionEvent)} for details on how these are created
151153
*/
152-
void onButtonClick(@NotNull ButtonClickEvent event, @NotNull List<String> args);
154+
void onButtonClick(@NotNull ButtonInteractionEvent event, @NotNull List<String> args);
153155

154156
/**
155157
* Triggered by the core system when a selection menu corresponding to this implementation
@@ -167,17 +169,17 @@ public interface SlashCommand extends Feature {
167169
*
168170
* @param event the event that triggered this
169171
* @param args the arguments transported with the selection menu, see
170-
* {@link #onSlashCommand(SlashCommandEvent)} for details on how these are created
172+
* {@link #onSlashCommand(SlashCommandInteractionEvent)} for details on how these are created
171173
*/
172-
void onSelectionMenu(@NotNull SelectionMenuEvent event, @NotNull List<String> args);
174+
void onSelectionMenu(@NotNull SelectMenuInteractionEvent event, @NotNull List<String> args);
173175

174176
/**
175177
* Triggered by the core system during its setup phase. It will provide the command a component
176178
* id generator through this method, which can be used to generate component ids, as used for
177-
* button or selection menus. See {@link #onSlashCommand(SlashCommandEvent)} for details on how
179+
* button or selection menus. See {@link #onSlashCommand(SlashCommandInteractionEvent)} for details on how
178180
* to use this.
179181
*
180182
* @param generator the provided component id generator
181183
*/
182184
void acceptComponentIdGenerator(@NotNull ComponentIdGenerator generator);
183-
}
185+
}

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

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package org.togetherjava.tjbot.commands;
22

3-
import net.dv8tion.jda.api.events.interaction.ButtonClickEvent;
4-
import net.dv8tion.jda.api.events.interaction.SelectionMenuEvent;
5-
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
3+
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
4+
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
5+
import net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent;
66
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
7+
import net.dv8tion.jda.api.interactions.commands.build.Commands;
8+
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
79
import org.jetbrains.annotations.NotNull;
810
import org.togetherjava.tjbot.commands.componentids.ComponentId;
911
import org.togetherjava.tjbot.commands.componentids.ComponentIdGenerator;
@@ -15,11 +17,11 @@
1517

1618
/**
1719
* Adapter implementation of a {@link SlashCommand}. The minimal setup only requires implementation
18-
* of {@link #onSlashCommand(SlashCommandEvent)}. A new command can then be registered by adding it
20+
* of {@link #onSlashCommand(SlashCommandInteractionEvent)}. A new command can then be registered by adding it
1921
* to {@link Features}.
2022
* <p>
21-
* Further, {@link #onButtonClick(ButtonClickEvent, List)} and
22-
* {@link #onSelectionMenu(SelectionMenuEvent, List)} can be overridden if desired. The default
23+
* Further, {@link #onButtonClick(ButtonInteractionEvent, List)} and
24+
* {@link #onSelectionMenu(SelectMenuInteractionEvent, List)} can be overridden if desired. The default
2325
* implementation is empty, the adapter will not react to such events.
2426
* <p>
2527
* <p>
@@ -31,7 +33,7 @@
3133
* <p>
3234
* If implementations want to add buttons or selection menus, it is highly advised to use component
3335
* IDs generated by {@link #generateComponentId(String...)}, which will automatically create IDs
34-
* that are valid per {@link SlashCommand#onSlashCommand(SlashCommandEvent)}.
36+
* that are valid per {@link SlashCommand#onSlashCommand(SlashCommandInteractionEvent)}.
3537
* <p>
3638
* <p>
3739
* Some example commands are available in {@link org.togetherjava.tjbot.commands.basic}. A minimal
@@ -46,7 +48,7 @@
4648
* }
4749
*
4850
* &#64;Override
49-
* public void onSlashCommand(@NotNull SlashCommandEvent event) {
51+
* public void onSlashCommand(@NotNull SlashCommandInteractionEvent event) {
5052
* event.reply("Pong!").queue();
5153
* }
5254
* }
@@ -59,16 +61,16 @@ public abstract class SlashCommandAdapter implements SlashCommand {
5961
private final String name;
6062
private final String description;
6163
private final SlashCommandVisibility visibility;
62-
private final CommandData data;
64+
private final SlashCommandData data;
6365
private ComponentIdGenerator componentIdGenerator;
6466

6567
/**
6668
* Creates a new adapter with the given data.
6769
*
6870
* @param name the name of this command, requirements for this are documented in
69-
* {@link CommandData#CommandData(String, String)}
71+
* {@link Commands#slash(String, String)}
7072
* @param description the description of this command, requirements for this are documented in
71-
* {@link CommandData#CommandData(String, String)}
73+
* {@link Commands#slash(String, String)}
7274
* @param visibility the visibility of the command
7375
*/
7476
protected SlashCommandAdapter(@NotNull String name, @NotNull String description,
@@ -77,7 +79,8 @@ protected SlashCommandAdapter(@NotNull String name, @NotNull String description,
7779
this.description = description;
7880
this.visibility = visibility;
7981

80-
data = new CommandData(name, description);
82+
83+
data = Commands.slash(name, description);
8184
}
8285

8386
@Override
@@ -96,7 +99,7 @@ protected SlashCommandAdapter(@NotNull String name, @NotNull String description,
9699
}
97100

98101
@Override
99-
public final @NotNull CommandData getData() {
102+
public final @NotNull SlashCommandData getData() {
100103
return data;
101104
}
102105

@@ -107,19 +110,19 @@ public final void acceptComponentIdGenerator(@NotNull ComponentIdGenerator gener
107110

108111
@SuppressWarnings("NoopMethodInAbstractClass")
109112
@Override
110-
public void onButtonClick(@NotNull ButtonClickEvent event, @NotNull List<String> args) {
113+
public void onButtonClick(@NotNull ButtonInteractionEvent event, @NotNull List<String> args) {
111114
// Adapter does not react by default, subclasses may change this behavior
112115
}
113116

114117
@SuppressWarnings("NoopMethodInAbstractClass")
115118
@Override
116-
public void onSelectionMenu(@NotNull SelectionMenuEvent event, @NotNull List<String> args) {
119+
public void onSelectionMenu(@NotNull SelectMenuInteractionEvent event, @NotNull List<String> args) {
117120
// Adapter does not react by default, subclasses may change this behavior
118121
}
119122

120123
/**
121124
* Helper method to generate component IDs that are considered valid per
122-
* {@link SlashCommand#onSlashCommand(SlashCommandEvent)}.
125+
* {@link SlashCommand#onSlashCommand(SlashCommandInteractionEvent)}.
123126
* <p>
124127
* They can be used to create buttons or selection menus and transport additional data
125128
* throughout the event (e.g. the user id who created the button dialog).
@@ -138,7 +141,7 @@ public void onSelectionMenu(@NotNull SelectionMenuEvent event, @NotNull List<Str
138141

139142
/**
140143
* Helper method to generate component IDs that are considered valid per
141-
* {@link SlashCommand#onSlashCommand(SlashCommandEvent)}.
144+
* {@link SlashCommand#onSlashCommand(SlashCommandInteractionEvent)}.
142145
* <p>
143146
* They can be used to create buttons or selection menus and transport additional data
144147
* throughout the event (e.g. the user id who created the button dialog).
@@ -154,4 +157,4 @@ public void onSelectionMenu(@NotNull SelectionMenuEvent event, @NotNull List<Str
154157
return Objects.requireNonNull(componentIdGenerator)
155158
.generate(new ComponentId(getName(), Arrays.asList(args)), lifespan);
156159
}
157-
}
160+
}

application/src/main/java/org/togetherjava/tjbot/commands/basic/PingCommand.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.togetherjava.tjbot.commands.basic;
22

3-
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
3+
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
44
import org.jetbrains.annotations.NotNull;
55
import org.togetherjava.tjbot.commands.SlashCommandAdapter;
66
import org.togetherjava.tjbot.commands.SlashCommandVisibility;
@@ -24,7 +24,7 @@ public PingCommand() {
2424
* @param event the corresponding event
2525
*/
2626
@Override
27-
public void onSlashCommand(@NotNull SlashCommandEvent event) {
27+
public void onSlashCommand(@NotNull SlashCommandInteractionEvent event) {
2828
event.reply("Pong!").queue();
2929
}
30-
}
30+
}

application/src/main/java/org/togetherjava/tjbot/commands/basic/VcActivityCommand.java

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

33
import net.dv8tion.jda.api.Permission;
44
import net.dv8tion.jda.api.entities.*;
5-
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
5+
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
66
import net.dv8tion.jda.api.interactions.commands.Command;
77
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
88
import net.dv8tion.jda.api.interactions.commands.OptionType;
99
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
1010
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData;
11-
import net.dv8tion.jda.api.requests.restaction.interactions.ReplyAction;
11+
import net.dv8tion.jda.api.requests.restaction.interactions.ReplyCallbackAction;
1212
import org.jetbrains.annotations.Contract;
1313
import org.jetbrains.annotations.NotNull;
1414
import org.jetbrains.annotations.Nullable;
@@ -121,7 +121,7 @@ public VcActivityCommand() {
121121

122122

123123
@Override
124-
public void onSlashCommand(@NotNull SlashCommandEvent event) {
124+
public void onSlashCommand(@NotNull SlashCommandInteractionEvent event) {
125125
Member member = Objects.requireNonNull(event.getMember(), "member is null");
126126
GuildVoiceState voiceState = Objects.requireNonNull(member.getVoiceState(),
127127
"Voicestates aren't being cached, check the JDABuilder");
@@ -188,7 +188,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) {
188188
return Optional.empty();
189189
}
190190

191-
private static void handleSubcommand(@NotNull SlashCommandEvent event,
191+
private static void handleSubcommand(@NotNull SlashCommandInteractionEvent event,
192192
@NotNull VoiceChannel voiceChannel, @NotNull String applicationId,
193193
@Nullable Integer maxUses, @Nullable Integer maxAgeDays,
194194
@NotNull String applicationName) {
@@ -204,16 +204,16 @@ private static void handleSubcommand(@NotNull SlashCommandEvent event,
204204

205205
}
206206

207-
private static @NotNull ReplyAction replyInvite(@NotNull SlashCommandEvent event,
208-
@NotNull Invite invite, @NotNull String applicationName) {
207+
private static @NotNull ReplyCallbackAction replyInvite(@NotNull SlashCommandInteractionEvent event,
208+
@NotNull Invite invite, @NotNull String applicationName) {
209209
return event.reply("""
210210
%s wants to start %s.
211211
Feel free to join by clicking %s , enjoy!
212212
If it says the activity ended, click on the URL instead.
213213
""".formatted(event.getUser().getAsTag(), applicationName, invite.getUrl()));
214214
}
215215

216-
private static void handleErrors(@NotNull SlashCommandEvent event,
216+
private static void handleErrors(@NotNull SlashCommandInteractionEvent event,
217217
@Nullable Throwable throwable) {
218218
event.reply("Something went wrong :/").queue();
219219
logger.warn("Something went wrong in the VcActivityCommand", throwable);
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
package org.togetherjava.tjbot.commands.componentids;
22

3-
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
3+
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
44
import org.jetbrains.annotations.NotNull;
55

66
import java.util.List;
77

88
/**
99
* Payload carried by component IDs. See
10-
* {@link org.togetherjava.tjbot.commands.SlashCommand#onSlashCommand(SlashCommandEvent)} for its
10+
* {@link org.togetherjava.tjbot.commands.SlashCommand#onSlashCommand(SlashCommandInteractionEvent)} for its
1111
* usages.
1212
*
1313
* @param commandName the name of the command that handles the event associated to this component
1414
* ID, when triggered
1515
* @param elements the additional elements to carry along this component ID, empty if not desired
1616
*/
1717
public record ComponentId(@NotNull String commandName, @NotNull List<String> elements) {
18-
}
18+
}

0 commit comments

Comments
 (0)