Package xyz.dynxsty.dih4jda.util
Class AutoCompleteUtils
java.lang.Object
xyz.dynxsty.dih4jda.util.AutoCompleteUtils
Utility class that contains some useful methods regarding the AutoComplete system.
- Since:
- v1.4
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringbuildCacheId(net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent event) Builds an identifier from the specifiedCommandAutoCompleteInteractionEventby combining the command path, the user's id, the guild's id (or simply "0" if the guild is null) and the option's name.static voidcacheChoices(net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent event, List<net.dv8tion.jda.api.interactions.commands.Command.Choice> choices) Caches the given list of choices.static List<net.dv8tion.jda.api.interactions.commands.Command.Choice>filterChoices(String filter, List<net.dv8tion.jda.api.interactions.commands.Command.Choice> choices) Filters all AutoComplete choices based on the user's current input.static List<net.dv8tion.jda.api.interactions.commands.Command.Choice>filterChoices(net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent event, List<net.dv8tion.jda.api.interactions.commands.Command.Choice> choices) Filters all AutoComplete choices based on the user's current input.static List<net.dv8tion.jda.api.interactions.commands.Command.Choice>getFromCache(String id) Attempts to get aListofCommand.Choices, based on the specified id.static List<net.dv8tion.jda.api.interactions.commands.Command.Choice>handleChoices(net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent event, Function<net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent, List<net.dv8tion.jda.api.interactions.commands.Command.Choice>> choicesFunction) A simple shortcut for caching AutoComplete Choices.static voidremoveFromCache(String commandPath, String userId, String guildId) Removes all cached choices for the given command, user invalid input: '&' guild.
-
Method Details
-
filterChoices
@Contract("_, _ -> param2") @Nonnull public static List<net.dv8tion.jda.api.interactions.commands.Command.Choice> filterChoices(@Nonnull net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent event, List<net.dv8tion.jda.api.interactions.commands.Command.Choice> choices) Filters all AutoComplete choices based on the user's current input.return event.replyChoices(AutoCompleteUtils.filterChoices(event, choices)); -
filterChoices
@Contract("_, _ -> param2") @Nonnull public static List<net.dv8tion.jda.api.interactions.commands.Command.Choice> filterChoices(String filter, @Nonnull List<net.dv8tion.jda.api.interactions.commands.Command.Choice> choices) Filters all AutoComplete choices based on the user's current input.return event.replyChoices(AutoCompleteUtils.filterChoices("abc", choices)); -
handleChoices
@Nonnull public static List<net.dv8tion.jda.api.interactions.commands.Command.Choice> handleChoices(@Nonnull net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent event, Function<net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent, List<net.dv8tion.jda.api.interactions.commands.Command.Choice>> choicesFunction) A simple shortcut for caching AutoComplete Choices. This will try to get, based on the specifiedCommandAutoCompleteInteractionEvent, aListofCommand.Choices. If no mapping is found, this will then simply cache the choices for later usage.- Parameters:
event- TheCommandAutoCompleteInteractionEventwhich was fired.choicesFunction- The function to use if no mapping is found and the choices need to be cached.- Returns:
- An unmodifiable
ListofCommand.Choices. - Since:
- v1.6
-
cacheChoices
public static void cacheChoices(@Nonnull net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent event, List<net.dv8tion.jda.api.interactions.commands.Command.Choice> choices) Caches the given list of choices.- Parameters:
event- TheCommandAutoCompleteInteractionEventwhich was fired.choices- TheListofCommand.Choices to cache.- Since:
- v1.6
-
getFromCache
@Nullable public static List<net.dv8tion.jda.api.interactions.commands.Command.Choice> getFromCache(String id) Attempts to get aListofCommand.Choices, based on the specified id. If there is no mapping with the specfied id, this will return null.- Parameters:
id- The choices' id.- Returns:
- An unmodifiable
ListofCommand.Choices, or null. - Since:
- v1.6
-
removeFromCache
Removes all cached choices for the given command, user invalid input: '&' guild. This method gets called every time the specified user executes the specified command in the specified guild. This is needed in order to retain the dynamic aspect of autocomplete choices.- Parameters:
commandPath- The command's path.userId- The user's id.guildId- The guild's id.- Since:
- v1.6
-
buildCacheId
@Nonnull public static String buildCacheId(@Nonnull net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent event) Builds an identifier from the specifiedCommandAutoCompleteInteractionEventby combining the command path, the user's id, the guild's id (or simply "0" if the guild is null) and the option's name.- Parameters:
event- TheCommandAutoCompleteInteractionEventwhich was fired.- Returns:
- The identifier which is used in combination with the
CHOICE_CACHE - Since:
- v1.6
-