Class Parsers
- Since:
- 1.0
- Version:
- 1.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
A parser that does not depend on the invocation context.static interface
A parser that executes synchronously and does not depend on the invocation context.static interface
A parser that executes synchronously. -
Method Summary
Modifier and TypeMethodDescriptionstatic AttachmentParser<Attachment>
Creates a parser that receives raw attachment values.static <T extends @NonNull Object>
AttachmentDataParser<T>attachment
(@org.checkerframework.common.value.qual.IntRange(from=0L) int maxSize, AttachmentParserStages.Parser<T> parser) Creates a parser that uses the given parser to parse the contents received in an attachment, with no validation performed prior to receiving attachment data (other than the size limit).static <T extends @NonNull Object>
AttachmentDataParser<T>attachment
(AttachmentParserStages.Parser<T> parser) Creates a parser that uses the given parser to parse the contents received in an attachment, with no validation performed prior to receiving attachment data, and with unbounded file size.static <T extends @NonNull Object>
AttachmentDataParser<T>attachment
(AttachmentParserStages.Validator validator, @org.checkerframework.common.value.qual.IntRange(from=0L) int maxSize, AttachmentParserStages.Parser<T> parser) Creates a parser that uses the given validator and parser to parse the contents received in an attachment.static <T extends @NonNull Object>
AttachmentParser<T>attachment
(ParserFunction<Attachment, T> parser) Creates a parser that uses the given function to parse received values.static BooleanParser<Boolean>
bool()
Creates a parser that receives plain boolean values.static <T extends @NonNull Object>
BooleanParser<T>bool
(ParserFunction<Boolean, T> parser) Creates a parser that uses the given function to parse received values.static <T extends @NonNull Object>
BooleanParser<T>bool
(T trueValue, T falseValue) Creates a parser that receives one of two values depending on the argument.static <C extends @NonNull Channel>
ChannelArgumentParser<C,C> Creates a parser that receives raw channel values.static <C extends @NonNull Channel,
T extends @NonNull Object>
ChannelArgumentParser<C,T> channel
(Class<C> type, ParserFunction<C, T> parser) Creates a parser that uses the given function to parse received values.static SnowflakeParser<Snowflake>
Creates a parser that receives channel IDs.static <T extends @NonNull Object>
SnowflakeParser<T>channelId
(ParserFunction<Snowflake, T> parser) Creates a parser that uses the given function to parse received values.static <T extends @NonNull Object>
IntegerParser<T>choiceInteger
(@MinLen(1) List<Map.Entry<ChoicesParser.Choice<Long>, T>> choices) Creates a parser that receives a value from within a set of choices.static <T extends @NonNull Object>
IntegerParser<T>choiceInteger
(Map.Entry<ChoicesParser.Choice<Long>, T> @MinLen(1) ... choices) Creates a parser that receives a value from within a set of choices.static <E extends @NonNull Enum<E>>
StringParser<E>Creates a parser that receives an enum value.static <R extends @NonNull Object,
T extends @NonNull Object>
ParserFunction<R,T> functor
(Parsers.Functor<R, T> parser) Uses a parser that does not depend on the execution context.static IntegerParser<Long>
integer()
Creates a parser that receives plain integer values.static IntegerParser<Long>
integer
(@MinLen(1) List<ChoicesParser.Choice<Long>> choices) Creates a parser that receives plain integer values from within a set of choices.static IntegerParser<Long>
integer
(ChoicesParser.Choice<Long> @MinLen(1) ... choices) Creates a parser that receives plain integer values from within a set of choices.static <T extends @NonNull Object>
IntegerParser<T>integer
(ParserFunction<Long, T> parser) Creates a parser that uses the given function to parse received values.static IntegerParser<Long>
integerAbove
(long minimum) Creates a parser that receives plain integer values, which must be at least the given value.static <T extends @NonNull Object>
IntegerParser<T>integerAbove
(long minimum, ParserFunction<Long, T> parser) Creates a parser that uses the given function to parse received values, which must be at least the given value.static IntegerParser<Long>
integerBelow
(long maximum) Creates a parser that receives plain integer values, which must be at most the given value.static <T extends @NonNull Object>
IntegerParser<T>integerBelow
(long maximum, ParserFunction<Long, T> parser) Creates a parser that uses the given function to parse received values, which must be at most the given value.static IntegerParser<Long>
integerBetween
(long minimum, long maximum) Creates a parser that receives plain integer values, which must be between the given values.static <T extends @NonNull Object>
IntegerParser<T>integerBetween
(long minimum, long maximum, ParserFunction<Long, T> parser) Creates a parser that uses the given function to parse received values, which must be between the given values.static ListParser<String>
list()
Creates a list parser with string items.static ListParser<String>
list
(@org.checkerframework.common.value.qual.IntRange(from=0L, to=2147483647L) int minItems, @org.checkerframework.common.value.qual.IntRange(from=1L, to=2147483647L) int maxItems) Creates a list parser with string items.static <T extends @NonNull Object>
ListParser<T>list
(ParserFunction<String, T> parser) Creates a list parser that uses the given function to parse items.static <T extends @NonNull Object>
ListParser<T>list
(ParserFunction<String, T> parser, @org.checkerframework.common.value.qual.IntRange(from=0L, to=2147483647L) int minItems, @org.checkerframework.common.value.qual.IntRange(from=1L, to=2147483647L) int maxItems) Creates a list parser that uses the given function to parse items.static MessageArgumentParser<Message>
message()
Creates a parser that receives raw message values.static <T extends @NonNull Object>
MessageArgumentParser<T>message
(ParserFunction<Message, T> parser) Creates a parser that uses the given function to parse received values.static <R extends @NonNull Object>
ParserFunction<R,R> nullValue
(R value) Creates a parser that returns an empty result for the given value, otherwise resulting in the raw value.static <R extends @NonNull Object,
T extends @NonNull Object>
ParserFunction<R,T> nullValue
(R value, ParserFunction<R, T> parser) Creates a parser that returns an empty result for the given value, otherwise deferring to the given parser.static <R extends @NonNull Object>
ParserFunction<R,R> nullValues
(Collection<? extends R> values) Creates a parser that returns an empty result for the given values, otherwise resulting in the raw value.static <R extends @NonNull Object,
T extends @NonNull Object>
ParserFunction<R,T> nullValues
(Collection<? extends R> values, ParserFunction<R, T> parser) Creates a parser that returns an empty result for the given values, otherwise deferring to the given parser.static FloatParser<Double>
number()
Creates a parser that receives plain floating-point values.static FloatParser<Double>
number
(@MinLen(1) List<ChoicesParser.Choice<Double>> choices) Creates a parser that receives plain floating-point values from within a set of choices.static FloatParser<Double>
number
(ChoicesParser.Choice<Double> @MinLen(1) ... choices) Creates a parser that receives plain floating-point values from within a set of choices.static <T extends @NonNull Object>
FloatParser<T>number
(ParserFunction<Double, T> parser) Creates a parser that uses the given function to parse received values.static FloatParser<Double>
numberAbove
(double minimum) Creates a parser that receives plain floating-point values, which must be at least the given value.static <T extends @NonNull Object>
FloatParser<T>numberAbove
(double minimum, ParserFunction<Double, T> parser) Creates a parser that uses the given function to parse received values, which must be at least the given value.static FloatParser<Double>
numberBelow
(double maximum) Creates a parser that receives plain floating-point values, which must be at most the given value.static <T extends @NonNull Object>
FloatParser<T>numberBelow
(double maximum, ParserFunction<Double, T> parser) Creates a parser that uses the given function to parse received values, which must be at most the given value.static FloatParser<Double>
numberBetween
(double minimum, double maximum) Creates a parser that receives plain floating-point values, which must be between the given values.static <T extends @NonNull Object>
FloatParser<T>numberBetween
(double minimum, double maximum, ParserFunction<Double, T> parser) Creates a parser that uses the given function to parse received values, which must be between the given values.static <T extends @NonNull Object>
FloatParser<T>numberChoice
(@MinLen(1) List<Map.Entry<ChoicesParser.Choice<Double>, T>> choices) Creates a parser that receives a value from within a set of choices.static <T extends @NonNull Object>
FloatParser<T>numberChoice
(Map.Entry<ChoicesParser.Choice<Double>, T> @MinLen(1) ... choices) Creates a parser that receives a value from within a set of choices.raw
(CommandContext context, R raw) Returns the raw value received.static RoleArgumentParser<Role>
role()
Creates a parser that receives raw role values.static <T extends @NonNull Object>
RoleArgumentParser<T>role
(ParserFunction<Role, T> parser) Creates a parser that uses the given function to parse received values.static SnowflakeParser<Snowflake>
roleId()
Creates a parser that receives role IDs.static <T extends @NonNull Object>
SnowflakeParser<T>roleId
(ParserFunction<Snowflake, T> parser) Creates a parser that uses the given function to parse received values.static <R extends @NonNull Object,
T extends @NonNull Object>
ParserFunction<R,T> simple
(Parsers.Simple<R, T> parser) Uses a parser that executes synchronously and does not depend on the execution context.static SnowflakeParser<Snowflake>
Creates a parser that receives snowflake IDs.static <T extends @NonNull Object>
SnowflakeParser<T>snowflake
(ParserFunction<Snowflake, T> parser) Creates a parser that uses the given function to parse received values.static StringParser<String>
string()
Creates a parser that receives plain string values.static StringParser<String>
string
(@Nullable @IntRange(from=0L,to=6000L) Integer minLength, @Nullable @IntRange(from=1L,to=6000L) Integer maxLength) Creates a parser that receives plain string values.static StringParser<String>
string
(@MinLen(1) List<ChoicesParser.Choice<String>> choices) Creates a parser that receives plain string values from within a set of choices.static StringParser<String>
string
(ChoicesParser.Choice<String> @MinLen(1) ... choices) Creates a parser that receives plain string values from within a set of choices.static <T extends @NonNull Object>
StringParser<T>string
(ParserFunction<String, T> parser) Creates a parser that uses the given function to parse received values.static <T extends @NonNull Object>
StringParser<T>string
(ParserFunction<String, T> parser, @Nullable @IntRange(from=0L,to=6000L) Integer minLength, @Nullable @IntRange(from=1L,to=6000L) Integer maxLength) Creates a parser that uses the given function to parse received values.static <T extends @NonNull Object>
StringParser<T>stringChoice
(@MinLen(1) List<Map.Entry<ChoicesParser.Choice<String>, T>> choices) Creates a parser that receives a value from within a set of choices.static <T extends @NonNull Object>
StringParser<T>stringChoice
(Map.Entry<ChoicesParser.Choice<String>, T> @MinLen(1) ... choices) Creates a parser that receives a value from within a set of choices.static <R extends @NonNull Object,
T extends @NonNull Object>
ParserFunction<R,T> sync
(Parsers.Synchronous<R, T> parser) Uses a parser that executes synchronously.static StringParser<String>
text()
Creates a parser that receives plain string values.static StringParser<String>
text
(@Nullable @IntRange(from=0L,to=6000L) Integer minLength, @Nullable @IntRange(from=1L,to=6000L) Integer maxLength) Creates a parser that receives plain string values.static <T extends @NonNull Object>
StringParser<T>text
(ParserFunction<String, T> parser) Creates a parser that uses the given function to parse received values.static <T extends @NonNull Object>
StringParser<T>text
(ParserFunction<String, T> parser, @Nullable @IntRange(from=0L,to=6000L) Integer minLength, @Nullable @IntRange(from=1L,to=6000L) Integer maxLength) Creates a parser that uses the given function to parse received values.static TextFileParser<String>
textFile()
Creates a parser that receives the plain contents of a text file, with unbounded file size.static TextFileParser<String>
textFile
(@org.checkerframework.common.value.qual.IntRange(from=0L) int maxSize) Creates a parser that receives the plain contents of a text file.static <T extends @NonNull Object>
TextFileParser<T>textFile
(@org.checkerframework.common.value.qual.IntRange(from=0L) int maxSize, ParserFunction<String, T> parser) Creates a parser that uses the given parser to parse the contents received in a text file.static <T extends @NonNull Object>
TextFileParser<T>textFile
(ParserFunction<String, T> parser) Creates a parser that uses the given parser to parse the contents received in a text file, with unbounded file size.static UserArgumentParser<User>
user()
Creates a parser that receives raw user values.static <T extends @NonNull Object>
UserArgumentParser<T>user
(ParserFunction<User, T> parser) Creates a parser that uses the given function to parse received values.static SnowflakeParser<Snowflake>
userId()
Creates a parser that receives user IDs.static <T extends @NonNull Object>
SnowflakeParser<T>userId
(ParserFunction<Snowflake, T> parser) Creates a parser that uses the given function to parse received values.
-
Method Details
-
raw
@SideEffectFree public static <R extends @NonNull Object> Mono<R> raw(CommandContext context, R raw) Returns the raw value received.- Type Parameters:
R
- The raw type.- Parameters:
context
- The context.raw
- The raw value.- Returns:
- A mono that issues the raw value.
- API Note:
- This method may be used as a
ParserFunction
using a method reference.
-
functor
@Pure public static <R extends @NonNull Object,T extends @NonNull Object> ParserFunction<R,T> functor(Parsers.Functor<R, T> parser) Uses a parser that does not depend on the execution context.- Type Parameters:
R
- The raw type received.T
- The parsed argument type.- Parameters:
parser
- The parserto use.- Returns:
- The parser.
- API Note:
- This is a convenience for adapting functions that do not quite match the interface.
-
sync
@Pure public static <R extends @NonNull Object,T extends @NonNull Object> ParserFunction<R,T> sync(Parsers.Synchronous<R, T> parser) Uses a parser that executes synchronously.- Type Parameters:
R
- The raw type received.T
- The parsed argument type.- Parameters:
parser
- The parser to use.- Returns:
- The parser.
- API Note:
- This is a convenience for adapting functions that do not quite match the interface.
-
simple
@Pure public static <R extends @NonNull Object,T extends @NonNull Object> ParserFunction<R,T> simple(Parsers.Simple<R, T> parser) Uses a parser that executes synchronously and does not depend on the execution context.- Type Parameters:
R
- The raw type received.T
- The parsed argument type.- Parameters:
parser
- The parser to use.- Returns:
- The parser.
- API Note:
- This is a convenience for adapting functions that do not quite match the interface.
-
nullValue
@SideEffectFree public static <R extends @NonNull Object,T extends @NonNull Object> ParserFunction<R,T> nullValue(R value, ParserFunction<R, T> parser) Creates a parser that returns an empty result for the given value, otherwise deferring to the given parser.- Type Parameters:
R
- The raw type received.T
- The parsed argument type.- Parameters:
value
- The raw value that should cause an empty result.parser
- The parser to delegate to otherwise.- Returns:
- The created parser.
-
nullValue
Creates a parser that returns an empty result for the given value, otherwise resulting in the raw value.- Type Parameters:
R
- The raw type received.- Parameters:
value
- The raw value that should cause an empty result.- Returns:
- The created parser.
-
nullValues
@SideEffectFree public static <R extends @NonNull Object,T extends @NonNull Object> ParserFunction<R,T> nullValues(Collection<? extends R> values, ParserFunction<R, T> parser) Creates a parser that returns an empty result for the given values, otherwise deferring to the given parser.- Type Parameters:
R
- The raw type received.T
- The parsed argument type.- Parameters:
values
- The raw values that should cause an empty result.parser
- The parser to delegate to otherwise.- Returns:
- The created parser.
- Implementation Note:
- The created parser uses
Collection.contains(Object)
, so prefer using collections with fast lookup times (like Set) when possible.
-
nullValues
@SideEffectFree public static <R extends @NonNull Object> ParserFunction<R,R> nullValues(Collection<? extends R> values) Creates a parser that returns an empty result for the given values, otherwise resulting in the raw value.- Type Parameters:
R
- The raw type received.- Parameters:
values
- The raw value that should cause an empty result.- Returns:
- The created parser.
- Implementation Note:
- The created parser uses
Collection.contains(Object)
, so prefer using collections with fast lookup times (like Set) when possible.
-
bool
Creates a parser that receives plain boolean values.- Returns:
- The parser.
-
bool
@SideEffectFree public static <T extends @NonNull Object> BooleanParser<T> bool(T trueValue, T falseValue) Creates a parser that receives one of two values depending on the argument.- Type Parameters:
T
- The parsed argument type.- Parameters:
trueValue
- The value to receive if the argument istrue
.falseValue
- The value to receive if the argument isfalse
.- Returns:
- The parser.
-
bool
@SideEffectFree public static <T extends @NonNull Object> BooleanParser<T> bool(ParserFunction<Boolean, T> parser) Creates a parser that uses the given function to parse received values.- Type Parameters:
T
- The parsed argument type.- Parameters:
parser
- The parser to use.- Returns:
- The parser.
-
integer
Creates a parser that receives plain integer values.- Returns:
- The parser.
-
integer
@SideEffectFree public static <T extends @NonNull Object> IntegerParser<T> integer(ParserFunction<Long, T> parser) Creates a parser that uses the given function to parse received values.- Type Parameters:
T
- The parsed argument type.- Parameters:
parser
- The parser to use.- Returns:
- The parser.
-
integer
@SideEffectFree public static IntegerParser<Long> integer(@MinLen(1) List<ChoicesParser.Choice<Long>> choices) throws IllegalArgumentException Creates a parser that receives plain integer values from within a set of choices.- Parameters:
choices
- The allowed values.- Returns:
- The parser.
- Throws:
IllegalArgumentException
- if the choice list is empty.
-
integer
@SideEffectFree @SafeVarargs public static IntegerParser<Long> integer(ChoicesParser.Choice<Long> @MinLen(1) ... choices) throws IllegalArgumentException Creates a parser that receives plain integer values from within a set of choices.- Parameters:
choices
- The allowed values.- Returns:
- The parser.
- Throws:
IllegalArgumentException
- if the choice list is empty.
-
choiceInteger
@SideEffectFree public static <T extends @NonNull Object> IntegerParser<T> choiceInteger(@MinLen(1) List<Map.Entry<ChoicesParser.Choice<Long>, T>> choices) throws IllegalArgumentExceptionCreates a parser that receives a value from within a set of choices.- Type Parameters:
T
- The parsed argument type.- Parameters:
choices
- The choices.- Returns:
- The parser.
- Throws:
IllegalArgumentException
- if the choice list is empty.
-
choiceInteger
@SideEffectFree @SafeVarargs public static <T extends @NonNull Object> IntegerParser<T> choiceInteger(Map.Entry<ChoicesParser.Choice<Long>, T> @MinLen(1) ... choices) throws IllegalArgumentExceptionCreates a parser that receives a value from within a set of choices.- Type Parameters:
T
- The parsed argument type.- Parameters:
choices
- The choices.- Returns:
- The parser.
- Throws:
IllegalArgumentException
- if the choice list is empty.
-
integerAbove
Creates a parser that receives plain integer values, which must be at least the given value.- Parameters:
minimum
- The minimum value allowed (inclusive).- Returns:
- The parser.
-
integerAbove
@SideEffectFree public static <T extends @NonNull Object> IntegerParser<T> integerAbove(long minimum, ParserFunction<Long, T> parser) Creates a parser that uses the given function to parse received values, which must be at least the given value.- Type Parameters:
T
- The parsed argument type.- Parameters:
minimum
- The minimum value allowed (inclusive).parser
- The parser to use.- Returns:
- The parser.
-
integerBelow
Creates a parser that receives plain integer values, which must be at most the given value.- Parameters:
maximum
- The maximum value allowed (inclusive).- Returns:
- The parser.
-
integerBelow
@SideEffectFree public static <T extends @NonNull Object> IntegerParser<T> integerBelow(long maximum, ParserFunction<Long, T> parser) Creates a parser that uses the given function to parse received values, which must be at most the given value.- Type Parameters:
T
- The parsed argument type.- Parameters:
maximum
- The maximum value allowed (inclusive).parser
- The parser to use.- Returns:
- The parser.
-
integerBetween
Creates a parser that receives plain integer values, which must be between the given values.- Parameters:
minimum
- The minimum value allowed (inclusive).maximum
- The maximum value allowed (inclusive).- Returns:
- The parser.
-
integerBetween
@SideEffectFree public static <T extends @NonNull Object> IntegerParser<T> integerBetween(long minimum, long maximum, ParserFunction<Long, T> parser) Creates a parser that uses the given function to parse received values, which must be between the given values.- Type Parameters:
T
- The parsed argument type.- Parameters:
minimum
- The minimum value allowed (inclusive).maximum
- The maximum value allowed (inclusive).parser
- The parser to use.- Returns:
- The parser.
-
number
Creates a parser that receives plain floating-point values.- Returns:
- The parser.
-
number
@SideEffectFree public static <T extends @NonNull Object> FloatParser<T> number(ParserFunction<Double, T> parser) Creates a parser that uses the given function to parse received values.- Type Parameters:
T
- The parsed argument type.- Parameters:
parser
- The parser to use.- Returns:
- The parser.
-
number
@SideEffectFree public static FloatParser<Double> number(@MinLen(1) List<ChoicesParser.Choice<Double>> choices) throws IllegalArgumentException Creates a parser that receives plain floating-point values from within a set of choices.- Parameters:
choices
- The allowed values.- Returns:
- The parser.
- Throws:
IllegalArgumentException
- if the choice list is empty.
-
number
@SideEffectFree @SafeVarargs public static FloatParser<Double> number(ChoicesParser.Choice<Double> @MinLen(1) ... choices) throws IllegalArgumentException Creates a parser that receives plain floating-point values from within a set of choices.- Parameters:
choices
- The allowed values.- Returns:
- The parser.
- Throws:
IllegalArgumentException
- if the choice list is empty.
-
numberChoice
@SideEffectFree public static <T extends @NonNull Object> FloatParser<T> numberChoice(@MinLen(1) List<Map.Entry<ChoicesParser.Choice<Double>, T>> choices) throws IllegalArgumentExceptionCreates a parser that receives a value from within a set of choices.- Type Parameters:
T
- The parsed argument type.- Parameters:
choices
- The choices.- Returns:
- The parser.
- Throws:
IllegalArgumentException
- if the choice list is empty.
-
numberChoice
@SideEffectFree @SafeVarargs public static <T extends @NonNull Object> FloatParser<T> numberChoice(Map.Entry<ChoicesParser.Choice<Double>, T> @MinLen(1) ... choices) throws IllegalArgumentExceptionCreates a parser that receives a value from within a set of choices.- Type Parameters:
T
- The parsed argument type.- Parameters:
choices
- The choices.- Returns:
- The parser.
- Throws:
IllegalArgumentException
- if the choice list is empty.
-
numberAbove
Creates a parser that receives plain floating-point values, which must be at least the given value.- Parameters:
minimum
- The minimum value allowed (inclusive).- Returns:
- The parser.
-
numberAbove
@SideEffectFree public static <T extends @NonNull Object> FloatParser<T> numberAbove(double minimum, ParserFunction<Double, T> parser) Creates a parser that uses the given function to parse received values, which must be at least the given value.- Type Parameters:
T
- The parsed argument type.- Parameters:
minimum
- The minimum value allowed (inclusive).parser
- The parser to use.- Returns:
- The parser.
-
numberBelow
Creates a parser that receives plain floating-point values, which must be at most the given value.- Parameters:
maximum
- The maximum value allowed (inclusive).- Returns:
- The parser.
-
numberBelow
@SideEffectFree public static <T extends @NonNull Object> FloatParser<T> numberBelow(double maximum, ParserFunction<Double, T> parser) Creates a parser that uses the given function to parse received values, which must be at most the given value.- Type Parameters:
T
- The parsed argument type.- Parameters:
maximum
- The maximum value allowed (inclusive).parser
- The parser to use.- Returns:
- The parser.
-
numberBetween
Creates a parser that receives plain floating-point values, which must be between the given values.- Parameters:
minimum
- The minimum value allowed (inclusive).maximum
- The maximum value allowed (inclusive).- Returns:
- The parser.
-
numberBetween
@SideEffectFree public static <T extends @NonNull Object> FloatParser<T> numberBetween(double minimum, double maximum, ParserFunction<Double, T> parser) Creates a parser that uses the given function to parse received values, which must be between the given values.- Type Parameters:
T
- The parsed argument type.- Parameters:
minimum
- The minimum value allowed (inclusive).maximum
- The maximum value allowed (inclusive).parser
- The parser to use.- Returns:
- The parser.
-
string
Creates a parser that receives plain string values.- Returns:
- The parser.
-
string
@SideEffectFree public static StringParser<String> string(@Nullable @IntRange(from=0L,to=6000L) Integer minLength, @Nullable @IntRange(from=1L,to=6000L) Integer maxLength) Creates a parser that receives plain string values.- Parameters:
minLength
- The minimum allowed length, ornull
if none.maxLength
- The maximum allowed length, ornull
if none.- Returns:
- The parser.
-
string
@SideEffectFree public static <T extends @NonNull Object> StringParser<T> string(ParserFunction<String, T> parser) Creates a parser that uses the given function to parse received values.- Type Parameters:
T
- The parsed argument type.- Parameters:
parser
- The parser to use.- Returns:
- The parser.
-
string
@SideEffectFree public static <T extends @NonNull Object> StringParser<T> string(ParserFunction<String, T> parser, @Nullable @IntRange(from=0L,to=6000L) Integer minLength, @Nullable @IntRange(from=1L,to=6000L) Integer maxLength) Creates a parser that uses the given function to parse received values.- Type Parameters:
T
- The parsed argument type.- Parameters:
parser
- The parser to use.minLength
- The minimum allowed length, ornull
if none.maxLength
- The maximum allowed length, ornull
if none.- Returns:
- The parser.
-
string
@SideEffectFree public static StringParser<String> string(@MinLen(1) List<ChoicesParser.Choice<String>> choices) throws IllegalArgumentException Creates a parser that receives plain string values from within a set of choices.- Parameters:
choices
- The allowed values.- Returns:
- The parser.
- Throws:
IllegalArgumentException
- if the choice list is empty.
-
string
@SideEffectFree @SafeVarargs public static StringParser<String> string(ChoicesParser.Choice<String> @MinLen(1) ... choices) throws IllegalArgumentException Creates a parser that receives plain string values from within a set of choices.- Parameters:
choices
- The allowed values.- Returns:
- The parser.
- Throws:
IllegalArgumentException
- if the choice list is empty.
-
stringChoice
@SideEffectFree public static <T extends @NonNull Object> StringParser<T> stringChoice(@MinLen(1) List<Map.Entry<ChoicesParser.Choice<String>, T>> choices) throws IllegalArgumentExceptionCreates a parser that receives a value from within a set of choices.- Type Parameters:
T
- The parsed argument type.- Parameters:
choices
- The choices.- Returns:
- The parser.
- Throws:
IllegalArgumentException
- if the choice list is empty.
-
stringChoice
@SideEffectFree @SafeVarargs public static <T extends @NonNull Object> StringParser<T> stringChoice(Map.Entry<ChoicesParser.Choice<String>, T> @MinLen(1) ... choices) throws IllegalArgumentExceptionCreates a parser that receives a value from within a set of choices.- Type Parameters:
T
- The parsed argument type.- Parameters:
choices
- The choices.- Returns:
- The parser.
- Throws:
IllegalArgumentException
- if the choice list is empty.
-
enums
public static <E extends @NonNull Enum<E>> StringParser<E> enums(Class<E> enumClass) throws IllegalArgumentException Creates a parser that receives an enum value.The enum constants are converted into a choice by calling
String.toLowerCase()
on theirname
, with the corresponding choice name being the value returned byEnum.toString()
.Note that, due to Discord's limit on choice values, this method only accepts enums that have at most 25 values. If looking to parse an enum with more values, use a regular
string parser
.- Type Parameters:
E
- The enum type.- Parameters:
enumClass
- The enum class.- Returns:
- The parser.
- Throws:
IllegalArgumentException
- if the given enum type has no values or more values than allowed by Discord on choice parameters (25).
-
text
Creates a parser that receives plain string values.- Returns:
- The parser.
- See Also:
-
text
@SideEffectFree public static StringParser<String> text(@Nullable @IntRange(from=0L,to=6000L) Integer minLength, @Nullable @IntRange(from=1L,to=6000L) Integer maxLength) Creates a parser that receives plain string values.Unlike the
string(Integer, Integer)
variant, this parser allowsmerging
.- Parameters:
minLength
- The minimum allowed length, ornull
if none.maxLength
- The maximum allowed length, ornull
if none.- Returns:
- The parser.
- See Also:
-
text
@SideEffectFree public static <T extends @NonNull Object> StringParser<T> text(ParserFunction<String, T> parser) Creates a parser that uses the given function to parse received values.Unlike the
string(ParserFunction)
variant, this parser allowsmerging
.- Type Parameters:
T
- The parsed argument type.- Parameters:
parser
- The parser to use.- Returns:
- The parser.
- See Also:
-
text
@SideEffectFree public static <T extends @NonNull Object> StringParser<T> text(ParserFunction<String, T> parser, @Nullable @IntRange(from=0L,to=6000L) Integer minLength, @Nullable @IntRange(from=1L,to=6000L) Integer maxLength) Creates a parser that uses the given function to parse received values.Unlike the
string(ParserFunction, Integer, Integer)
variant, this parser allowsmerging
.- Type Parameters:
T
- The parsed argument type.- Parameters:
parser
- The parser to use.minLength
- The minimum allowed length, ornull
if none.maxLength
- The maximum allowed length, ornull
if none.- Returns:
- The parser.
- See Also:
-
attachment
Creates a parser that receives raw attachment values.- Returns:
- The parser.
-
attachment
@SideEffectFree public static <T extends @NonNull Object> AttachmentParser<T> attachment(ParserFunction<Attachment, T> parser) Creates a parser that uses the given function to parse received values.- Type Parameters:
T
- The parsed argument type.- Parameters:
parser
- The parser to use.- Returns:
- The parser.
-
attachment
@SideEffectFree public static <T extends @NonNull Object> AttachmentDataParser<T> attachment(AttachmentParserStages.Validator validator, @org.checkerframework.common.value.qual.IntRange(from=0L) int maxSize, AttachmentParserStages.Parser<T> parser) throws IllegalArgumentException Creates a parser that uses the given validator and parser to parse the contents received in an attachment.- Type Parameters:
T
- The parsed argument type.- Parameters:
validator
- The validator to use.maxSize
- The maximum file size allowed, in bytes.parser
- The parser to use.- Returns:
- The parser.
- Throws:
IllegalArgumentException
- if the size is negative.- API Note:
- Validation is applied before fetching the attachment data.
-
attachment
@SideEffectFree public static <T extends @NonNull Object> AttachmentDataParser<T> attachment(@org.checkerframework.common.value.qual.IntRange(from=0L) int maxSize, AttachmentParserStages.Parser<T> parser) Creates a parser that uses the given parser to parse the contents received in an attachment, with no validation performed prior to receiving attachment data (other than the size limit).- Type Parameters:
T
- The parsed argument type.- Parameters:
maxSize
- The maximum file size allowed, in bytes.parser
- The parser to use.- Returns:
- The parser.
-
attachment
@SideEffectFree public static <T extends @NonNull Object> AttachmentDataParser<T> attachment(AttachmentParserStages.Parser<T> parser) Creates a parser that uses the given parser to parse the contents received in an attachment, with no validation performed prior to receiving attachment data, and with unbounded file size.- Type Parameters:
T
- The parsed argument type.- Parameters:
parser
- The parser to use.- Returns:
- The parser.
-
textFile
@SideEffectFree public static <T extends @NonNull Object> TextFileParser<T> textFile(@org.checkerframework.common.value.qual.IntRange(from=0L) int maxSize, ParserFunction<String, T> parser) Creates a parser that uses the given parser to parse the contents received in a text file.- Type Parameters:
T
- The parsed argument type.- Parameters:
maxSize
- The maximum file size allowed, in bytes.parser
- The parser to use.- Returns:
- The parser.
-
textFile
@SideEffectFree public static <T extends @NonNull Object> TextFileParser<T> textFile(ParserFunction<String, T> parser) Creates a parser that uses the given parser to parse the contents received in a text file, with unbounded file size.- Type Parameters:
T
- The parsed argument type.- Parameters:
parser
- The parser to use.- Returns:
- The parser.
-
textFile
@SideEffectFree public static TextFileParser<String> textFile(@org.checkerframework.common.value.qual.IntRange(from=0L) int maxSize) Creates a parser that receives the plain contents of a text file.- Parameters:
maxSize
- The maximum file size allowed, in bytes.- Returns:
- The parser.
-
textFile
Creates a parser that receives the plain contents of a text file, with unbounded file size.- Returns:
- The parser.
-
snowflake
@SideEffectFree public static <T extends @NonNull Object> SnowflakeParser<T> snowflake(ParserFunction<Snowflake, T> parser) Creates a parser that uses the given function to parse received values.Note that validation is performed other than that the value is a properly formatted snowflake ID, and for interaction commands it will appear as a string parameter.
- Type Parameters:
T
- The parsed argument type.- Parameters:
parser
- The parser to use.- Returns:
- The parser.
-
snowflake
Creates a parser that receives snowflake IDs.Note that validation is performed other than that the value is a properly formatted snowflake ID, and for interaction commands it will appear as a string parameter. That makes it functionally identical to
string(ParserFunction)
with a parser function ofSnowflake.of(String)
.- Returns:
- The parser.
-
userId
@SideEffectFree public static <T extends @NonNull Object> SnowflakeParser<T> userId(ParserFunction<Snowflake, T> parser) Creates a parser that uses the given function to parse received values.Note that this parser does not itself perform any validation on whether the snowflake received is a valid user ID. It is useful only for hybrid commands (text and interaction) to have a user-type argument (which is fully received with the interaction) without making the text case fetch the entire user (which is an additional request in text commands) when just the ID is necessary.
If validation is necessary and text-command performance is not a concern use
user()
.- Type Parameters:
T
- The parsed argument type.- Parameters:
parser
- The parser to use.- Returns:
- The parser.
-
userId
Creates a parser that receives user IDs.Note that this parser does not itself perform any validation on whether the snowflake received is a valid user ID. It is useful only for hybrid commands (text and interaction) to have a user-type argument (which is fully received with the interaction) without making the text case fetch the entire user (which is an additional request in text commands) when just the ID is necessary.
If validation is necessary and text-command performance is not a concern use
user()
.- Returns:
- The parser.
-
roleId
@SideEffectFree public static <T extends @NonNull Object> SnowflakeParser<T> roleId(ParserFunction<Snowflake, T> parser) Creates a parser that uses the given function to parse received values.Note that this parser does not itself perform any validation on whether the snowflake received is a valid role ID. It is useful only for hybrid commands (text and interaction) to have a role-type argument (which is fully received with the interaction) without making the text case fetch the entire role (which is an additional request in text commands) when just the ID is necessary.
If validation is necessary and text-command performance is not a concern use
role()
.- Type Parameters:
T
- The parsed argument type.- Parameters:
parser
- The parser to use.- Returns:
- The parser.
-
roleId
Creates a parser that receives role IDs.Note that this parser does not itself perform any validation on whether the snowflake received is a valid role ID. It is useful only for hybrid commands (text and interaction) to have a role-type argument (which is fully received with the interaction) without making the text case fetch the entire role (which is an additional request in text commands) when just the ID is necessary.
If validation is necessary and text-command performance is not a concern use
role()
.- Returns:
- The parser.
-
channelId
@SideEffectFree public static <T extends @NonNull Object> SnowflakeParser<T> channelId(ParserFunction<Snowflake, T> parser) Creates a parser that uses the given function to parse received values.Note that this parser does not itself perform any validation on whether the snowflake received is a valid channel ID. It is useful only for hybrid commands (text and interaction) to have a channel-type argument (which is fully received with the interaction) without making the text case fetch the entire channel (which is an additional request in text commands) when just the ID is necessary.
If validation is necessary and text-command performance is not a concern use
channel(Class)
.- Type Parameters:
T
- The parsed argument type.- Parameters:
parser
- The parser to use.- Returns:
- The parser.
-
channelId
Creates a parser that receives channel IDs.Note that this parser does not itself perform any validation on whether the snowflake received is a valid channel ID. It is useful only for hybrid commands (text and interaction) to have a channel-type argument (which is fully received with the interaction) without making the text case fetch the entire channel (which is an additional request in text commands) when just the ID is necessary.
If validation is necessary and text-command performance is not a concern use
channel(Class)
.- Returns:
- The parser.
-
user
Creates a parser that receives raw user values.- Returns:
- The parser.
-
user
@SideEffectFree public static <T extends @NonNull Object> UserArgumentParser<T> user(ParserFunction<User, T> parser) Creates a parser that uses the given function to parse received values.- Type Parameters:
T
- The parsed argument type.- Parameters:
parser
- The parser to use.- Returns:
- The parser.
-
role
Creates a parser that receives raw role values.- Returns:
- The parser.
-
role
@SideEffectFree public static <T extends @NonNull Object> RoleArgumentParser<T> role(ParserFunction<Role, T> parser) Creates a parser that uses the given function to parse received values.- Type Parameters:
T
- The parsed argument type.- Parameters:
parser
- The parser to use.- Returns:
- The parser.
-
message
Creates a parser that receives raw message values.- Returns:
- The parser.
-
message
@SideEffectFree public static <T extends @NonNull Object> MessageArgumentParser<T> message(ParserFunction<Message, T> parser) Creates a parser that uses the given function to parse received values.- Type Parameters:
T
- The parsed argument type.- Parameters:
parser
- The parser to use.- Returns:
- The parser.
-
channel
@SideEffectFree public static <C extends @NonNull Channel> ChannelArgumentParser<C,C> channel(Class<C> type) Creates a parser that receives raw channel values.- Type Parameters:
C
- The channel type.- Parameters:
type
- The channel type.- Returns:
- The parser.
-
channel
@SideEffectFree public static <C extends @NonNull Channel,T extends @NonNull Object> ChannelArgumentParser<C,T> channel(Class<C> type, ParserFunction<C, T> parser) Creates a parser that uses the given function to parse received values.- Type Parameters:
C
- The channel type.T
- The parsed argument type.- Parameters:
type
- The channel type.parser
- The parser to use.- Returns:
- The parser.
-
list
Creates a list parser with string items.- Returns:
- The parser.
-
list
@SideEffectFree public static ListParser<String> list(@org.checkerframework.common.value.qual.IntRange(from=0L, to=2147483647L) int minItems, @org.checkerframework.common.value.qual.IntRange(from=1L, to=2147483647L) int maxItems) Creates a list parser with string items.- Parameters:
minItems
- The minimum number of items allowed. Note that, when setting to 0, it is recommended to set the associated parameter to be non-required with an empty list as default value. SeeListParser.minItems()
for details.maxItems
- The maximum number of items allowed.- Returns:
- The parser.
-
list
@SideEffectFree public static <T extends @NonNull Object> ListParser<T> list(ParserFunction<String, T> parser) Creates a list parser that uses the given function to parse items.- Type Parameters:
T
- The item type.- Parameters:
parser
- The parser to use.- Returns:
- The parser.
-
list
@SideEffectFree public static <T extends @NonNull Object> ListParser<T> list(ParserFunction<String, T> parser, @org.checkerframework.common.value.qual.IntRange(from=0L, to=2147483647L) int minItems, @org.checkerframework.common.value.qual.IntRange(from=1L, to=2147483647L) int maxItems) Creates a list parser that uses the given function to parse items.- Type Parameters:
T
- The item type.- Parameters:
parser
- The parser to use.minItems
- The minimum number of items allowed. Note that, when setting to 0, it is recommended to set the associated parameter to be non-required with an empty list as default value. SeeListParser.minItems()
for details.maxItems
- The maximum number of items allowed.- Returns:
- The parser.
-