Interface StringParser<T extends @NonNull Object>

Type Parameters:
T - The type of argument that is provided.
All Superinterfaces:
ArgumentParser<String,T>, BiFunction<CommandContext,String,Mono<T>>, ChoicesParser<String,T>, InputParser<String,T>, ParserFunction<String,T>
All Known Subinterfaces:
ListParser<T>
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public non-sealed interface StringParser<T extends @NonNull Object> extends ChoicesParser<String,T>
Parses string-based input arguments.
Since:
1.0
Version:
1.0
API Note:
Implementations do not have to verify in parsing that the length of the received raw value is within the range specified by minLength() and maxLength(). The system will automatically do this verification before invoking the parser.
  • Field Details

    • MAX_LENGTH

      static final int MAX_LENGTH
      The maximum length possible (in the Discord API for application commands).
      See Also:
  • Method Details

    • minLength

      @Pure default @IntRange(from=0L,to=6000L) @Nullable Integer minLength()
      The minimum length allowed (inclusive).
      Returns:
      The length, or null if no minimum.
      Implementation Requirements:
      The default is null. Must be between 0 and 6000.
    • maxLength

      @Pure default @IntRange(from=1L,to=6000L) @Nullable Integer maxLength()
      The maximum length allowed (inclusive).
      Returns:
      The length, or null if no maximum.
      Implementation Requirements:
      The default is null. Must be between 1 and 6000.
    • allowMerge

      @Pure default boolean allowMerge()
      Whether to allow merge behavior when a parameter using this parser is the last parameter of the command.

      If enabled, whenever an associated parameter is the last parameter of a message-based invocation, all content in the message beyond the second-to-last argument is considered to correspond to this parameter, and is parsed as-is, rather than being tokenized like the preceding arguments.

      This behavior allows the last argument to contain delimiter characters (such as spaces) and generally maintain formatting without the user needing to surround it with quotes (particularly useful when the last parameter is a message or a list).

      One consequence of it, however, is that if the user does include quotes (out of habit, for example), they will not be stripped prior to parsing. It also disables automatic checking for extra arguments, which may cause parsing errors instead.

      If this parameter is not the last parameter, or the invocation is not through a message, this value is ignored.

      Returns:
      Whether to enable merge behavior.
      Implementation Requirements:
      The default is false.
    • verifyLength

      @Pure default String verifyLength(String raw) throws InvalidArgumentException
      Verifies that the given string is within the allowed length range for this parser.
      Parameters:
      raw - The string to validate.
      Returns:
      The given string.
      Throws:
      InvalidArgumentException - If the length is outside the allowed range.
      API Note:
      Implementations do not need to call this method.
    • validateRaw

      default String validateRaw(String raw) throws InvalidArgumentException
      Description copied from interface: ArgumentParser
      Validates the raw value before parsing.
      Specified by:
      validateRaw in interface ArgumentParser<String,T extends @NonNull Object>
      Specified by:
      validateRaw in interface ChoicesParser<String,T extends @NonNull Object>
      Parameters:
      raw - The raw value.
      Returns:
      The raw value.
      Throws:
      InvalidArgumentException - if the value is invalid.