Search in sources :

Example 1 with ISlashCommand

use of com.dynxsty.dih4jda.commands.interactions.slash_command.ISlashCommand in project DIH4JDA by DynxstyGIT.

the class InteractionHandler method getSubcommandData.

/**
 * Gets all {@link SubcommandData} from the given array of {@link Subcommand} classes.
 *
 * @param command      The base command's instance.
 * @param subClasses   All sub command classes.
 * @param subGroupName The Subcommand Group's name. (if available)
 * @param guild        The current guild (if available)
 * @return The new {@link CommandListUpdateAction}.
 * @throws Exception If an error occurs.
 */
private Set<SubcommandData> getSubcommandData(BaseSlashCommand command, Class<? extends Subcommand>[] subClasses, @Nullable String subGroupName, @Nullable Guild guild) throws Exception {
    Set<SubcommandData> subDataList = new HashSet<>();
    for (Class<? extends Subcommand> sub : subClasses) {
        Subcommand instance = (Subcommand) this.getClassInstance(guild, sub);
        if (instance.getSubcommandData() == null) {
            DIH4JDALogger.warn(String.format("Class %s is missing SubcommandData. It will be ignored.", sub.getName()));
            continue;
        }
        String commandPath;
        if (subGroupName == null) {
            commandPath = buildCommandPath(command.getCommandData().getName(), instance.getSubcommandData().getName());
        } else {
            commandPath = buildCommandPath(command.getCommandData().getName(), subGroupName, instance.getSubcommandData().getName());
        }
        slashCommandIndex.put(commandPath, new SlashCommandInteraction((ISlashCommand) instance, sub, command.getCommandPrivileges()));
        DIH4JDALogger.info(String.format("\t[*] Registered command: /%s", commandPath), DIH4JDALogger.Type.SLASH_COMMAND_REGISTERED);
        subDataList.add(instance.getSubcommandData());
    }
    return subDataList;
}
Also used : ISlashCommand(com.dynxsty.dih4jda.commands.interactions.slash_command.ISlashCommand) SubcommandData(net.dv8tion.jda.api.interactions.commands.build.SubcommandData) SlashCommandInteraction(com.dynxsty.dih4jda.commands.interactions.slash_command.SlashCommandInteraction)

Example 2 with ISlashCommand

use of com.dynxsty.dih4jda.commands.interactions.slash_command.ISlashCommand in project DIH4JDA by DynxstyGIT.

the class InteractionHandler method getBaseCommandData.

/**
 * Gets the complete {@link SlashCommandData} (including Subcommands & Subcommand Groups) of a single {@link BaseSlashCommand}.
 *
 * @param command      The base command's instance.
 * @param commandClass The base command's class.
 * @param guild        The current guild (if available)
 * @return The new {@link CommandListUpdateAction}.
 * @throws Exception If an error occurs.
 */
private SlashCommandData getBaseCommandData(@NotNull BaseSlashCommand command, Class<? extends BaseSlashCommand> commandClass, @Nullable Guild guild) throws Exception {
    if (command.getCommandData() == null) {
        DIH4JDALogger.warn(String.format("Class %s is missing CommandData. It will be ignored.", commandClass.getName()));
        return null;
    }
    SlashCommandData commandData = command.getCommandData();
    if (command.getSubcommandGroups() != null) {
        commandData.addSubcommandGroups(this.getSubcommandGroupData(command, guild));
    }
    if (command.getSubcommands() != null) {
        commandData.addSubcommands(this.getSubcommandData(command, command.getSubcommands(), null, guild));
    }
    if (command.getSubcommandGroups() == null && command.getSubcommands() == null) {
        slashCommandIndex.put(buildCommandPath(commandData.getName()), new SlashCommandInteraction((ISlashCommand) command, commandClass, command.getCommandPrivileges()));
        DIH4JDALogger.info(String.format("\t[*] Registered command: /%s", command.getCommandData().getName()), DIH4JDALogger.Type.SLASH_COMMAND_REGISTERED);
    }
    return commandData;
}
Also used : ISlashCommand(com.dynxsty.dih4jda.commands.interactions.slash_command.ISlashCommand) SlashCommandData(net.dv8tion.jda.api.interactions.commands.build.SlashCommandData) SlashCommandInteraction(com.dynxsty.dih4jda.commands.interactions.slash_command.SlashCommandInteraction)

Aggregations

ISlashCommand (com.dynxsty.dih4jda.commands.interactions.slash_command.ISlashCommand)2 SlashCommandInteraction (com.dynxsty.dih4jda.commands.interactions.slash_command.SlashCommandInteraction)2 SlashCommandData (net.dv8tion.jda.api.interactions.commands.build.SlashCommandData)1 SubcommandData (net.dv8tion.jda.api.interactions.commands.build.SubcommandData)1