Skip to content

Update JDA-4 to JDA-5 alpha 9 #420

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

Merged
merged 3 commits into from
Mar 29, 2022
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
6 changes: 1 addition & 5 deletions application/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ plugins {

repositories {
mavenCentral()
maven {
name 'm2-dv8tion'
url 'https://m2.dv8tion.net/releases'
}
}

var outputImage = 'togetherjava.duckdns.org:5001/togetherjava/tjbot:' + System.getenv('BRANCH_NAME') ?: 'latest'
Expand Down Expand Up @@ -45,7 +41,7 @@ shadowJar {
dependencies {
implementation project(':database')

implementation 'net.dv8tion:JDA:4.4.0_352'
implementation 'net.dv8tion:JDA:5.0.0-alpha.9'

implementation 'org.apache.logging.log4j:log4j-core:2.16.0'
runtimeOnly 'org.apache.logging.log4j:log4j-slf4j18-impl:2.16.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* Main class of the application. Use {@link #main(String[])} to start an instance of it.
* <p>
* New commands can be created by implementing
* {@link net.dv8tion.jda.api.events.interaction.SlashCommandEvent} or extending
* {@link net.dv8tion.jda.api.events.interaction.SlashCommandInteractionEvent} or extending
* {@link org.togetherjava.tjbot.commands.SlashCommandAdapter}. They can then be registered in
* {@link Features}.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.togetherjava.tjbot.commands;

import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
import net.dv8tion.jda.api.events.message.guild.GuildMessageUpdateEvent;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.events.message.MessageUpdateEvent;
import org.jetbrains.annotations.NotNull;

import java.util.regex.Pattern;
Expand Down Expand Up @@ -38,7 +38,7 @@ public interface MessageReceiver extends Feature {
* @param event the event that triggered this, containing information about the corresponding
* message that was sent and received
*/
void onMessageReceived(@NotNull GuildMessageReceivedEvent event);
void onMessageReceived(@NotNull MessageReceivedEvent event);

/**
* Triggered by the core system whenever an existing message was edited in a text channel of a
Expand All @@ -47,5 +47,5 @@ public interface MessageReceiver extends Feature {
* @param event the event that triggered this, containing information about the corresponding
* message that was edited
*/
void onMessageUpdated(@NotNull GuildMessageUpdateEvent event);
void onMessageUpdated(@NotNull MessageUpdateEvent event);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.togetherjava.tjbot.commands;

import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
import net.dv8tion.jda.api.events.message.guild.GuildMessageUpdateEvent;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.events.message.MessageUpdateEvent;
import org.jetbrains.annotations.NotNull;

import java.util.regex.Pattern;
Expand All @@ -10,8 +10,8 @@
* Adapter implementation of a {@link MessageReceiver}. A new receiver can then be registered by
* adding it to {@link Features}.
* <p>
* {@link #onMessageReceived(GuildMessageReceivedEvent)} and
* {@link #onMessageUpdated(GuildMessageUpdateEvent)} can be overridden if desired. The default
* {@link #onMessageReceived(MessageReceivedEvent)} and
* {@link #onMessageUpdated(MessageUpdateEvent)} can be overridden if desired. The default
* implementation is empty, the adapter will not react to such events.
*/
public abstract class MessageReceiverAdapter implements MessageReceiver {
Expand All @@ -35,13 +35,13 @@ protected MessageReceiverAdapter(@NotNull Pattern channelNamePattern) {

@SuppressWarnings("NoopMethodInAbstractClass")
@Override
public void onMessageReceived(@NotNull GuildMessageReceivedEvent event) {
public void onMessageReceived(@NotNull MessageReceivedEvent event) {
// Adapter does not react by default, subclasses may change this behavior
}

@SuppressWarnings("NoopMethodInAbstractClass")
@Override
public void onMessageUpdated(@NotNull GuildMessageUpdateEvent event) {
public void onMessageUpdated(@NotNull MessageUpdateEvent event) {
// Adapter does not react by default, subclasses may change this behavior
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package org.togetherjava.tjbot.commands;

import net.dv8tion.jda.api.entities.Emoji;
import net.dv8tion.jda.api.events.interaction.ButtonClickEvent;
import net.dv8tion.jda.api.events.interaction.SelectionMenuEvent;
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
import net.dv8tion.jda.api.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.interactions.commands.build.CommandData;
import net.dv8tion.jda.api.interactions.components.ButtonStyle;
import net.dv8tion.jda.api.interactions.commands.build.Commands;
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
import net.dv8tion.jda.api.interactions.components.ComponentInteraction;
import net.dv8tion.jda.api.interactions.components.buttons.Button;
import net.dv8tion.jda.api.interactions.components.buttons.ButtonStyle;
import org.jetbrains.annotations.NotNull;
import org.togetherjava.tjbot.commands.componentids.ComponentId;
import org.togetherjava.tjbot.commands.componentids.ComponentIdGenerator;
Expand All @@ -28,9 +31,9 @@
* is then to be returned by {@link #getData()} where the system will then pick it up from.
* <p>
* After registration, the system will notify a command whenever one of its corresponding slash
* commands ({@link #onSlashCommand(SlashCommandEvent)}), buttons
* ({@link #onButtonClick(ButtonClickEvent, List)}) or menus
* ({@link #onSelectionMenu(SelectionMenuEvent, List)}) have been triggered.
* commands ({@link #onSlashCommand(SlashCommandInteractionEvent)}), buttons
* ({@link #onButtonClick(ButtonInteractionEvent, List)}) or menus
* ({@link #onSelectionMenu(SelectMenuInteractionEvent, List)}) have been triggered.
* <p>
* <p>
* Some example commands are available in {@link org.togetherjava.tjbot.commands.basic}.
Expand All @@ -40,7 +43,7 @@ public interface SlashCommand extends Feature {
/**
* Gets the name of the command.
* <p>
* Requirements for this are documented in {@link CommandData#CommandData(String, String)}.
* Requirements for this are documented in {@link Commands#slash(String, String)}.
* <p>
* <p>
* After registration of the command, the name must not change anymore.
Expand All @@ -53,7 +56,7 @@ public interface SlashCommand extends Feature {
/**
* Gets the description of the command.
* <p>
* Requirements for this are documented in {@link CommandData#CommandData(String, String)}.
* Requirements for this are documented in {@link Commands#slash(String, String)}.
* <p>
* <p>
* After registration of the command, the description must not change anymore.
Expand Down Expand Up @@ -89,7 +92,7 @@ public interface SlashCommand extends Feature {
* @return the command data of this command
*/
@NotNull
CommandData getData();
SlashCommandData getData();

/**
* Triggered by the core system when a slash command corresponding to this implementation (based
Expand All @@ -104,9 +107,9 @@ public interface SlashCommand extends Feature {
* <p>
* Buttons or menus have to be created with a component ID (see
* {@link ComponentInteraction#getComponentId()},
* {@link net.dv8tion.jda.api.interactions.components.Button#of(ButtonStyle, String, Emoji)}) in
* a very specific format, otherwise the core system will fail to identify the command that
* corresponded to the button or menu click event and is unable to route it back.
* {@link Button#of(ButtonStyle, String, Emoji)}}) in a very specific format, otherwise the core
* system will fail to identify the command that corresponded to the button or menu click event
* and is unable to route it back.
* <p>
* The component ID has to be a UUID-string (see {@link java.util.UUID}), which is associated to
* a specific database entry, containing meta information about the command being executed. Such
Expand All @@ -115,8 +118,8 @@ public interface SlashCommand extends Feature {
* given to {@link #acceptComponentIdGenerator(ComponentIdGenerator)} 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(ButtonClickEvent, List)},
* {@link #onSelectionMenu(SelectionMenuEvent, List)}).
* {@link #onButtonClick(ButtonInteractionEvent, List)},
* {@link #onSelectionMenu(SelectMenuInteractionEvent, List)}).
* <p>
* Alternatively, if {@link SlashCommandAdapter} has been extended, it also offers a handy
* {@link SlashCommandAdapter#generateComponentId(String...)} method to ease the flow.
Expand All @@ -129,7 +132,7 @@ public interface SlashCommand extends Feature {
*
* @param event the event that triggered this
*/
void onSlashCommand(@NotNull SlashCommandEvent event);
void onSlashCommand(@NotNull SlashCommandInteractionEvent event);

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

/**
* Triggered by the core system when a selection menu corresponding to this implementation
Expand All @@ -167,15 +171,16 @@ public interface SlashCommand extends Feature {
*
* @param event the event that triggered this
* @param args the arguments transported with the selection menu, see
* {@link #onSlashCommand(SlashCommandEvent)} for details on how these are created
* {@link #onSlashCommand(SlashCommandInteractionEvent)} for details on how these are
* created
*/
void onSelectionMenu(@NotNull SelectionMenuEvent event, @NotNull List<String> args);
void onSelectionMenu(@NotNull SelectMenuInteractionEvent event, @NotNull List<String> args);

/**
* Triggered by the core system during its setup phase. It will provide the command a component
* id generator through this method, which can be used to generate component ids, as used for
* button or selection menus. See {@link #onSlashCommand(SlashCommandEvent)} for details on how
* to use this.
* button or selection menus. See {@link #onSlashCommand(SlashCommandInteractionEvent)} for
* details on how to use this.
*
* @param generator the provided component id generator
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package org.togetherjava.tjbot.commands;

import net.dv8tion.jda.api.events.interaction.ButtonClickEvent;
import net.dv8tion.jda.api.events.interaction.SelectionMenuEvent;
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
import net.dv8tion.jda.api.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.interactions.commands.build.CommandData;
import net.dv8tion.jda.api.interactions.commands.build.Commands;
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
import org.jetbrains.annotations.NotNull;
import org.togetherjava.tjbot.commands.componentids.ComponentId;
import org.togetherjava.tjbot.commands.componentids.ComponentIdGenerator;
Expand All @@ -15,12 +17,12 @@

/**
* Adapter implementation of a {@link SlashCommand}. The minimal setup only requires implementation
* of {@link #onSlashCommand(SlashCommandEvent)}. A new command can then be registered by adding it
* to {@link Features}.
* of {@link #onSlashCommand(SlashCommandInteractionEvent)}. A new command can then be registered by
* adding it to {@link Features}.
* <p>
* Further, {@link #onButtonClick(ButtonClickEvent, List)} and
* {@link #onSelectionMenu(SelectionMenuEvent, List)} can be overridden if desired. The default
* implementation is empty, the adapter will not react to such events.
* Further, {@link #onButtonClick(ButtonInteractionEvent, List)} and
* {@link #onSelectionMenu(SelectMenuInteractionEvent, List)} can be overridden if desired. The
* default implementation is empty, the adapter will not react to such events.
* <p>
* <p>
* The adapter manages all command related data itself, which can be provided during construction
Expand All @@ -31,7 +33,7 @@
* <p>
* If implementations want to add buttons or selection menus, it is highly advised to use component
* IDs generated by {@link #generateComponentId(String...)}, which will automatically create IDs
* that are valid per {@link SlashCommand#onSlashCommand(SlashCommandEvent)}.
* that are valid per {@link SlashCommand#onSlashCommand(SlashCommandInteractionEvent)}.
* <p>
* <p>
* Some example commands are available in {@link org.togetherjava.tjbot.commands.basic}. A minimal
Expand All @@ -46,7 +48,7 @@
* }
*
* &#64;Override
* public void onSlashCommand(@NotNull SlashCommandEvent event) {
* public void onSlashCommand(@NotNull SlashCommandInteractionEvent event) {
* event.reply("Pong!").queue();
* }
* }
Expand All @@ -59,7 +61,7 @@ public abstract class SlashCommandAdapter implements SlashCommand {
private final String name;
private final String description;
private final SlashCommandVisibility visibility;
private final CommandData data;
private final SlashCommandData data;
private ComponentIdGenerator componentIdGenerator;

/**
Expand All @@ -77,7 +79,7 @@ protected SlashCommandAdapter(@NotNull String name, @NotNull String description,
this.description = description;
this.visibility = visibility;

data = new CommandData(name, description);
data = Commands.slash(name, description);
}

@Override
Expand All @@ -96,7 +98,7 @@ protected SlashCommandAdapter(@NotNull String name, @NotNull String description,
}

@Override
public final @NotNull CommandData getData() {
public final @NotNull SlashCommandData getData() {
return data;
}

Expand All @@ -107,19 +109,20 @@ public final void acceptComponentIdGenerator(@NotNull ComponentIdGenerator gener

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

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

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

/**
* Helper method to generate component IDs that are considered valid per
* {@link SlashCommand#onSlashCommand(SlashCommandEvent)}.
* {@link SlashCommand#onSlashCommand(SlashCommandInteractionEvent)}.
* <p>
* They can be used to create buttons or selection menus and transport additional data
* throughout the event (e.g. the user id who created the button dialog).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.togetherjava.tjbot.commands.basic;

import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import org.jetbrains.annotations.NotNull;
import org.togetherjava.tjbot.commands.SlashCommandAdapter;
import org.togetherjava.tjbot.commands.SlashCommandVisibility;
Expand All @@ -24,7 +24,7 @@ public PingCommand() {
* @param event the corresponding event
*/
@Override
public void onSlashCommand(@NotNull SlashCommandEvent event) {
public void onSlashCommand(@NotNull SlashCommandInteractionEvent event) {
event.reply("Pong!").queue();
}
}
Loading