use of dev.triumphteam.cmd.slash.choices.EmptyChoice in project triumph-cmds by TriumphTeam.
the class SlashSubCommand method getJdaOptions.
public List<OptionData> getJdaOptions() {
final List<OptionData> options = new ArrayList<>();
final List<InternalArgument<S, ?>> internalArguments = getArguments();
for (int i = 0; i < internalArguments.size(); i++) {
final InternalArgument<S, ?> internalArgument = internalArguments.get(i);
final OptionData option = new OptionData(JdaOptionUtil.fromType(internalArgument.getType()), internalArgument.getName(), internalArgument.getDescription(), !internalArgument.isOptional());
options.add(option);
final Choice suggestion = getChoice(i);
if (suggestion instanceof EmptyChoice)
continue;
option.addChoices(suggestion.getChoices().stream().map(it -> new Command.Choice(it, it)).limit(25).collect(Collectors.toList()));
}
return options;
}
use of dev.triumphteam.cmd.slash.choices.EmptyChoice in project triumph-cmds by TriumphTeam.
the class SlashSubCommandProcessor method extractChoices.
public List<Choice> extractChoices(@NotNull final Method method, @NotNull final Class<? extends BaseCommand> commandClass) {
final List<Choice> choiceList = new ArrayList<>();
for (final dev.triumphteam.cmd.slash.annotation.Choice choice : getChoicesFromAnnotation(method)) {
final String key = choice.value();
if (key.isEmpty()) {
choiceList.add(new EmptyChoice());
continue;
}
final Supplier<List<String>> resolver = choiceRegistry.getChoiceResolver(ChoiceKey.of(key));
if (resolver == null) {
throw new SubCommandRegistrationException("Cannot find the suggestion key `" + key + "`", method, commandClass);
}
choiceList.add(new SimpleChoice(resolver));
}
extractSuggestionFromParams(method, choiceList, commandClass);
return choiceList;
}
Aggregations