diff --git a/application/src/main/java/org/togetherjava/tjbot/Application.java b/application/src/main/java/org/togetherjava/tjbot/Application.java index 97d038c5c8..5927afe8af 100644 --- a/application/src/main/java/org/togetherjava/tjbot/Application.java +++ b/application/src/main/java/org/togetherjava/tjbot/Application.java @@ -83,7 +83,11 @@ public static void runBot(Config config) { .build(); jda.awaitReady(); + BotCore core = new BotCore(jda, database, config); + CommandReloading.reloadCommands(jda, core); + core.scheduleRoutines(jda); + jda.addEventListener(core); logger.info("Bot is ready"); diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/UserInteractorPrefix.java b/application/src/main/java/org/togetherjava/tjbot/commands/UserInteractorPrefix.java index e4537853e7..53c76a3b5c 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/UserInteractorPrefix.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/UserInteractorPrefix.java @@ -7,18 +7,24 @@ *
* This is used for separate interactors with the same name, by command type (and possibly more in * the future). Our system doesn't allow multiple interactors with the same name, while having a - * slash-command and a message-context-command with the same name can be really useful. + * slash-command, and a message-context-command with the same name can be useful. */ public enum UserInteractorPrefix { - /* - * Implementations that are none of the following have no dedicated prefix - */ + // Implementations that are none of the following have no dedicated prefix. + /** + * Prefix for slash commands. + */ SLASH_COMMAND(SlashCommand.class, "s-"), + /** + * Prefix for message context commands. + */ MESSAGE_CONTEXT_COMMAND(MessageContextCommand.class, "mc-"), + /** + * Prefix for user context commands. + */ USER_CONTEXT_COMMAND(UserContextCommand.class, "uc-"); - private final Class extends UserInteractor> classType; private final String prefix; @@ -36,6 +42,16 @@ public String getPrefix() { return prefix; } + /** + * Returns the name, attached with the prefix in front of it. + * + * @param name the name + * @return the name, with the prefix in front of it. + */ + public String getPrefixedName(String name) { + return prefix + name; + } + /** * The class type that should receive the prefix * diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/system/BotCore.java b/application/src/main/java/org/togetherjava/tjbot/commands/system/BotCore.java index 8c0d5cb0b4..f4b1d6d1ba 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/system/BotCore.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/system/BotCore.java @@ -2,17 +2,19 @@ import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.entities.Channel; +import net.dv8tion.jda.api.events.interaction.command.MessageContextInteractionEvent; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; +import net.dv8tion.jda.api.events.interaction.command.UserContextInteractionEvent; import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; import net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.events.message.MessageUpdateEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; import net.dv8tion.jda.api.interactions.components.ComponentInteraction; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Unmodifiable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.togetherjava.tjbot.CommandReloading; import org.togetherjava.tjbot.commands.*; import org.togetherjava.tjbot.commands.componentids.ComponentId; import org.togetherjava.tjbot.commands.componentids.ComponentIdParser; @@ -38,7 +40,6 @@ * events. It forwards events to their corresponding commands and does the heavy lifting on all sort * of event parsing. *
- *
* Commands are made available via {@link Features}, then the system has to be added to JDA as an
* event listener, using {@link net.dv8tion.jda.api.JDA#addEventListener(Object...)}. Afterwards,
* the system is ready and will correctly forward events to all commands.
@@ -112,25 +113,16 @@ public BotCore(JDA jda, Database database, Config config) {
if (logger.isInfoEnabled()) {
logger.info("Available user interactors: {}", interactors);
}
-
-
- CommandReloading.reloadCommands(jda, this);
- scheduleRoutines(jda);
}
/**
- * Returns a predicate which validates the given interactor
+ * Returns a predicate, which validates the given interactor
*
- * @return A predicate which validates the given interactor
+ * @return A predicate, which validates the given interactor
*/
private static Predicate
@@ -306,33 +320,34 @@ private