Record Class CommandTree

java.lang.Object
java.lang.Record
io.github.kaktushose.jdac.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 depth is 3 due to Discords limitations on SubcommandGroups.
See Also:
  • Constructor Details

    • CommandTree

      public CommandTree(Collection<SlashCommandDefinition> commands)

      Constructs a new CommandTree from the given SlashCommandDefinitions.

      The labels of the SlashCommandDefinitions 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.

    • CommandTree

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

    • getSlashCommandData

      public Collection<SlashCommandData> getSlashCommandData(LocalizationFunction localizationFunction)

      Transforms this CommandTree to SlashCommandData based on the tree structure.

      More formally, a depth-first-search is performed to determine which commands should be registered as a slash command, a sub command group or a sub command.

      Returns:
      a Collection of SlashCommandData
    • 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