Command
in package
A message-based command that the MessageCommandClient will listen for.
Tags
Table of Contents
Properties
- $command : string
- The trigger for the command.
- $cooldown : int
- Cooldown duration in milliseconds.
- $cooldownMessage : string
- Message displayed when the cooldown is active.
- $description : string
- Short description shown in help listings.
- $longDescription : string
- Long description for detailed help.
- $showHelp : bool
- Whether this command should be shown in help listings.
- $usage : string
- Usage string.
- $callable : callable
- The callable executed when the command is invoked.
- $client : MessageCommandClient
- Owning MessageCommandClient instance.
- $cooldownManager : CooldownManager
- Cooldowns map: user ID => timestamp when cooldown expires.
- $options : array<string|int, mixed>
- An array of options passed to the command.
- $subCommandRegistry : SubCommandRegistry
- Sub-commands map: name => Command.
Methods
- __construct() : mixed
- Creates a command instance.
- __get() : mixed|null
- Handles dynamic getters for some public properties.
- __invoke() : mixed
- Magic invoke to allow the command to be called like a callable.
- getCommand() : Command|null
- Attempts to get a sub command.
- getHelp() : array<string|int, mixed>
- Gets help information for this command.
- handle() : mixed
- Executes the command.
- registerSubCommand() : Command
- Registers a new sub-command.
- registerSubCommandAlias() : void
- Register an alias for a sub-command.
- unregisterSubCommand() : void
- Unregister a sub-command.
- unregisterSubCommandAlias() : void
- Unregister a sub-command alias.
- enforceCooldown() : string|null
- Enforce and update cooldowns for a message author.
- normalizeName() : string
- Normalize a command or alias according to the client's case sensitivity setting.
- resolveOptions() : array<string|int, mixed>
- Resolve and normalize command options.
Properties
$command
The trigger for the command.
public
string
$command
$cooldown
Cooldown duration in milliseconds.
public
int
$cooldown
$cooldownMessage
Message displayed when the cooldown is active.
public
string
$cooldownMessage
$description
Short description shown in help listings.
public
string
$description
$longDescription
Long description for detailed help.
public
string
$longDescription
$showHelp
Whether this command should be shown in help listings.
public
bool
$showHelp
$usage
Usage string.
public
string
$usage
$callable
The callable executed when the command is invoked.
protected
callable
$callable
$client
Owning MessageCommandClient instance.
protected
MessageCommandClient
$client
$cooldownManager
Cooldowns map: user ID => timestamp when cooldown expires.
protected
CooldownManager
$cooldownManager
Managed by CooldownManager.
$options
An array of options passed to the command.
protected
array<string|int, mixed>
$options
$subCommandRegistry
Sub-commands map: name => Command.
protected
SubCommandRegistry
$subCommandRegistry
Managed by SubCommandRegistry.
Methods
__construct()
Creates a command instance.
public
__construct(MessageCommandClient $client, string $command, callable $callable[, bool $options = [] ]) : mixed
Parameters
- $client : MessageCommandClient
-
The message command client.
- $command : string
-
Command trigger.
- $callable : callable
-
Callable to execute.
- $options : bool = []
-
['showHelp'] Whether to show in help.
__get()
Handles dynamic getters for some public properties.
public
__get(string $variable) : mixed|null
Parameters
- $variable : string
-
Property name.
Return values
mixed|null__invoke()
Magic invoke to allow the command to be called like a callable.
public
__invoke(Message $message, array<string|int, mixed> $args) : mixed
Parameters
- $message : Message
-
The message that triggered the command.
- $args : array<string|int, mixed>
-
Parsed arguments.
Return values
mixed —The result of handle().
getCommand()
Attempts to get a sub command.
public
getCommand(string $command[, bool $aliases = true ]) : Command|null
Parameters
- $command : string
-
The sub-command to get.
- $aliases : bool = true
-
Whether to search aliases as well.
Return values
Command|nullgetHelp()
Gets help information for this command.
public
getHelp(string $prefix) : array<string|int, mixed>
Parameters
- $prefix : string
-
The prefix to display before the command.
Return values
array<string|int, mixed> —Help information.
handle()
Executes the command.
public
handle(Message $message, array<string|int, mixed> $args) : mixed
Parameters
- $message : Message
-
The message that triggered the command.
- $args : array<string|int, mixed>
-
Parsed arguments.
Return values
mixed —The response from the callable or sub-command.
registerSubCommand()
Registers a new sub-command.
public
registerSubCommand(string $command, callable|string $callable[, array<string|int, mixed> $options = [] ]) : Command
Parameters
- $command : string
-
The command name.
- $callable : callable|string
-
The function called when the sub-command is executed.
- $options : array<string|int, mixed> = []
-
Options for the sub-command.
Return values
Command —The created sub-command instance.
registerSubCommandAlias()
Register an alias for a sub-command.
public
registerSubCommandAlias(string $alias, string $command) : void
Parameters
- $alias : string
-
Alias name.
- $command : string
-
Target sub-command name.
Tags
unregisterSubCommand()
Unregister a sub-command.
public
unregisterSubCommand(string $command) : void
Parameters
- $command : string
-
Sub-command name.
Tags
unregisterSubCommandAlias()
Unregister a sub-command alias.
public
unregisterSubCommandAlias(string $alias) : void
Parameters
- $alias : string
-
Alias name.
enforceCooldown()
Enforce and update cooldowns for a message author.
protected
enforceCooldown(Message $message, int $currentTime) : string|null
Parameters
- $message : Message
-
The message that triggered the command.
- $currentTime : int
-
Current time in milliseconds.
Return values
string|null —Returns a formatted cooldown message when the author is on cooldown, or null when allowed.
normalizeName()
Normalize a command or alias according to the client's case sensitivity setting.
protected
normalizeName(string $name) : string
Parameters
- $name : string
Return values
stringresolveOptions()
Resolve and normalize command options.
protected
resolveOptions([array<string|int, mixed> $options = [] ]) : array<string|int, mixed>
Parameters
- $options : array<string|int, mixed> = []