- Type Parameters:
T
- The type of argument that is provided.R
- The type of raw argument that is received.
- All Superinterfaces:
BiFunction<CommandContext,
,R, Mono<T>> ParserFunction<R,
T>
- All Known Subinterfaces:
AttachmentDataParser<T>
,AttachmentParser<T>
,BooleanParser<T>
,ChannelArgumentParser<C,
,T> ChoicesParser<P,
,T> EntityArgumentParser<E,
,T> FloatParser<T>
,InputParser<P,
,T> IntegerParser<T>
,ListParser<T>
,MessageArgumentParser<T>
,NumberParser<P,
,T> RoleArgumentParser<T>
,SnowflakeParser<T>
,StringParser<T>
,TextFileParser<T>
,UserArgumentParser<T>
public sealed interface ArgumentParser<R extends @NonNull Object,T extends @NonNull Object>
extends ParserFunction<R,T>
permits AttachmentParser<T>, InputParser<P,T>
Parses received arguments into their actual value.
- Since:
- 1.0
- Version:
- 1.0
-
Nested Class Summary
Nested classes/interfaces inherited from interface dev.sympho.modular_commands.api.command.parameter.parse.ParserFunction
ParserFunction.PostParser<R extends @NonNull Object,
I extends @NonNull Object, T extends @NonNull Object, P1 extends @NonNull ParserFunction<R, I>, P2 extends @NonNull ParserFunction<I, T>> -
Method Summary
Modifier and TypeMethodDescriptionparse
(CommandContext context, R raw) Parses the given raw argument from the user into the corresponding value.parseArgument
(CommandContext context, R raw) Parses the given raw argument from the user into the corresponding value.default R
validateRaw
(R raw) Validates the raw value before parsing.Methods inherited from interface java.util.function.BiFunction
andThen
Methods inherited from interface dev.sympho.modular_commands.api.command.parameter.parse.ParserFunction
apply, then
-
Method Details
-
validateRaw
Validates the raw value before parsing.- Parameters:
raw
- The raw value.- Returns:
- The raw value.
- Throws:
InvalidArgumentException
- if the value is invalid.- API Note:
- This method is used to provide built-in validation in text-commands that would
be done by Discord's servers in slash commands. Client code should place any
custom validation in
parseArgument(CommandContext, Object)
.
-
parseArgument
@SideEffectFree Mono<T> parseArgument(CommandContext context, R raw) throws InvalidArgumentException Parses the given raw argument from the user into the corresponding value.- Parameters:
context
- The execution context.raw
- The raw argument received from the user.- Returns:
- A Mono that issues the parsed argument. If the raw value is invalid, it may
fail with a
InvalidArgumentException
. - Throws:
InvalidArgumentException
- if the given argument is not a valid value.
-
parse
Description copied from interface:ParserFunction
Parses the given raw argument from the user into the corresponding value.- Specified by:
parse
in interfaceParserFunction<R extends @NonNull Object,
T extends @NonNull Object> - Parameters:
context
- The execution context.raw
- The raw argument received from the user.- Returns:
- A Mono that issues the parsed argument. If the raw value is invalid, it may
fail with a
InvalidArgumentException
. May be empty, in which case the value defers to thedefault
(functionally the same as if the argument was missing, but without causing an error if the parameter isrequired
). - Throws:
InvalidArgumentException
- if the given argument is not a valid value.- API Note:
- Do not override.
-