Class BaseCommandExecutor<E extends Event,CTX extends InstrumentedContext & LazyContext,H extends Handlers,I extends SmartIterator<String>>
- Type Parameters:
E- The type of event that triggers commands.CTX- The type of command context.H- The type of handlers.I- The iterator type used to traverse the received arguments.
- Direct Known Subclasses:
MessageCommandExecutor
- Since:
- 1.0
- Version:
- 1.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final AccessManagerThe access manager to use for access checks.protected final GatewayDiscordClientThe client to receive events from.protected final io.micrometer.core.instrument.MeterRegistryThe meter registry to use.protected final io.micrometer.observation.ObservationRegistryThe observation registry to use.protected final RegistryThe registry to use to look up commands.Fields inherited from class dev.sympho.modular_commands.execute.CommandExecutor
logger -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedBaseCommandExecutor(GatewayDiscordClient client, Registry registry, Optional<AccessManager> accessManager, Optional<io.micrometer.core.instrument.MeterRegistry> meters, Optional<io.micrometer.observation.ObservationRegistry> observations) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionCreates a function that adds the common instrumentation tags for the given event to Monos.protected Flux<?>Constructs the processing pipeline that processes command events.Retrives the command type to use.protected booleaneventFilter(E event) Determines if an event should be processed for commands.Retrieves the event type to listen for.protected abstract booleanDetermines whether a parsed arg list (as given byparse(Event)) must always be fully matched to a command.protected abstract UserRetrieves the user that invoked the command from the triggering event.protected abstract Mono<MessageChannel>getChannel(E event) Retrieves the channel where the command was invoked from the triggering event.protected abstract SnowflakegetChannelId(E event) Retrieves the ID of the channel where the command was invoked from the triggering event.Retrieves the guild where the command was invoked, if any, from the triggering event.getGuildId(E event) Retrieves the ID of the guild where the command was invoked, if any, from the triggering event.protected abstract InvocationHandler<? super CTX>getInvocationHandler(H handlers) Retrieves the invocation handler specified by the given hander set.protected abstract List<? extends ResultHandler<? super CTX>>getResultHandlers(H handlers) Retrieves the result handlers specified by the given hander set.protected abstract CTXmakeContext(E event, Command<? extends H> command, Invocation invocation, I args) Creates a command context from a parsed invocation.protected abstract IParses the raw args from the event.protected abstract Metrics.Tag.TypetagType()Determines thetype tagfor this pipeline.Methods inherited from class dev.sympho.modular_commands.execute.CommandExecutor
start, stop
-
Field Details
-
client
The client to receive events from. -
registry
The registry to use to look up commands. -
accessManager
The access manager to use for access checks. -
meters
protected final io.micrometer.core.instrument.MeterRegistry metersThe meter registry to use. -
observations
protected final io.micrometer.observation.ObservationRegistry observationsThe observation registry to use.
-
-
Constructor Details
-
BaseCommandExecutor
protected BaseCommandExecutor(GatewayDiscordClient client, Registry registry, Optional<AccessManager> accessManager, Optional<io.micrometer.core.instrument.MeterRegistry> meters, Optional<io.micrometer.observation.ObservationRegistry> observations) Creates a new instance.- Parameters:
client- The client to receive events from.registry- The registry to use to look up commands.accessManager- The access manager to use for access checks. Defaults toAccessManager.basic().meters- The meter registry to use. Defaults to a no-op registry.observations- The observation registry to use. Defaults to a no-op registry.
-
-
Method Details
-
buildPipeline
Description copied from class:CommandExecutorConstructs the processing pipeline that processes command events.- Specified by:
buildPipelinein classCommandExecutor- Returns:
- The constructed pipeline.
-
tagType
Determines thetype tagfor this pipeline.- Returns:
- The tag.
-
addTags
Creates a function that adds the common instrumentation tags for the given event to Monos.- Type Parameters:
T- The mono value type.- Parameters:
event- The event.- Returns:
- The function.
-
eventType
Retrieves the event type to listen for.- Returns:
- The event type.
-
commandType
Retrives the command type to use.- Returns:
- The command type.
-
fullMatch
Determines whether a parsed arg list (as given byparse(Event)) must always be fully matched to a command. Iftrue, the presence of leftover args (as would be received bymakeContext(Event, Command, Invocation, SmartIterator)) triggers an error for that event (stopping the processing of that particular event, but without stopping the pipeline).- Returns:
trueif the parsed args must be fully matched to a command.falseif additional args are allowed.- API Note:
- This check is not related to any user-facing functionality, but purely as an
internal sanity check. If an event provides arguments in a way other than the
parsed args, with said args being used only to identify the command to execute,
it would not make sense for extra args to be received.
For example, in a slash command, the comand name is provided separately from the arguments, and any subcommands are already labeled as such, so there is no need to evaluate any further args when looking up the command. At the same time, since slash commands (including subcommands) have to be registered with Discord ahead of time to be callable by users, the only way that a slash command event would provide a subcommand that is not found is if the command was registered to Discord without having a corresponding internal handler, without would indicate an inconsistency in the command system (the declared commands do not match the implemented commands), which should be reported to the administrator as a (non-fatal) pipeline error.
-
eventFilter
Determines if an event should be processed for commands. This filter is applied at the start of handling, before any parsing is performed.- Parameters:
event- The event to check.- Returns:
trueif the event should be processed.falseif the event should be discarded.- Implementation Requirements:
- The default is to process all received events.
-
parse
Parses the raw args from the event. This includes the names that identify the command and subcommands, as well as any additional args,if allowed.- Parameters:
event- The event to parse args from.- Returns:
- The parsed args. May have no elements if the event should not be handled as a command.
-
makeContext
@SideEffectFree protected abstract CTX makeContext(E event, Command<? extends H> command, Invocation invocation, I args) Creates a command context from a parsed invocation.- Parameters:
event- The event being processed.command- The identified command.invocation- The invocation that mapped to the command. This may be different from the command's declaredCommand.invocation()if it was invoked using an alias (when supported).args- The args that remained after removing the command identifiers. IffullMatch()istrue, this will always be empty.- Returns:
- The context that represents the given invocation.
-
getGuildId
Retrieves the ID of the guild where the command was invoked, if any, from the triggering event.- Parameters:
event- The triggering event.- Returns:
- The ID of the guild where the event was invoked.
-
getGuild
Retrieves the guild where the command was invoked, if any, from the triggering event.- Parameters:
event- The triggering event.- Returns:
- The guild where the event was invoked.
-
getChannelId
Retrieves the ID of the channel where the command was invoked from the triggering event.- Parameters:
event- The triggering event.- Returns:
- The ID of the channel where the event was invoked.
-
getChannel
Retrieves the channel where the command was invoked from the triggering event.- Parameters:
event- The triggering event.- Returns:
- The channel where the event was invoked.
-
getCaller
Retrieves the user that invoked the command from the triggering event.- Parameters:
event- The triggering event.- Returns:
- The user that invoked the command.
-
getInvocationHandler
Retrieves the invocation handler specified by the given hander set.- Parameters:
handlers- The handler set.- Returns:
- The invocation handler.
-
getResultHandlers
Retrieves the result handlers specified by the given hander set.- Parameters:
handlers- The handler set.- Returns:
- The result handlers.
-