Compare commits

..

No commits in common. "1ecbc563a63a70cea8656286b3f260c9eff22726" and "a17f5e826f42e55c3f6d10213867eff53002ec2d" have entirely different histories.

2 changed files with 4 additions and 25 deletions

View File

@ -5,19 +5,15 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import org.apache.logging.log4j.Logger;
import net.tomatentum.marinara.Marinara; import net.tomatentum.marinara.Marinara;
import net.tomatentum.marinara.interaction.InteractionHandler; import net.tomatentum.marinara.interaction.InteractionHandler;
import net.tomatentum.marinara.interaction.InteractionType; import net.tomatentum.marinara.interaction.InteractionType;
import net.tomatentum.marinara.interaction.commands.SlashCommandDefinition; import net.tomatentum.marinara.interaction.commands.SlashCommandDefinition;
import net.tomatentum.marinara.interaction.commands.ExecutableSlashCommandDefinition; import net.tomatentum.marinara.interaction.commands.ExecutableSlashCommandDefinition;
import net.tomatentum.marinara.interaction.methods.SlashCommandInteractionMethod; import net.tomatentum.marinara.interaction.methods.SlashCommandInteractionMethod;
import net.tomatentum.marinara.util.LoggerUtil;
import net.tomatentum.marinara.interaction.methods.InteractionMethod; import net.tomatentum.marinara.interaction.methods.InteractionMethod;
public class InteractionRegistry { public class InteractionRegistry {
private Logger logger = LoggerUtil.getLogger(getClass());
private List<InteractionMethod> interactionMethods; private List<InteractionMethod> interactionMethods;
private Marinara marinara; private Marinara marinara;
@ -30,11 +26,8 @@ public class InteractionRegistry {
public void addInteractions(InteractionHandler interactionHandler) { public void addInteractions(InteractionHandler interactionHandler) {
for (Method method : interactionHandler.getClass().getMethods()) { for (Method method : interactionHandler.getClass().getMethods()) {
InteractionMethod iMethod = InteractionMethod.create(method, interactionHandler, marinara); InteractionMethod iMethod = InteractionMethod.create(method, interactionHandler, marinara);
if (iMethod != null) { if (iMethod != null)
this.interactionMethods.add(iMethod); this.interactionMethods.add(iMethod);
logger.debug("Added {} method from {}", iMethod.getMethod().getName(), interactionHandler.getClass().getSimpleName());
}
logger.info("Added all Interactions from {}", interactionHandler.getClass().getSimpleName());
} }
} }
@ -53,26 +46,16 @@ public class InteractionRegistry {
appDef.get().addExecutableCommand(def); appDef.get().addExecutableCommand(def);
else else
defs.add(new SlashCommandDefinition(def.applicationCommand()).addExecutableCommand(def)); 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(SlashCommandDefinition[]::new)); marinara.getWrapper().registerSlashCommands(defs.toArray(new SlashCommandDefinition[0]));
logger.info("Registered all SlashCommands");
} }
public void handle(Object context) { public void handle(Object context) {
InteractionType type = marinara.getWrapper().getInteractionType(context.getClass());
logger.debug("Received {} interaction ", context);
interactionMethods.forEach((m) -> { interactionMethods.forEach((m) -> {
if (m.getType().equals(type) && m.canRun(context)) { InteractionType type = marinara.getWrapper().getInteractionType(context.getClass());
if (m.getType().equals(type) && m.canRun(context))
m.run(context); m.run(context);
logger.info("Running {} interaction using {}\ncontext: {}", type, m.getMethod().toString(), context.toString());
}
}); });
} }
} }

View File

@ -17,8 +17,4 @@ public class LoggerUtil {
return new SimpleLogger(name, Level.DEBUG, true, false, true, true, "yyyy-MM-dd HH:mm:ss.SSSZ", null, return new SimpleLogger(name, Level.DEBUG, true, false, true, true, "yyyy-MM-dd HH:mm:ss.SSSZ", null,
new PropertiesUtil(new Properties()), System.out); new PropertiesUtil(new Properties()), System.out);
} }
public static Logger getLogger(Class<?> clazz) {
return getLogger(clazz.getName());
}
} }