Class OptionData

    • Constructor Detail

      • OptionData

        public OptionData​(@Nonnull
                          OptionType type,
                          @Nonnull
                          String name,
                          @Nonnull
                          String description)
        Create an option builder.
        This option is not required by default.
        Parameters:
        type - The OptionType
        name - The option name, 1-32 lowercase alphanumeric characters
        description - The option description, 1-100 characters
        Throws:
        IllegalArgumentException - If any of the following requirements are not met
        • The name must be lowercase alphanumeric (with dash), 1-32 characters long
        • The description must be 1-100 characters long
        • The type must not be null
      • OptionData

        public OptionData​(@Nonnull
                          OptionType type,
                          @Nonnull
                          String name,
                          @Nonnull
                          String description,
                          boolean isRequired)
        Create an option builder.
        Parameters:
        type - The OptionType
        name - The option name, 1-32 lowercase alphanumeric characters
        description - The option description, 1-100 characters
        isRequired - True, if this option is required
        Throws:
        IllegalArgumentException - If any of the following requirements are not met
        • The name must be lowercase alphanumeric (with dash), 1-32 characters long
        • The description must be 1-100 characters long
        • The type must not be null
    • Method Detail

      • getName

        @Nonnull
        public String getName()
        The name for this option
        Returns:
        The name
      • getDescription

        @Nonnull
        public String getDescription()
        The description for this option
        Returns:
        The description
      • isRequired

        public boolean isRequired()
        Whether this option is required.
        This can be configured with setRequired(boolean).

        Required options must always be set by the command invocation.

        Returns:
        True, if this option is required
      • setName

        @Nonnull
        public OptionData setName​(@Nonnull
                                  String name)
        Configure the name
        Parameters:
        name - The lowercase alphanumeric (with dash) name, 1-32 characters
        Returns:
        The OptionData instance, for chaining
        Throws:
        IllegalArgumentException - If the name is null, not alphanumeric, or not between 1-32 characters
      • setDescription

        @Nonnull
        public OptionData setDescription​(@Nonnull
                                         String description)
        Configure the description
        Parameters:
        description - The description, 1-100 characters
        Returns:
        The OptionData instance, for chaining
        Throws:
        IllegalArgumentException - If the name is null or not between 1-100 characters
      • setRequired

        @Nonnull
        public OptionData setRequired​(boolean required)
        Configure whether the user must set this option.
        Required options must always be filled out when using the command.
        Parameters:
        required - True, if this option is required
        Returns:
        The OptionData instance, for chaining
      • addChoice

        @Nonnull
        public OptionData addChoice​(@Nonnull
                                    String name,
                                    int value)
        Add a predefined choice for this option.
        The user can only provide one of the choices and cannot specify any other value.
        Parameters:
        name - The name used in the client
        value - The value received in OptionMapping
        Returns:
        The OptionData instance, for chaining
        Throws:
        IllegalArgumentException - If the name is null, empty, or longer than 100 characters. Also thrown if this is not an option of type OptionType.INTEGER or more than 25 choices are provided.
      • addChoice

        @Nonnull
        public OptionData addChoice​(@Nonnull
                                    String name,
                                    @Nonnull
                                    String value)
        Add a predefined choice for this option.
        The user can only provide one of the choices and cannot specify any other value.
        Parameters:
        name - The name used in the client
        value - The value received in OptionMapping
        Returns:
        The OptionData instance, for chaining
        Throws:
        IllegalArgumentException - If the name or value is null, empty, or longer than 100 characters. Also thrown if this is not an option of type OptionType.STRING or more than 25 choices are provided.
      • addChoices

        @Nonnull
        public OptionData addChoices​(@Nonnull
                                     Command.Choice... choices)
        Adds up to 25 predefined choices for this option.
        The user can only provide one of the choices and cannot specify any other value.
        Parameters:
        choices - The choices to add
        Returns:
        The OptionData instance, for chaining
        Throws:
        IllegalArgumentException - If any name or value is null, empty, or longer than 100 characters. Also thrown if this is not an option type is incompatible with the choice type or more than 25 choices are provided.
      • addChoices

        @Nonnull
        public OptionData addChoices​(@Nonnull
                                     Collection<? extends Command.Choice> choices)
        Adds up to 25 predefined choices for this option.
        The user can only provide one of the choices and cannot specify any other value.
        Parameters:
        choices - The choices to add
        Returns:
        The OptionData instance, for chaining
        Throws:
        IllegalArgumentException - If any name or value is null, empty, or longer than 100 characters. Also thrown if this is not an option type is incompatible with the choice type or more than 25 choices are provided.
      • fromData

        @Nonnull
        public static OptionData fromData​(@Nonnull
                                          DataObject json)
        Parses the provided serialization back into an OptionData instance.
        This is the reverse function for toData().
        Parameters:
        json - The serialized DataObject representing the option
        Returns:
        The parsed OptionData instance, which can be further configured through setters
        Throws:
        ParsingException - If the serialized object is missing required fields
        IllegalArgumentException - If any of the values are failing the respective checks such as length