Class EntityUrlParser<E extends @NonNull Entity>

java.lang.Object
dev.sympho.modular_commands.utils.parse.entity.EntityUrlParser<E>
Type Parameters:
E - The entity type.
All Implemented Interfaces:
ParserFunction<String,E>, UrlParser<E>, BiFunction<CommandContext,String,Mono<E>>
Direct Known Subclasses:
ChannelUrlParser, MessageUrlParser

public abstract class EntityUrlParser<E extends @NonNull Entity> extends Object implements UrlParser<E>
A parser for URLs of Discord entities.
Since:
1.0
Version:
1.0
  • Constructor Details

    • EntityUrlParser

      protected EntityUrlParser(EntityRefUrlParser<? extends EntityRef<E>> refParser)
      Creates a new instance.
      Parameters:
      refParser - The parser to obtain the reference with.
  • Method Details

    • supports

      public boolean supports(URL url)
      Description copied from interface: UrlParser
      Checks if the given URL is supported by this parser. If this returns false, calling UrlParser.parse(CommandContext, URL) with the same URL will result in an error.

      Note that the opposite isn't necessarily true; it is possible for this method to return true for a given URL while UrlParser.parse(CommandContext, URL) results in an error. That just means that the basic structure of the URL was detected as being compatible with this parser (for example, having a particular host and/or protocol), but was malformed or a variant that the parser doesn't support.

      Specified by:
      supports in interface UrlParser<E extends @NonNull Entity>
      Parameters:
      url - The URL to check.
      Returns:
      Whether the URL is compatible with this parser.
    • parse

      public Mono<E> parse(CommandContext context, URL url) throws InvalidArgumentException
      Description copied from interface: UrlParser
      Parses the given URL.
      Specified by:
      parse in interface UrlParser<E extends @NonNull Entity>
      Parameters:
      context - The execution context.
      url - The URL to parse.
      Returns:
      The parsed value. May result in a InvalidArgumentException if the URL is invalid.
      Throws:
      InvalidArgumentException - if the URL is invalid.