- Type Parameters:
T
- The type of argument that is provided.
- All Superinterfaces:
ArgumentParser<Attachment,
,T> AttachmentParser<T>
,AttachmentParserStages.Parser<T>
,AttachmentParserStages.Validator
,BiFunction<CommandContext,
,Attachment, Mono<T>> ParserFunction<Attachment,
T>
- All Known Subinterfaces:
TextFileParser<T>
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface
public interface AttachmentDataParser<T extends @NonNull Object>
extends AttachmentParser<T>, AttachmentParserStages.Validator, AttachmentParserStages.Parser<T>
Parses received attachment arguments into their actual value.
- Since:
- 1.0
- Version:
- 1.0
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic final class
Resources used by an instance.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>> -
Field Summary
Modifier and TypeFieldDescriptionstatic final AttachmentDataParser.Resources
Resources used by all instances. -
Method Summary
Modifier and TypeMethodDescriptiondefault reactor.netty.http.client.HttpClient
getHttpClient
(CommandContext context) Determines the HTTP client to use to fetch the attachment.default String
getUrl
(Attachment value) Obtains the URL to download the attachment from.default @org.checkerframework.common.value.qual.IntRange(from=0L) int
maxSize()
Retrieves the maximum size (in bytes) that the attachment may have.parseArgument
(CommandContext context, Attachment raw) Parses the given raw argument from the user into the corresponding value.default void
validate
(Attachment attachment) Validates that the attachment is appropriate prior to fetching it.default Attachment
validateRaw
(Attachment raw) Validates the raw value before parsing.Methods inherited from interface dev.sympho.modular_commands.api.command.parameter.parse.ArgumentParser
parse
Methods inherited from interface dev.sympho.modular_commands.api.command.parameter.parse.AttachmentParserStages.Parser
parse
Methods inherited from interface java.util.function.BiFunction
andThen
Methods inherited from interface dev.sympho.modular_commands.api.command.parameter.parse.ParserFunction
apply, then
-
Field Details
-
GLOBAL_RESOURCES
Resources used by all instances.
-
-
Method Details
-
validate
Description copied from interface:AttachmentParserStages.Validator
Validates that the attachment is appropriate prior to fetching it.- Specified by:
validate
in interfaceAttachmentParserStages.Validator
- Parameters:
attachment
- The attachment to validate.- Throws:
InvalidArgumentException
- if the attachment is not valid.- Implementation Requirements:
- The default is a no-op.
-
maxSize
Retrieves the maximum size (in bytes) that the attachment may have.- Returns:
- The maximum size.
- Implementation Requirements:
- The default is
Integer.MAX_VALUE
.
-
validateRaw
Description copied from interface:ArgumentParser
Validates the raw value before parsing.- Specified by:
validateRaw
in interfaceArgumentParser<Attachment,
T extends @NonNull Object> - Parameters:
raw
- The raw value.- Returns:
- The raw value.
- Throws:
InvalidArgumentException
- if the value is invalid.
-
getUrl
Obtains the URL to download the attachment from.- Parameters:
value
- The attachment.- Returns:
- The URL to download from.
- Implementation Requirements:
- Defaults to the non-proxy URL.
-
getHttpClient
Determines the HTTP client to use to fetch the attachment.- Parameters:
context
- The execution context.- Returns:
- The HTTP client to use.
- Implementation Requirements:
- The default delegates to
GLOBAL_RESOURCES
.AttachmentDataParser.Resources.getClientGetter()
.
-
parseArgument
default Mono<T> parseArgument(CommandContext context, Attachment raw) throws InvalidArgumentException Description copied from interface:ArgumentParser
Parses the given raw argument from the user into the corresponding value.- Specified by:
parseArgument
in interfaceArgumentParser<Attachment,
T extends @NonNull Object> - 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
. - Throws:
InvalidArgumentException
- if the given argument is not a valid value.- Implementation Requirements:
- Fetches the attachment from the
URL
using a client obtained byHttpClient.create()
then delegates toAttachmentParserStages.Parser.parse(CommandContext, HttpClientResponse, ByteBufMono)
.
-