Command Modules Minimum Structure
Updated as of Sonnet V1.2.2
Every command is an async function with passed args: message, args, and client.
Passed kwargs
Name | Description |
---|---|
stats: Dict[str, int] | .01ms detail integer timestamps representing process times of the bot |
cmds: List[commandmodule] | The command modules as imported by LeXdPyK |
dlibs: List[dynamiclibmodule] | The dynamiclib modules as imported by LeXdPyK |
bot_start: float | The time.time() timestamp of when the kernel started, can vary between UTC or local time based on env vars |
main_version: str | The version string of the kernel |
kernel_ramfs: LeXdPyK.ram_filesystem | Ramfs passed from kernel |
ramfs: LeXdPyK.ram_filesystem | Ramfs passed from kernel |
conf_cache: Dict[str, Any] | A cache of sonnets common database entries, what is stored in this cache can change by version but always will include prefix and automod data |
verbose: bool | A true|false flag telling the command if it should be verbose, this is up to the command developer to implement, sonnet commands follow the rule that error messages should always print but sucess messages should be based on the verbose flag |
cmds_dict: commandmodule.commands | A hashmap of the commands used by sonnet to process and execute commands |
File format
category_info: Dict[str, str]
Type: hmap, required fields:
Name | Description |
---|---|
name | Internal name of module |
pretty_name | Prettified name of module used in printing to end user |
description | A short description of the module |
commands: Dict[str, Dict[str, Any]]
Type: hmap, for each command create an hmap within with the name of the command with the following required fields:
Name | Description | Required |
---|---|---|
pretty_name: str | A prettified name of the command used for printing to user | Required |
description: str | A short description of what the command does | Required |
rich_description: str | A complex description of what the command does, used to explain more advanced features | Optional |
permission: Union[str, Tuple[str, Callable[[discord.Message], bool]]] | The required permission level of the command, can be everyone , moderator , administrator , or owner . Additionally can be a tuple where the 0 value is the name and the 1 value is a function taking a discord.py message parameter that returns true or false, this allows for custom permissions |
Required |
cache: str | Whether to keep , regenerate , or purge cache on command completion. Due to implementation updates purge and regenerate do the same job and only both exist for legacy support, as there is no reason to remove it, it is suggested that commands still use purge and regenerate to better specify the intent of the command |
Required |
execute: Awaitable[[discord.Message, List[str], discord.Client, **Any], Optional[int]] | A map to the function this command runs | Required |
Optionally you can have an alias entry
Name | Description | Required |
---|---|---|
alias: str | the hashmap key of another command, cannot alias to another alias | Required |
version_info: str
Type: string; a string representing the version of the command module
Example module
Here is a simple example module that is used for the jban
command. You can use it to learn the module format.
cmd_jokes.py [910 bytes]