Package discord4j.command.util
Class AbstractCommandDispatcher
- java.lang.Object
-
- discord4j.command.util.AbstractCommandDispatcher
-
- All Implemented Interfaces:
CommandDispatcher
public abstract class AbstractCommandDispatcher extends Object implements CommandDispatcher
An utility abstract implementation ofCommandDispatcher
.The implementation of
dispatch(MessageCreateEvent, Set, CommandErrorHandler)
is designed to cover the vast majority of use cases. It will automatically filter out empty contents and bots and will determine command names by stripping any prefix (provided bygetPrefixes(MessageCreateEvent)
) and determining the command name based off the first sequence of characters before a space or until end-of-string is reached. The rest of the remaining content index is considered to be part of the argument namespace.
-
-
Constructor Summary
Constructors Constructor Description AbstractCommandDispatcher()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Publisher<? extends Command<?>>
dispatch(discord4j.core.event.domain.message.MessageCreateEvent event, Set<CommandProvider<?>> providers, CommandErrorHandler errorHandler)
Called to handle the logic of invoking a command based on an event.protected abstract Publisher<String>
getPrefixes(discord4j.core.event.domain.message.MessageCreateEvent event)
Requests to retrieve the prefixes for the supplied event.
-
-
-
Method Detail
-
dispatch
public Publisher<? extends Command<?>> dispatch(discord4j.core.event.domain.message.MessageCreateEvent event, Set<CommandProvider<?>> providers, CommandErrorHandler errorHandler)
Description copied from interface:CommandDispatcher
Called to handle the logic of invoking a command based on an event. This is expected to do two things:- Determine whether a command should be triggered. This can be due to any arbitrary criteria (existence of a prefix, a specific use sending the message, etc).
- Generate hints to allow for naive argument parsing by command providers. These hints are not necessarily binding, but providers are expected to at least consider them. The hints are composed of the command that the message author is attempting to execute (single word) and a set of string indices denoting the subsequence of the message string which contains the command's arguments.
- Specified by:
dispatch
in interfaceCommandDispatcher
- Parameters:
event
- The event for command execution.providers
- TheCommandProvider
s this dispatcher should consider for dispatching.errorHandler
- The error handler to pass to command.- Returns:
- A flux which emits executed command.
- See Also:
CommandProvider.provide(discord4j.core.event.domain.message.MessageCreateEvent, String, int, int)
-
getPrefixes
protected abstract Publisher<String> getPrefixes(discord4j.core.event.domain.message.MessageCreateEvent event)
Requests to retrieve the prefixes for the supplied event.- Parameters:
event
- The event to retrieve prefixes for.- Returns:
- A
Publisher
that continually emits the prefixes for the supplied event.
-
-