Search in sources :

Example 1 with BaseContextCommand

use of com.dynxsty.dih4jda.commands.interactions.context_command.dao.BaseContextCommand in project DIH4JDA by DynxstyGIT.

the class InteractionHandler method registerContextCommands.

/**
 * Registers all context commands. Loops through all classes found in the commands package that is a subclass of {@link BaseContextCommand}.
 */
private void registerContextCommands() {
    Reflections commands = new Reflections(this.dih4jda.getCommandsPackage());
    Set<Class<? extends BaseContextCommand>> classes = commands.getSubTypesOf(BaseContextCommand.class);
    for (Class<? extends BaseContextCommand> c : classes) {
        if (c.getSuperclass().equals(GlobalContextCommand.class)) {
            globalContexts.add(c);
        } else if (c.getSuperclass().equals(GuildContextCommand.class)) {
            guildContexts.add(c);
        }
    }
}
Also used : GuildContextCommand(com.dynxsty.dih4jda.commands.interactions.context_command.dao.GuildContextCommand) BaseContextCommand(com.dynxsty.dih4jda.commands.interactions.context_command.dao.BaseContextCommand) Reflections(org.reflections.Reflections)

Example 2 with BaseContextCommand

use of com.dynxsty.dih4jda.commands.interactions.context_command.dao.BaseContextCommand in project DIH4JDA by DynxstyGIT.

the class InteractionHandler method getGlobalContextCommandData.

/**
 * Gets all Global Context commands registered in {@link InteractionHandler#registerContextCommands()} and
 * returns their {@link CommandData} as a List.
 *
 * @throws Exception If an error occurs.
 */
private Set<CommandData> getGlobalContextCommandData() throws Exception {
    Set<CommandData> commands = new HashSet<>();
    for (Class<? extends BaseContextCommand> contextCommandClass : this.globalContexts) {
        BaseContextCommand instance = (BaseContextCommand) this.getClassInstance(null, contextCommandClass);
        CommandData data = this.getContextCommandData(instance, contextCommandClass);
        if (data != null) {
            commands.add(data);
        }
    }
    DIH4JDALogger.info("[*] Queuing Global Context Commands", DIH4JDALogger.Type.CONTEXT_COMMANDS_QUEUED);
    return commands;
}
Also used : BaseContextCommand(com.dynxsty.dih4jda.commands.interactions.context_command.dao.BaseContextCommand) CommandData(net.dv8tion.jda.api.interactions.commands.build.CommandData) SlashCommandData(net.dv8tion.jda.api.interactions.commands.build.SlashCommandData)

Example 3 with BaseContextCommand

use of com.dynxsty.dih4jda.commands.interactions.context_command.dao.BaseContextCommand in project DIH4JDA by DynxstyGIT.

the class InteractionHandler method getGuildContextCommandData.

/**
 * Gets all Guild Context commands registered in {@link InteractionHandler#registerContextCommands()} and
 * returns their {@link CommandData} as a List.
 *
 * @param guild The context command's guild.
 * @throws Exception If an error occurs.
 */
private Set<CommandData> getGuildContextCommandData(@NotNull Guild guild) throws Exception {
    Set<CommandData> commands = new HashSet<>();
    for (Class<? extends BaseContextCommand> contextCommandClass : this.guildContexts) {
        BaseContextCommand instance = (BaseContextCommand) this.getClassInstance(guild, contextCommandClass);
        commands.add(this.getContextCommandData(instance, contextCommandClass));
    }
    DIH4JDALogger.info(String.format("[%s] Queuing Guild Context Commands", guild.getName()), DIH4JDALogger.Type.CONTEXT_COMMANDS_QUEUED);
    return commands;
}
Also used : BaseContextCommand(com.dynxsty.dih4jda.commands.interactions.context_command.dao.BaseContextCommand) CommandData(net.dv8tion.jda.api.interactions.commands.build.CommandData) SlashCommandData(net.dv8tion.jda.api.interactions.commands.build.SlashCommandData)

Aggregations

BaseContextCommand (com.dynxsty.dih4jda.commands.interactions.context_command.dao.BaseContextCommand)3 CommandData (net.dv8tion.jda.api.interactions.commands.build.CommandData)2 SlashCommandData (net.dv8tion.jda.api.interactions.commands.build.SlashCommandData)2 GuildContextCommand (com.dynxsty.dih4jda.commands.interactions.context_command.dao.GuildContextCommand)1 Reflections (org.reflections.Reflections)1