Contra › extend
From Botdom Documentation
This page should hopefully inform you how to extend Contra, as in, make extensions/modules/plugins/whatever. One thing you should know, is that Contra extensions are made by extending the extension class. You have to define the constructor method yourself. Here I will give an example on how to make a module, using a basic "hello world" example.
Contents |
Initialise
Ok, the first thing you want to do is make a file in ~/plugins/extensions/, and you might want to call it name.module.php, replacing name with whatever you're calling your module. For this one, we'll call it first.module.php.
Inside the file created, we have a few things that must be done. Below is the code snippet.
<?php class module extends extension { // The class you make must be an extension of the extension class. // To set the information of a module we use class properties. Much easier to manage. // All of the properties are protected, and can be in any order. // Most of these explain themselves... protected $name = 'Module example'; protected $version = 1; protected $about = 'Just an example of how modules work.'; // This next one is either true or false, meaning on or off respectively. protected $status = true; protected $author = 'photofroggy'; // The type can either be EXT_CUSTOM, EXT_SYSTEM or EXT_LIBRARY protected $type = EXT_CUSTOM; // Next we have the init method. This is called when the module is loaded. function init() { } } new module; // Here we just instantiate the class to load the module. ?>
So, that's the basic template, but for initialising we need to focus on the init() method of the class. Not much needs to be done in there, it's mainly where you add commands and hook events to the module.
<?php function init() { // All we are doing today is adding a command. // The command is called example, uses the method c_example, and requires priv level 25 $this->addCmd('example', 'c_example', 25); } ?>
Notice that we have added a command using $this->addCmd();? We've told the bot that "example" uses the method "c_example". Well, we don't have that method at the moment, but it can be created easily! The next section should show you how.
Command methods
Right, lets make that c_example method!
function c_example($ns, $from, $message, $target) { }
Notice the stuff inside the brackets? They are the input parameters that the bot's event system will give to the method. You need to have these parameters in command methods. At the moment, the method doesn't actually do anything, so let's make it say a message!
function c_example($ns, $from, $message, $target) { $this->dAmn->say($ns, 'Hello, world!'); }
So we've got a message out to a dAmn chatroom! Note that $ns is the channel that the command was received from, and a channel needs to be used to send the message to.
first.module.php
If you have been following this documentation, you should now have a file which looks something like the code below.
<?php class module extends extension { // The class you make must be an extension of the extension class. // To set the information of a module we use class properties. Much easier to manage. // All of the properties are protected, and can be in any order. // Most of these explain themselves... protected $name = 'Module example'; protected $version = 1; protected $about = 'Just an example of how modules work.'; // This next one is either true or false, meaning on or off respectively. protected $status = true; protected $author = 'photofroggy'; // The type can either be EXT_CUSTOM, EXT_SYSTEM or EXT_LIBRARY protected $type = EXT_CUSTOM; // Next we have the init method. This is called when the module is loaded. function init() { // All we are doing today is adding a command. // The command is called example, uses the method c_example, and requires priv level 25 $this->addCmd('example', 'c_example', 25); } function c_example($ns, $from, $message, $target) { $this->dAmn->say($ns, 'Hello, world!'); } } new module; // Here we just instantiate the class to load the module. ?>
Now that you have this code, you need to save your file. We started off with first.module.php being saved in the folder ~/plugins/extensions/, so the path and file name should be something like "~/plugins/extensions/first.module.php". Now you need to make sure that your module file is saved in the right folder. If it isn't in the extensions folder then it won't be loaded!
After saving your module, all you have to do is start the bot, and everything else will be done for you!
Extra
Here I should put more on how to do other things...

