use of com.freya02.botcommands.internal.application.slash.autocomplete.AutocompleteCommandParameter in project BotCommands by freya022.
the class BaseAutocompletionCache method getCompositeOptionValues.
private String[] getCompositeOptionValues(AutocompletionHandlerInfo info, SlashCommandInfo slashCommand, CommandAutoCompleteInteractionEvent event) {
final List<String> optionValues = new ArrayList<>();
optionValues.add(event.getFocusedOption().getValue());
int optionIndex = 0;
final List<String> optionNames = event.getGuild() != null ? slashCommand.getLocalizedOptions(event.getGuild()) : null;
for (final AutocompleteCommandParameter parameter : info.getParameters()) {
final ApplicationOptionData applicationOptionData = parameter.getApplicationOptionData();
if (parameter.isOption()) {
final String optionName = optionNames == null ? applicationOptionData.getEffectiveName() : optionNames.get(optionIndex);
if (optionName == null) {
throw new IllegalArgumentException(String.format("Option name #%d (%s) could not be resolved for %s", optionIndex, applicationOptionData.getEffectiveName(), Utils.formatMethodShort(info.getMethod())));
}
optionIndex++;
if (parameter.isCompositeKey()) {
final OptionMapping option = event.getOption(optionName);
if (option == null) {
optionValues.add("null");
} else if (!event.getFocusedOption().getName().equals(optionName)) {
// Only add the options other than the focused one, since it's already there, saves us from an HashSet
optionValues.add(option.getAsString());
}
}
}
}
return optionValues.toArray(new String[0]);
}
Aggregations