Paradiso/Modules
From Botdom Wiki
Contents |
What are modules?
A module must be self-contained in /modules/MODULE_NAME/. For the bot to register the module, it must contain a config file - a config.php.
Nothing else apart from the config file is needed to make the module part of the bot's system. So, to remove the module, simply close the bot and delete /modules/MODULE_NAME/ and everything in it. Or, to "comment-out" the module, simply rename the config file to something else apart from config.php.
During use, individual commands can be activated/deactivated by using the command "module [deactivate|activate] [MODULE_COMMAND_NAME]".
Config file
An example config.php can be found in the /modules/example/ folder. Generally, a config file follows this form:
<?php
global $modules;
$modules->name('MODULE_NAME');
// any other things you need to do at startup,
// such as initialise data/variables to be used in your module
?>
- $modules is a class which contains all the module funtions.
- $modules->name is the function that sets the name of the module, MODULE_NAME must be equal to the name of the module folder..
- This config file is only ever run once, in the main file on startup.
You MUST set the name of the module with $modules->name(MODULE_NAME). When the script is run, its value at that time needs be the name of the folder of the module so the scripts are included correctly.
Adding commands
A command is an action triggered by user-input which starts with the bot's trigger. For example, if your bot's trigger is "!", then !test would trigger the script assigned to the command "test".
To assign scripts to commands, use the following in your module config file.
$modules->addCmd(COMMAND_NAME, COMMAND_FILE, LOWEST_USER_PERMISSION, DEFAULT_STATUS);
- LOWEST_USER_PERMISSION is an integer between 0 and 99 that keeps users without privs from accessing ur bot commands.
- DEFAULT_STATUS is the status this command or event will have when the module is loaded or activated as a whole. Set it as 'on' or 'off'.
So, to set the file "example.php" to run whenever an Owner of the bot (permission level = 99) types "!example1", you would use:
$modules->addCmd('example1','example',99, 'on');
Conflicting commands
Different commands may be assigned the same file, so that typing "!example1" and "!example2" both result in "example.php" being run. However, only one file can be assigned to one command in ALL MODULES. This is to avoid unexpected results in the bot.
Commands which cause conflict are negotiated in the following order:
- /modules/A/config.php
- /modules/Z/config.php
- /modules/a/config.php
- /modules/z/config.php
The first module to contain the command (when modules are listed in the above order) takes priority. A notice will be displayed in the console whenever a command causes a conflict, so that it may be fixed.
Adding events
An event is an action triggered by anything which the bot may come across during usage. The default triggers are join, part, msg, and action.
To assign scripts to events, use the following in your module config file.
$modules->addEvt(TRIGGER_NAME, MESSAGE, FILE, DEFAULT_STATUS]]);
- TRIGGER_NAME is the name of the trigger (msg, action, join, part)
- DEFAULT_STATUS is the status this command or event will have when the module is loaded or activated as a whole, use 'on' or 'off'
So, to set the file "example.php" to run whenever someone joins the room, you would use:
$modules->addEvt('join', $message, 'example', 'on');
Unlike commands, multiple triggers may be registered with the same file, and vice versa.
Commands
Variables you may access from any command are:
- $from
- accesser of command.
- $c
- channel of command.
- $commandname
- name of command.
- $args
- arguments of command.
Events
Variables you may access from any event are:
- $from
- person who activated the event.
- $c
- channel of event.
- $message
- arguments of event.

