From 1ecbc563a63a70cea8656286b3f260c9eff22726 Mon Sep 17 00:00:00 2001 From: tueem Date: Thu, 19 Dec 2024 18:07:33 +0100 Subject: [PATCH] add Logging in InteractionRegistry --- .../registry/InteractionRegistry.java | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/lib/src/main/java/net/tomatentum/marinara/registry/InteractionRegistry.java b/lib/src/main/java/net/tomatentum/marinara/registry/InteractionRegistry.java index d1640d6..8bb8612 100644 --- a/lib/src/main/java/net/tomatentum/marinara/registry/InteractionRegistry.java +++ b/lib/src/main/java/net/tomatentum/marinara/registry/InteractionRegistry.java @@ -5,15 +5,19 @@ import java.util.ArrayList; import java.util.List; import java.util.Optional; +import org.apache.logging.log4j.Logger; + import net.tomatentum.marinara.Marinara; import net.tomatentum.marinara.interaction.InteractionHandler; import net.tomatentum.marinara.interaction.InteractionType; import net.tomatentum.marinara.interaction.commands.SlashCommandDefinition; import net.tomatentum.marinara.interaction.commands.ExecutableSlashCommandDefinition; import net.tomatentum.marinara.interaction.methods.SlashCommandInteractionMethod; +import net.tomatentum.marinara.util.LoggerUtil; import net.tomatentum.marinara.interaction.methods.InteractionMethod; public class InteractionRegistry { + private Logger logger = LoggerUtil.getLogger(getClass()); private List interactionMethods; private Marinara marinara; @@ -26,8 +30,11 @@ public class InteractionRegistry { public void addInteractions(InteractionHandler interactionHandler) { for (Method method : interactionHandler.getClass().getMethods()) { InteractionMethod iMethod = InteractionMethod.create(method, interactionHandler, marinara); - if (iMethod != null) + if (iMethod != null) { this.interactionMethods.add(iMethod); + logger.debug("Added {} method from {}", iMethod.getMethod().getName(), interactionHandler.getClass().getSimpleName()); + } + logger.info("Added all Interactions from {}", interactionHandler.getClass().getSimpleName()); } } @@ -46,16 +53,26 @@ public class InteractionRegistry { appDef.get().addExecutableCommand(def); else defs.add(new SlashCommandDefinition(def.applicationCommand()).addExecutableCommand(def)); + + logger.debug("Added Executable Command {}{}{} for registration", + def.applicationCommand().name(), + def.subCommandGroup().name().isBlank() ? "" : "." + def.subCommandGroup().name(), + def.subCommand().name().isBlank() ? "" : "." + def.subCommand().name() + ); }); - marinara.getWrapper().registerSlashCommands(defs.toArray(new SlashCommandDefinition[0])); + marinara.getWrapper().registerSlashCommands(defs.toArray(SlashCommandDefinition[]::new)); + logger.info("Registered all SlashCommands"); } public void handle(Object context) { + InteractionType type = marinara.getWrapper().getInteractionType(context.getClass()); + logger.debug("Received {} interaction ", context); interactionMethods.forEach((m) -> { - InteractionType type = marinara.getWrapper().getInteractionType(context.getClass()); - if (m.getType().equals(type) && m.canRun(context)) + if (m.getType().equals(type) && m.canRun(context)) { m.run(context); + logger.info("Running {} interaction using {}\ncontext: {}", type, m.getMethod().toString(), context.toString()); + } }); } }