Class MessageCommandExecutor
java.lang.Object
dev.sympho.modular_commands.execute.CommandExecutor
dev.sympho.modular_commands.execute.BaseCommandExecutor<MessageCreateEvent,MessageContextImpl,MessageHandlers,StringSplitter.Async.Iterator>
dev.sympho.modular_commands.execute.MessageCommandExecutor
public class MessageCommandExecutor
extends BaseCommandExecutor<MessageCreateEvent,MessageContextImpl,MessageHandlers,StringSplitter.Async.Iterator>
Executor that receives and handles commands through text messages.
Note that, as command names are restricted to only using lowercase characters, command matching is case insensitive (argument parsing is not affected).
- Since:
- 1.0
- Version:
- 1.0
-
Field Summary
Fields inherited from class dev.sympho.modular_commands.execute.BaseCommandExecutor
accessManager, client, meters, observations, registryFields inherited from class dev.sympho.modular_commands.execute.CommandExecutor
logger -
Constructor Summary
ConstructorsConstructorDescriptionMessageCommandExecutor(GatewayDiscordClient client, Registry registry, Optional<dev.sympho.bot_utils.access.AccessManager> accessManager, Optional<io.micrometer.core.instrument.MeterRegistry> meters, Optional<io.micrometer.observation.ObservationRegistry> observations, PrefixProvider prefixProvider, Optional<AliasProvider> aliases) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionbuilder()Creates a new builder.protected Class<MessageHandlers>Retrives the command type to use.protected booleaneventFilter(MessageCreateEvent event) Determines if an event should be processed for commands.protected Class<MessageCreateEvent>Retrieves the event type to listen for.protected booleanDetermines whether a parsed arg list (as given byBaseCommandExecutor.parse(Event)) must always be fully matched to a command.protected UsergetCaller(MessageCreateEvent event) Retrieves the user that invoked the command from the triggering event.protected Mono<MessageChannel>getChannel(MessageCreateEvent event) Retrieves the channel where the command was invoked from the triggering event.protected SnowflakegetChannelId(MessageCreateEvent event) Retrieves the ID of the channel where the command was invoked from the triggering event.getGuild(MessageCreateEvent event) Retrieves the guild where the command was invoked, if any, from the triggering event.getGuildId(MessageCreateEvent event) Retrieves the ID of the guild where the command was invoked, if any, from the triggering event.protected InvocationHandler<? super MessageContextImpl>getInvocationHandler(MessageHandlers handlers) Retrieves the invocation handler specified by the given hander set.protected List<? extends ResultHandler<? super MessageContextImpl>>getResultHandlers(MessageHandlers handlers) Retrieves the result handlers specified by the given hander set.protected MessageContextImplmakeContext(MessageCreateEvent event, Command<? extends MessageHandlers> command, Invocation invocation, StringSplitter.Async.Iterator args) Creates a command context from a parsed invocation.protected StringSplitter.Async.Iteratorparse(MessageCreateEvent event) Parses the raw args from the event.protected Metrics.Tag.TypetagType()Determines thetype tagfor this pipeline.Methods inherited from class dev.sympho.modular_commands.execute.BaseCommandExecutor
addTags, buildPipelineMethods inherited from class dev.sympho.modular_commands.execute.CommandExecutor
start, stop
-
Constructor Details
-
MessageCommandExecutor
@Constructor public MessageCommandExecutor(GatewayDiscordClient client, Registry registry, Optional<dev.sympho.bot_utils.access.AccessManager> accessManager, Optional<io.micrometer.core.instrument.MeterRegistry> meters, Optional<io.micrometer.observation.ObservationRegistry> observations, PrefixProvider prefixProvider, Optional<AliasProvider> aliases) 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.prefixProvider- The provider to get prefixes from.aliases- Provides the aliases that should be applied. Defaults toAliasProvider.none().
-
-
Method Details
-
builder
Creates a new builder.- Returns:
- The created builder.
-
tagType
Description copied from class:BaseCommandExecutorDetermines thetype tagfor this pipeline.- Specified by:
tagTypein classBaseCommandExecutor<MessageCreateEvent,MessageContextImpl, MessageHandlers, StringSplitter.Async.Iterator> - Returns:
- The tag.
-
eventType
Description copied from class:BaseCommandExecutorRetrieves the event type to listen for.- Specified by:
eventTypein classBaseCommandExecutor<MessageCreateEvent,MessageContextImpl, MessageHandlers, StringSplitter.Async.Iterator> - Returns:
- The event type.
-
commandType
Description copied from class:BaseCommandExecutorRetrives the command type to use.- Specified by:
commandTypein classBaseCommandExecutor<MessageCreateEvent,MessageContextImpl, MessageHandlers, StringSplitter.Async.Iterator> - Returns:
- The command type.
-
fullMatch
protected boolean fullMatch()Description copied from class:BaseCommandExecutorDetermines whether a parsed arg list (as given byBaseCommandExecutor.parse(Event)) must always be fully matched to a command. Iftrue, the presence of leftover args (as would be received byBaseCommandExecutor.makeContext(Event, Command, Invocation, SmartIterator)) triggers an error for that event (stopping the processing of that particular event, but without stopping the pipeline).- Specified by:
fullMatchin classBaseCommandExecutor<MessageCreateEvent,MessageContextImpl, MessageHandlers, StringSplitter.Async.Iterator> - Returns:
trueif the parsed args must be fully matched to a command.falseif additional args are allowed.
-
eventFilter
Description copied from class:BaseCommandExecutorDetermines if an event should be processed for commands. This filter is applied at the start of handling, before any parsing is performed.- Overrides:
eventFilterin classBaseCommandExecutor<MessageCreateEvent,MessageContextImpl, MessageHandlers, StringSplitter.Async.Iterator> - Parameters:
event- The event to check.- Returns:
trueif the event should be processed.falseif the event should be discarded.
-
parse
Description copied from class:BaseCommandExecutorParses the raw args from the event. This includes the names that identify the command and subcommands, as well as any additional args,if allowed.- Specified by:
parsein classBaseCommandExecutor<MessageCreateEvent,MessageContextImpl, MessageHandlers, StringSplitter.Async.Iterator> - 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
protected MessageContextImpl makeContext(MessageCreateEvent event, Command<? extends MessageHandlers> command, Invocation invocation, StringSplitter.Async.Iterator args) Description copied from class:BaseCommandExecutorCreates a command context from a parsed invocation.- Specified by:
makeContextin classBaseCommandExecutor<MessageCreateEvent,MessageContextImpl, MessageHandlers, StringSplitter.Async.Iterator> - 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. IfBaseCommandExecutor.fullMatch()istrue, this will always be empty.- Returns:
- The context that represents the given invocation.
-
getGuildId
Description copied from class:BaseCommandExecutorRetrieves the ID of the guild where the command was invoked, if any, from the triggering event.- Specified by:
getGuildIdin classBaseCommandExecutor<MessageCreateEvent,MessageContextImpl, MessageHandlers, StringSplitter.Async.Iterator> - Parameters:
event- The triggering event.- Returns:
- The ID of the guild where the event was invoked.
-
getGuild
Description copied from class:BaseCommandExecutorRetrieves the guild where the command was invoked, if any, from the triggering event.- Specified by:
getGuildin classBaseCommandExecutor<MessageCreateEvent,MessageContextImpl, MessageHandlers, StringSplitter.Async.Iterator> - Parameters:
event- The triggering event.- Returns:
- The guild where the event was invoked.
-
getChannelId
Description copied from class:BaseCommandExecutorRetrieves the ID of the channel where the command was invoked from the triggering event.- Specified by:
getChannelIdin classBaseCommandExecutor<MessageCreateEvent,MessageContextImpl, MessageHandlers, StringSplitter.Async.Iterator> - Parameters:
event- The triggering event.- Returns:
- The ID of the channel where the event was invoked.
-
getChannel
Description copied from class:BaseCommandExecutorRetrieves the channel where the command was invoked from the triggering event.- Specified by:
getChannelin classBaseCommandExecutor<MessageCreateEvent,MessageContextImpl, MessageHandlers, StringSplitter.Async.Iterator> - Parameters:
event- The triggering event.- Returns:
- The channel where the event was invoked.
-
getCaller
Description copied from class:BaseCommandExecutorRetrieves the user that invoked the command from the triggering event.- Specified by:
getCallerin classBaseCommandExecutor<MessageCreateEvent,MessageContextImpl, MessageHandlers, StringSplitter.Async.Iterator> - Parameters:
event- The triggering event.- Returns:
- The user that invoked the command.
-
getInvocationHandler
protected InvocationHandler<? super MessageContextImpl> getInvocationHandler(MessageHandlers handlers) Description copied from class:BaseCommandExecutorRetrieves the invocation handler specified by the given hander set.- Specified by:
getInvocationHandlerin classBaseCommandExecutor<MessageCreateEvent,MessageContextImpl, MessageHandlers, StringSplitter.Async.Iterator> - Parameters:
handlers- The handler set.- Returns:
- The invocation handler.
-
getResultHandlers
protected List<? extends ResultHandler<? super MessageContextImpl>> getResultHandlers(MessageHandlers handlers) Description copied from class:BaseCommandExecutorRetrieves the result handlers specified by the given hander set.- Specified by:
getResultHandlersin classBaseCommandExecutor<MessageCreateEvent,MessageContextImpl, MessageHandlers, StringSplitter.Async.Iterator> - Parameters:
handlers- The handler set.- Returns:
- The result handlers.
-