diff --git a/src/main/java/me/goudham/command/SlashCommandManager.java b/src/main/java/me/goudham/command/SlashCommandManager.java index c3f556c6..808dced4 100644 --- a/src/main/java/me/goudham/command/SlashCommandManager.java +++ b/src/main/java/me/goudham/command/SlashCommandManager.java @@ -3,19 +3,21 @@ package me.goudham.command; import io.micronaut.core.annotation.Introspected; import jakarta.inject.Inject; import jakarta.inject.Singleton; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.util.HashMap; import java.util.List; import java.util.Map; -import me.goudham.bot.command.ISlashCommand; import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; import net.dv8tion.jda.api.interactions.commands.build.CommandData; import net.dv8tion.jda.api.requests.restaction.CommandListUpdateAction; +import net.dv8tion.jda.internal.utils.tuple.Pair; @Singleton @Introspected public class SlashCommandManager implements CommandManager { - private final Map commandMap = new HashMap<>(); + private final Map> commandMap = new HashMap<>(); private final CommandLoader commandLoader; @Inject @@ -32,8 +34,15 @@ public class SlashCommandManager implements CommandManager { @Override public void handleSlashCommandEvent(SlashCommandEvent slashCommandEvent) { - String name = slashCommandEvent.getName(); - ISlashCommand slashCommand = commandMap.get(name); - slashCommand.handle(slashCommandEvent); + String commandPath = slashCommandEvent.getCommandPath(); + Pair slashCommandPair = commandMap.get(commandPath); + Object bean = slashCommandPair.getLeft(); + Method method = slashCommandPair.getRight(); + + try { + method.invoke(bean, slashCommandEvent); + } catch (IllegalAccessException | InvocationTargetException exp) { + exp.printStackTrace(); + } } }