java.lang.Object
dev.sympho.modular_commands.utils.parse.entity.EntityRefMentionParser<R>
- Type Parameters:
R- The reference type.
- All Implemented Interfaces:
ParserFunction<String,,R> BiFunction<CommandContext,String, Mono<R>>
- Direct Known Subclasses:
ChannelRefMentionParser,RoleRefMentionParser,UserRefMentionParser
public abstract class EntityRefMentionParser<R extends EntityRef<? extends @NonNull Entity>>
extends Object
implements ParserFunction<String,R>
A parser for mentions of Discord entities to references.
- 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
Constructors -
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.Parses the given string.parseRef(CommandContext context, String raw) Parses the given string.protected abstract booleanprefixMatches(String prefix) Determines if the mention prefix matches the expected type.protected abstract StringtypeName()Gets the display name for this type.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
-
EntityRefMentionParser
public EntityRefMentionParser()
-
-
Method Details
-
prefixMatches
Determines if the mention prefix matches the expected type.- Parameters:
prefix- The detected prefix.- Returns:
trueif the prefix matches the expected,falseotherwise.
-
makeRef
Creates the reference.- Parameters:
context- The execution context.id- The parsed ID.- Returns:
- The created reference.
-
typeName
Gets the display name for this type.- Returns:
- The name.
- API Note:
- For use in error messages.
-
parseId
Parses the given string.- Parameters:
raw- The string to parse.- Returns:
- The ID parsed from the mention, or
nullif the given string is not a mention. - Throws:
InvalidArgumentException- if the given string is a mention but of the wrong type.
-
parseRef
@SideEffectFree public @Nullable R parseRef(CommandContext context, String raw) throws InvalidArgumentException Parses the given string.- Parameters:
context- The execution context.raw- The string to parse.- Returns:
- The reference parsed from the mention, or
nullif the given string is not a mention. - Throws:
InvalidArgumentException- if the given string is a mention but of the wrong type.
-
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.
-