Class AutoCompleteUtils

java.lang.Object
xyz.dynxsty.dih4jda.util.AutoCompleteUtils

public class AutoCompleteUtils extends Object
Utility class that contains some useful methods regarding the AutoComplete system.
Since:
v1.4
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    buildCacheId(net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent event)
    Builds an identifier from the specified CommandAutoCompleteInteractionEvent by 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 void
    cacheChoices(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>
    Attempts to get a List of Command.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 void
    removeFromCache(String commandPath, String userId, String guildId)
    Removes all cached choices for the given command, user invalid input: '&' guild.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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));
       
      Parameters:
      event - The CommandAutoCompleteInteractionEvent that was fired.
      choices - A List of Command.Choices.
      Returns:
      The filtered List of Command.Choices.
      Since:
      v1.4
    • 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));
       
      Parameters:
      filter - The filter.
      choices - A List of Command.Choices.
      Returns:
      The filtered List of Command.Choices.
      Since:
      v1.4
    • 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 specified CommandAutoCompleteInteractionEvent, a List of Command.Choices. If no mapping is found, this will then simply cache the choices for later usage.
      Parameters:
      event - The CommandAutoCompleteInteractionEvent which was fired.
      choicesFunction - The function to use if no mapping is found and the choices need to be cached.
      Returns:
      An unmodifiable List of Command.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 - The CommandAutoCompleteInteractionEvent which was fired.
      choices - The List of Command.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 a List of Command.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 List of Command.Choices, or null.
      Since:
      v1.6
    • removeFromCache

      public static void removeFromCache(String commandPath, String userId, String guildId)
      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 specified CommandAutoCompleteInteractionEvent by 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 - The CommandAutoCompleteInteractionEvent which was fired.
      Returns:
      The identifier which is used in combination with the CHOICE_CACHE
      Since:
      v1.6