From 526880e1f152b65c7c5b4f95054288135a0f3e86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beatrice=20Dellac=C3=A0?= Date: Tue, 22 Nov 2022 14:40:44 +0100 Subject: [PATCH] Start implementing message-base commands Slash commands can't be used for everything, so we need something to fall back on. --- .../hidekobot/objects/MessageCommand.java | 25 +++++++++++++++++++ .../hidekobot/objects/SlashCommand.java | 11 ++++++++ 2 files changed, 36 insertions(+) create mode 100644 src/main/java/wtf/beatrice/hidekobot/objects/MessageCommand.java diff --git a/src/main/java/wtf/beatrice/hidekobot/objects/MessageCommand.java b/src/main/java/wtf/beatrice/hidekobot/objects/MessageCommand.java new file mode 100644 index 0000000..9deb7d2 --- /dev/null +++ b/src/main/java/wtf/beatrice/hidekobot/objects/MessageCommand.java @@ -0,0 +1,25 @@ +package wtf.beatrice.hidekobot.objects; + +import net.dv8tion.jda.api.events.message.MessageReceivedEvent; + +public interface MessageCommand +{ + + /** + * Get the command's label, which is used when determining if this is the correct command or not. + * + * @return the command label. + */ + String getCommandName(); + + /** + * Run the command logic by parsing the event and replying accordingly. + * + * @param event the received message event. It should not be used for parsing message contents data as + * the arguments already account for it in a better way. + * @param args a pre-formatted list of arguments, excluding the bot prefix and the command name. + * This is useful because command logic won't have to change in case the bot prefix is changed, + * removed, or we switch to another method of triggering commands (ping, trigger words, ...). + */ + void runCommand(MessageReceivedEvent event, String[] args); +} diff --git a/src/main/java/wtf/beatrice/hidekobot/objects/SlashCommand.java b/src/main/java/wtf/beatrice/hidekobot/objects/SlashCommand.java index 54c3251..066a10b 100644 --- a/src/main/java/wtf/beatrice/hidekobot/objects/SlashCommand.java +++ b/src/main/java/wtf/beatrice/hidekobot/objects/SlashCommand.java @@ -5,7 +5,18 @@ import org.jetbrains.annotations.NotNull; public interface SlashCommand { + /** + * Get the command's registered label, or how Discord sees and runs the registered command. + * + * @return the command label. + */ String getCommandName(); + + /** + * Run the command logic by parsing the event and replying accordingly. + * + * @param event the received slash command event. + */ void runSlashCommand(@NotNull SlashCommandInteractionEvent event); }