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;
}
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;
}
Aggregations