- java.lang.Object
-
- com.github.alex1304.ultimategdbot.api.command.CommandService
-
public final class CommandService extends Object
The command service coordinates the command providers from all plugins. It also holds a blacklist to restrict the usage of commands from certain guilds, channels or users. It listens to message create events and dispatch them to the proper command providers to trigger the execution of commands.
-
-
Field Summary
Fields Modifier and Type Field Description static String
CONFIG_RESOURCE_NAME
-
Constructor Summary
Constructors Constructor Description CommandService(BotConfig botConfig, discord4j.core.GatewayDiscordClient gateway, LocalizationService localizationService, LoggingService loggingService)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addProvider(CommandProvider provider)
Adds a new command provider to this kernel.void
blacklist(long id)
Blacklists a new ID.Optional<Command>
getCommandByAlias(String alias)
Gets a command instance corresponding to the given alias.String
getCommandPrefix()
Set<CommandProvider>
getCommandProviders()
Gets an immutable view of the command providers added to the service.String
getFlagPrefix()
PermissionChecker
getPermissionChecker()
Gets the permission checker used to check permissions for commands provided by this kernel.reactor.core.publisher.Mono<Void>
processEvent(discord4j.core.event.domain.message.MessageCreateEvent event)
Processes a MessageCreateEvent.void
setPrefixForGuild(long guildId, String prefix)
Sets a prefix specific for the given guild.void
unblacklist(long id)
Removes an ID from the blacklist.
-
-
-
Field Detail
-
CONFIG_RESOURCE_NAME
public static final String CONFIG_RESOURCE_NAME
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
CommandService
public CommandService(BotConfig botConfig, discord4j.core.GatewayDiscordClient gateway, LocalizationService localizationService, LoggingService loggingService)
-
-
Method Detail
-
addProvider
public void addProvider(CommandProvider provider)
Adds a new command provider to this kernel.- Parameters:
provider
- the command provider to add
-
processEvent
public reactor.core.publisher.Mono<Void> processEvent(discord4j.core.event.domain.message.MessageCreateEvent event)
Processes a MessageCreateEvent. It first checks if neither the guild, the channel and the user is blacklisted, then proceeds to find the guild-specific prefix and trigger the command if it matches with one provided by one of the command providers.- Parameters:
event
- theMessageCreateEvent
that was received- Returns:
- a Mono that completes when the command has terminated. If the blacklist check doesn't pass, a Mono completing immediately is returned. Any errors that may occur when running the command are forwarded through this Mono.
-
getCommandByAlias
public Optional<Command> getCommandByAlias(String alias)
Gets a command instance corresponding to the given alias.- Parameters:
alias
- the alias of the command- Returns:
- the corresponding command instance, if present
-
getPermissionChecker
public PermissionChecker getPermissionChecker()
Gets the permission checker used to check permissions for commands provided by this kernel.- Returns:
- the permission checker
-
blacklist
public void blacklist(long id)
Blacklists a new ID.- Parameters:
id
- the ID of a user, a channel or a guild that won't be allowed to run commands from this kernel.
-
unblacklist
public void unblacklist(long id)
Removes an ID from the blacklist.- Parameters:
id
- the ID of a user, a channel or a guild that will be allowed to run commands from this kernel again.
-
setPrefixForGuild
public void setPrefixForGuild(long guildId, @Nullable String prefix)
Sets a prefix specific for the given guild. If one was already set for the same guild, it is overwritten.- Parameters:
guildId
- the guild idprefix
- the new prefix. May be null, in which case the prefix is removed.
-
getCommandProviders
public Set<CommandProvider> getCommandProviders()
Gets an immutable view of the command providers added to the service.- Returns:
- the command providers
-
getCommandPrefix
public String getCommandPrefix()
-
getFlagPrefix
public String getFlagPrefix()
-
-