use of net.dv8tion.jda.api.interactions.commands.build.SubcommandGroupData in project Discord-Core-Bot-Apple by demodude4u.
the class DiscordBot method buildUpdateCommands.
// Hold my beer
@SuppressWarnings("unchecked")
private void buildUpdateCommands(CommandListUpdateAction updateCommands) {
Map<String, Object> root = new LinkedHashMap<>();
for (SlashCommandDefinition command : commandSlash.values()) {
String[] pathSplit = command.getPath().split("/");
Map<String, Object> group = root;
for (int i = 0; i < pathSplit.length; i++) {
String name = pathSplit[i];
if (i == pathSplit.length - 1) {
group.put(name, command);
} else {
Object subGroup = group.get(name);
if (subGroup == null) {
group.put(name, subGroup = new LinkedHashMap<String, Object>());
}
group = (Map<String, Object>) subGroup;
}
}
}
for (Entry<String, Object> rootEntry : root.entrySet()) {
SlashCommandData commandData;
if (rootEntry.getValue() instanceof SlashCommandDefinition) {
SlashCommandDefinition commandDefinition = (SlashCommandDefinition) rootEntry.getValue();
commandData = Commands.slash(rootEntry.getKey(), commandDefinition.getDescription());
for (SlashCommandOptionDefinition option : commandDefinition.getOptions()) {
commandData = commandData.addOption(option.getType(), option.getName(), option.getDescription(), option.isRequired(), option.isAutoComplete());
}
} else {
Map<String, Object> sub = (Map<String, Object>) rootEntry.getValue();
commandData = Commands.slash(rootEntry.getKey(), sub.keySet().stream().collect(Collectors.joining(", ")));
for (Entry<String, Object> subEntry : sub.entrySet()) {
if (subEntry.getValue() instanceof SlashCommandDefinition) {
SlashCommandDefinition commandDefinition = (SlashCommandDefinition) subEntry.getValue();
SubcommandData subcommandData = new SubcommandData(subEntry.getKey(), commandDefinition.getDescription());
for (SlashCommandOptionDefinition option : commandDefinition.getOptions()) {
subcommandData = subcommandData.addOption(option.getType(), option.getName(), option.getDescription(), option.isRequired(), option.isAutoComplete());
}
commandData = commandData.addSubcommands(subcommandData);
} else {
Map<String, SlashCommandDefinition> subSub = (Map<String, SlashCommandDefinition>) subEntry.getValue();
SubcommandGroupData subcommandGroupData = new SubcommandGroupData(subEntry.getKey(), subSub.keySet().stream().collect(Collectors.joining(", ")));
for (Entry<String, SlashCommandDefinition> subSubEntry : subSub.entrySet()) {
SubcommandData subcommandData = new SubcommandData(subSubEntry.getKey(), subSubEntry.getValue().getDescription());
for (SlashCommandOptionDefinition option : subSubEntry.getValue().getOptions()) {
subcommandData = subcommandData.addOption(option.getType(), option.getName(), option.getDescription(), option.isRequired(), option.isAutoComplete());
}
subcommandGroupData = subcommandGroupData.addSubcommands(subcommandData);
}
commandData = commandData.addSubcommandGroups(subcommandGroupData);
}
}
}
updateCommands = updateCommands.addCommands(commandData);
}
for (MessageCommandDefinition commandDefinition : commandMessage.values()) {
CommandData commandData = Commands.message(commandDefinition.getName());
updateCommands = updateCommands.addCommands(commandData);
}
}
Aggregations