CommandRouter
Class · Sharkord\Commands\CommandRouter
Class CommandRouter
Responsible for loading, registering, and executing chat commands.
Methods
Section titled “Methods”__construct()
Section titled “__construct()”CommandRouter constructor.
Parameters
| Parameter | Type | Description |
|---|---|---|
$sharkord | Sharkord |
register()
Section titled “register()”Registers a single command instance to the router.
Parameters
| Parameter | Type | Description |
|---|---|---|
$command | CommandInterface | The command object to register. |
loadFromDirectory()
Section titled “loadFromDirectory()”Automatically loads and registers all command classes from a specific directory.
Parameters
| Parameter | Type | Description |
|---|---|---|
$directory | string | The absolute path to the directory containing command classes. |
$namespace (optional) | string | (Optional) The namespace used in the command files. Default is empty (global). |
handle()
Section titled “handle()”Checks if a received message matches a command pattern and executes it.
Parameters
| Parameter | Type | Description |
|---|---|---|
$message | Message | The received message object. |
$matches | array | The original regex matches |
getCommands()
Section titled “getCommands()”Retrieves all registered commands. Useful for generating “Help” menus.
Returns array<string,\CommandInterface>