Contra › class › extension
From Botdom Documentation
This is the extension class! This is the class you want to extend when making a module/plugin.
Contents |
Location
~/core/Module_class.php
Properties
protected $Bot = Null; // This is where an instance of the core class is stored. protected $Console = Null; // This is an instance of the console class. protected $dAmn = Null; // Instance for dAmnPHP protected $Timer = Null; // Instance for the Timer class. protected $user = Null; // User class. protected $name = Null; // Name for the extension. protected $type = EXT_CUSTOM;// Type for the extension protected $status = false; // Initial status. protected $about = Null; // Extension information. protected $author = Null; // Extension author. protected $version = Null; // Extension version. protected $loading = Null; // Whether we are loading or not. protected $evts = Null; // Events. protected $cmds = Null; // Commands.
Methods
These are the methods in the extension class which are needed, and thus can't be overridden.
__get
This is called when variables are requested.
__construct
This is called when the class is instantiated.
addCmd
This hooks a command into the core! This is one of the main things you want.
Parameters: $command - string. This is the command that will be used to trigger $method. $method - string. This is the name of the method that will be called when the command is triggered. The method must be part of the child class. $access - integer. Access level required for this command. Can be used to restrict access to system commands. Default is 25 (Guest). $status - bool(true/false). Whether the command is switched on or off. Default is true (on).
This should be used in the constructor to hook commands! Example:
$this->addCmd('note', 'c_note', 25, true);
cmdHelp
Use this to give helpful information about a command.
Parameters: $command - string. This is the command to give help for. $help - string. Some helpful information.
Example:
$this->cmdHelp('note', 'Send a note to someone!');
switchCmd
Use this to turn commands on or off.
Parameters: $command - string. The command to switch on or off. $status - bool(true/false). Setting to change the command to. Default is true(on).
Example:
$this->switchCmd('note', false); // Command "note" is now switched off.
hook
Hook $method onto event $event.
Parameters: $method - string. The name of the method that will be called on $event. $event - string. The name of the event that should trigger $method.
Example usage:
$this->hook('e_check_notes', 'recv_msg');
unhook
Unhook $method from event $event.
Parameters: $method - string. $event - string.
Example usage:
$this->unhook('e_check_notes', 'recv_msg');
newEvt
This creates an event!
Parameters: $event - string. This is the name of the event.
Example usage:
$this->newEvt('recv_note');
load
This method is another to be used inside the constructor method, and the last one to be used there. This hooks the module into the bot's core. The method takes no parameters. Example:
$this->load();
turn
Another method for outside the module. This is used to turn the module on or off.
Parameters: $status - bool(true/false).
Example usage:
$this->Bot->mod['notes']->turn(true);
Write
This method is to be used inside the module!
Parameters: $file - string. Name of the file to write to. $data - mixed. Data to write to $file. $format - integer. How to format the data. 0 = serialized, 1 = as is, 2 = var_export()'d. The default is 0.
You should only really use this when a dAmn event or command has been triggered. Otherwise you'll need to set the global System::$bot before calling this method. This goes for all of the other data methods in the extension class. Example usage:
$this->Write('lol', 'wot', 1);
The data methods refer to the directory ~/storage/(BOT NAME)/(MODULE NAME)/(FILE NAME).bsv. Calling this method from file 'data' inside module 'notes' on bot 'Amphino' would write data to ~/storage/Amphino/notes/data.bsv.
Read
This is also to be used inside the module, and is another data method.
Parameters: $file - string. Name of the file to read. $format - integer. How to read the file. 0 = unserialize, 1 = as is, 2 = include code. The default is 0.
Example usage of this method:
$this->Read('lol', 1);
Unlink
This method is another data method to be used inside the module. This method deletes the file.
Parameters: $file - string. File to delete. $return - bool(true/false). Whether to return the data in $file. Default is false. $format - integer. What formatting to use when returning the data, if $return = true. Default is 0.
Example usage:
$this->Unlink('lol', true, 1);

