add registerCommands() method

This commit is contained in:
tueem 2024-10-14 17:13:51 +02:00
parent 42a1d86bf9
commit b809411faf
Signed by: tueem
GPG Key ID: 65C8667EC17A88FB

@ -1,10 +1,15 @@
package net.tomatentum.marinara.registry;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import net.tomatentum.marinara.handler.InteractionHandler;
import net.tomatentum.marinara.interaction.InteractionType;
import net.tomatentum.marinara.interaction.commands.ApplicationCommandDefinition;
import net.tomatentum.marinara.interaction.commands.ExecutableCommandDefinition;
import net.tomatentum.marinara.interaction.methods.CommandInteractionMethod;
import net.tomatentum.marinara.interaction.methods.InteractionMethod;
import net.tomatentum.marinara.wrapper.LibraryWrapper;
@ -23,6 +28,24 @@ public class InteractionRegistry {
}
}
public void registerCommands() {
List<ApplicationCommandDefinition> defs = new ArrayList<>();
List<ExecutableCommandDefinition> execDefs = interactionMethods.stream()
.filter((x) -> x.getClass().isAssignableFrom(CommandInteractionMethod.class))
.map((x) -> ((CommandInteractionMethod)x).getCommandDefinition())
.toList();
execDefs.forEach((def) -> {
Optional<ApplicationCommandDefinition> appDef = defs.stream()
.filter((x) -> x.applicationCommand().equals(def.applicationCommand()))
.findFirst();
if (appDef.isPresent())
appDef.get().addExecutableCommand(def);
else
defs.add(new ApplicationCommandDefinition(def.applicationCommand()).addExecutableCommand(def));
});
}
public void handle(Object context) {
interactionMethods.forEach((m) -> {
InteractionType type = wrapper.getInteractionType(context.getClass());