Search in sources :

Example 1 with EmptyChoice

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;
}
Also used : List(java.util.List) EmptyChoice(dev.triumphteam.cmd.slash.choices.EmptyChoice) AbstractSubCommand(dev.triumphteam.cmd.core.AbstractSubCommand) ExecutionProvider(dev.triumphteam.cmd.core.execution.ExecutionProvider) OptionData(net.dv8tion.jda.api.interactions.commands.build.OptionData) Choice(dev.triumphteam.cmd.slash.choices.Choice) JdaOptionUtil(dev.triumphteam.cmd.slash.util.JdaOptionUtil) InternalArgument(dev.triumphteam.cmd.core.argument.InternalArgument) NotNull(org.jetbrains.annotations.NotNull) Command(net.dv8tion.jda.api.interactions.commands.Command) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) EmptyChoice(dev.triumphteam.cmd.slash.choices.EmptyChoice) Choice(dev.triumphteam.cmd.slash.choices.Choice) OptionData(net.dv8tion.jda.api.interactions.commands.build.OptionData) InternalArgument(dev.triumphteam.cmd.core.argument.InternalArgument) ArrayList(java.util.ArrayList) EmptyChoice(dev.triumphteam.cmd.slash.choices.EmptyChoice)

Example 2 with EmptyChoice

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;
}
Also used : SimpleChoice(dev.triumphteam.cmd.slash.choices.SimpleChoice) EmptyChoice(dev.triumphteam.cmd.slash.choices.EmptyChoice) SimpleChoice(dev.triumphteam.cmd.slash.choices.SimpleChoice) Choice(dev.triumphteam.cmd.slash.choices.Choice) EnumChoice(dev.triumphteam.cmd.slash.choices.EnumChoice) SubCommandRegistrationException(dev.triumphteam.cmd.core.exceptions.SubCommandRegistrationException) ArrayList(java.util.ArrayList) EmptyChoice(dev.triumphteam.cmd.slash.choices.EmptyChoice) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List)

Aggregations

Choice (dev.triumphteam.cmd.slash.choices.Choice)2 EmptyChoice (dev.triumphteam.cmd.slash.choices.EmptyChoice)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 AbstractSubCommand (dev.triumphteam.cmd.core.AbstractSubCommand)1 InternalArgument (dev.triumphteam.cmd.core.argument.InternalArgument)1 SubCommandRegistrationException (dev.triumphteam.cmd.core.exceptions.SubCommandRegistrationException)1 ExecutionProvider (dev.triumphteam.cmd.core.execution.ExecutionProvider)1 EnumChoice (dev.triumphteam.cmd.slash.choices.EnumChoice)1 SimpleChoice (dev.triumphteam.cmd.slash.choices.SimpleChoice)1 JdaOptionUtil (dev.triumphteam.cmd.slash.util.JdaOptionUtil)1 Collections.emptyList (java.util.Collections.emptyList)1 Collections.singletonList (java.util.Collections.singletonList)1 Collectors (java.util.stream.Collectors)1 Command (net.dv8tion.jda.api.interactions.commands.Command)1 OptionData (net.dv8tion.jda.api.interactions.commands.build.OptionData)1 NotNull (org.jetbrains.annotations.NotNull)1