Remove the need to register slash commands separately
All checks were successful
continuous-integration/drone/push Build is passing

We modified the slash command interface to allow getting command data, and created a generic implementation of it that automatically retrieves data from the command data. The interface should not be used now. Instead, extending the implementation is preferred as it provides a semi-working command already.
This commit is contained in:
2022-11-22 16:39:31 +01:00
parent ee263a1297
commit a7ac446b0b
12 changed files with 126 additions and 65 deletions

View File

@@ -1,10 +1,12 @@
package wtf.beatrice.hidekobot.objects;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
import org.jetbrains.annotations.NotNull;
public interface SlashCommand
{
/**
* Get the command's registered label, or how Discord sees and runs the registered command.
*
@@ -12,6 +14,13 @@ public interface SlashCommand
*/
String getCommandName();
/**
* Get a JDA command data object that will then be used to tell the Discord API the specifics of this
* command.
*
* @return the command data object.
*/
CommandData getSlashCommandData();
/**
* Run the command logic by parsing the event and replying accordingly.
*

View File

@@ -0,0 +1,24 @@
package wtf.beatrice.hidekobot.objects;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
import org.jetbrains.annotations.NotNull;
public class SlashCommandImpl implements SlashCommand
{
@Override
public String getCommandName() {
return getSlashCommandData().getName();
}
@Override
public CommandData getSlashCommandData() {
return null;
}
@Override
public void runSlashCommand(@NotNull SlashCommandInteractionEvent event) {
event.reply("Base command implementation").queue();
}
}