Skip to content

CommandRouter

Class  ·  Sharkord\Commands\CommandRouter

Class CommandRouter

Responsible for loading, registering, and executing chat commands.

CommandRouter constructor.

Parameters

ParameterTypeDescription
$sharkordSharkord

Registers a single command instance to the router.

Parameters

ParameterTypeDescription
$commandCommandInterfaceThe command object to register.

Automatically loads and registers all command classes from a specific directory.

Parameters

ParameterTypeDescription
$directorystringThe absolute path to the directory containing command classes.
$namespace (optional)string(Optional) The namespace used in the command files. Default is empty (global).

Checks if a received message matches a command pattern and executes it.

Parameters

ParameterTypeDescription
$messageMessageThe received message object.
$matchesarrayThe original regex matches

Retrieves all registered commands. Useful for generating “Help” menus.

Returns array<string,\CommandInterface>