use of net.anweisen.utilities.jda.manager.impl.slashcommands.build.ICommandData in project Utility by anweisen.
the class SlashCommandHelper method acquireCommand.
@Nonnull
private IBaseCommandData<?, ?> acquireCommand(@Nonnull RegisteredCommand command) {
String name = command.getOptions().getFirstName();
List<String> subcommandNames = new ArrayList<>(Arrays.asList(name.split(" ")));
String parentName = subcommandNames.get(0);
ICommandData parentRootCommand = slashCommands.computeIfAbsent(parentName, key -> new ICommandData(parentName));
switch(subcommandNames.size()) {
default:
throw new IllegalArgumentException("Discord only supports 3 chained command names for subcommands in slashcommands (got " + subcommandNames.size() + ": '" + name + "')");
case 1:
return parentRootCommand;
case 2:
{
String commandName = subcommandNames.get(1);
ISubcommandData commandData = new ISubcommandData(commandName);
parentRootCommand.addSubcommand(commandData);
return commandData;
}
case 3:
{
String subCommandName = subcommandNames.get(1);
ISubcommandGroupData subcommandGroup = parentRootCommand.getSubcommandGroups().stream().filter(data -> data.getName().equals(subCommandName)).findFirst().orElseGet(() -> {
ISubcommandGroupData result = new ISubcommandGroupData(subCommandName);
parentRootCommand.addSubcommandGroup(result);
return result;
});
String commandName = subcommandNames.get(2);
ISubcommandData commandData = new ISubcommandData(commandName);
subcommandGroup.addSubcommand(commandData);
return commandData;
}
}
}
Aggregations