java.lang.Object
dev.sympho.modular_commands.utils.parse.entity.EntityRefParser<R>
- Type Parameters:
R- The reference type.
- All Implemented Interfaces:
ParserFunction<String,,R> BiFunction<CommandContext,String, Mono<R>>
- Direct Known Subclasses:
ChannelRefParser,MessageRefParser,RoleRefParser,UserRefParser
public abstract class EntityRefParser<R extends EntityRef<? extends @NonNull Entity>>
extends Object
implements ParserFunction<String,R>
A parser that extracts an entity reference from a string.
- 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>> -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedEntityRefParser(@Nullable EntityRefUrlParser<R> urlParser, @Nullable EntityRefMentionParser<R> mentionParser) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract RmakeRef(CommandContext context, Snowflake id) Creates the reference.parse(CommandContext context, String raw) Parses the given raw argument from the user into the corresponding value.parseRef(CommandContext context, String raw) Parses the given string.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.function.BiFunction
andThenMethods inherited from interface dev.sympho.modular_commands.api.command.parameter.parse.ParserFunction
apply, then
-
Constructor Details
-
EntityRefParser
@Pure protected EntityRefParser(@Nullable EntityRefUrlParser<R> urlParser, @Nullable EntityRefMentionParser<R> mentionParser) Creates a new instance.- Parameters:
urlParser- The parser to use for URLs. May benullif the entity does not support URLs.mentionParser- The parser to use for mentions. May benullif the entity does not support URLs.
-
-
Method Details
-
makeRef
Creates the reference.- Parameters:
context- The execution context.id- The parsed ID.- Returns:
- The created reference.
-
parseRef
@SideEffectFree public R parseRef(CommandContext context, String raw) throws InvalidArgumentException Parses the given string.- Parameters:
context- The execution context.raw- The string to parse.- Returns:
- The parsed reference.
- Throws:
InvalidArgumentException- if the given string does not contain a valid reference.
-
parse
Description copied from interface:ParserFunctionParses the given raw argument from the user into the corresponding value.- Specified by:
parsein interfaceParserFunction<String,R extends EntityRef<? extends @NonNull Entity>> - 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.
-