java.lang.Object
dev.sympho.modular_commands.utils.parse.EntityParser<E>
- Type Parameters:
E
- The entity type.
- All Implemented Interfaces:
ParserFunction<String,
,E> BiFunction<CommandContext,
String, Mono<E>>
- Direct Known Subclasses:
MentionableParser
,MessageParser
public abstract class EntityParser<E extends @NonNull Entity>
extends Object
implements ParserFunction<String,E>
A parser that extracts an entity 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
-
Method Summary
Modifier and TypeMethodDescriptionParses the entity ID from the raw argument.getEntity
(CommandContext context, Snowflake id) Retrieves the entity with the given ID.Retrieves the parser to use for URLs, if supported.parse
(CommandContext context, String raw) Parses the given raw argument from the user into the corresponding value.static Snowflake
Parses a snowflake ID from an argument string.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.function.BiFunction
andThen
Methods inherited from interface dev.sympho.modular_commands.api.command.parameter.parse.ParserFunction
apply, then
-
Constructor Details
-
EntityParser
public EntityParser()
-
-
Method Details
-
parseId
Parses a snowflake ID from an argument string.- Parameters:
raw
- The argument.- Returns:
- The snowflake ID.
- Throws:
InvalidArgumentException
- if the given string is not a valid snowflake.
-
getUrlParser
Retrieves the parser to use for URLs, if supported.- Returns:
- The URL parser, or
null
if URLs are not supported. - Implementation Requirements:
- The default returns
null
.
-
extractId
Parses the entity ID from the raw argument.- Parameters:
raw
- The received argument.- Returns:
- The entity ID.
- Throws:
InvalidArgumentException
- if the given string is not a valid ID.- Implementation Requirements:
- Supports only plain IDs by default.
-
getEntity
Retrieves the entity with the given ID.- Parameters:
context
- The execution context.id
- The entity ID.- Returns:
- The entity. May be empty if not found.
-
parse
Description copied from interface:ParserFunction
Parses the given raw argument from the user into the corresponding value.- Specified by:
parse
in interfaceParserFunction<String,
E 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.
-