Class EntityRefMentionParser<R extends EntityRef<? extends @NonNull Entity>>

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
  • Constructor Details

    • EntityRefMentionParser

      public EntityRefMentionParser()
  • Method Details

    • prefixMatches

      @Pure protected abstract boolean prefixMatches(String prefix)
      Determines if the mention prefix matches the expected type.
      Parameters:
      prefix - The detected prefix.
      Returns:
      true if the prefix matches the expected, false otherwise.
    • makeRef

      @SideEffectFree protected abstract R makeRef(CommandContext context, Snowflake id)
      Creates the reference.
      Parameters:
      context - The execution context.
      id - The parsed ID.
      Returns:
      The created reference.
    • typeName

      @Pure protected abstract String 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 null if 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 null if the given string is not a mention.
      Throws:
      InvalidArgumentException - if the given string is a mention but of the wrong type.
    • parse

      public Mono<R> parse(CommandContext context, String raw) throws InvalidArgumentException
      Description copied from interface: ParserFunction
      Parses the given raw argument from the user into the corresponding value.
      Specified by:
      parse in interface ParserFunction<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 the default (functionally the same as if the argument was missing, but without causing an error if the parameter is required).
      Throws:
      InvalidArgumentException - if the given argument is not a valid value.