Record Class CommandTree

java.lang.Object
java.lang.Record
com.github.kaktushose.jda.commands.internal.register.CommandTree

@Internal public record CommandTree(TreeNode root) extends Record
A tree data structure representing slash commands sorted into Subcommands and SubcommandGroups. Each TreeNode can have n children, however the maximum level is 3 due to Discords limitations on SubcommandGroups.
See Also:
  • Constructor Details

    • CommandTree

      public CommandTree()
      Constructs an empty CommandTree.
    • CommandTree

      public CommandTree(Collection<SlashCommandDefinition> commands)
      Constructs a new CommandTree.
    • CommandTree

      public CommandTree(TreeNode root)
      Creates an instance of a CommandTree record class.
      Parameters:
      root - the value for the root record component
  • Method Details

    • add

      public void add(SlashCommandDefinition command)
      Adds a SlashCommandDefinition to the CommandTree. The label of the SlashCommandDefinition will be sanitized to match the regex ^[\w-]+$. Furthermore, if the label consists of more than three spaces any additional space will be replaced with _ due to Discords limitations on SubcommandGroups.
      Parameters:
      command - the SlashCommandDefinition to add
    • addAll

      public void addAll(Collection<SlashCommandDefinition> commands)
      Parameters:
      commands - a Collection of SlashCommandDefinitions to add
      See Also:
    • getCommands

      public List<net.dv8tion.jda.api.interactions.commands.build.SlashCommandData> getCommands()
      Gets all SlashCommandData.This will only return the SlashCommandData of the leaf nodes.
      Returns:
      a List of SlashCommandData
    • getNames

      public List<String> getNames()
      Gets the sanitized labels of all SlashCommandData returned by getCommands(). The labels will match the regex ^[\w-]+$. Furthermore, if the label consists of more than three spaces any additional space will be replaced with _ due to Discords limitations on SubcommandGroups.
      Returns:
      a List of labels
    • toString

      public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • root

      public TreeNode root()
      Returns the value of the root record component.
      Returns:
      the value of the root record component