Chapter 1. Basics

Table of Contents
The Code
Registering your module

To extend the Jabber Perl Bot you have to write modules which is inherited from the modules.pm and I recommend that you give modules in the modules/ directory. May you also make your own directory for your module. (I will describe this later)

The Code

Example 1-1. First JPB Module

package	modules::myfirstmodule;

use module;
use vars '@ISA';
@ISA = ("module");

sub hello {
  my ($pkg, %args) = @_;
  main::SendMessage(to => $args{from}, body => 'Hello World !');
}

1;
      

In Example 1-1. You see that the first line defines the name of your module. In this example you have to put it into a file named myfirstmodule.pm in the modules/ directory of your bot.

The next thing is to include the module package so you can inherit from it (@ISA = ("module");)

The important thing is the method hello. You have to register your module in the config.pl with one of these commands: bindm (bind module) or sbind (standard bind) (I will describe it in detail later.) Now look at Example 1-2 for a standardbind of myfirstmodule.

Example 1-2. Register First JPB Module with sbind

sbind('modules::myfirstmodule','hello','^hello');
      

It is not important yet what it does exactly, it just tells the module handler that you have a module modules::myfirstmodule and a method hello which should be called when someone sends a chat message to the bot where body =~ /^hello/ is true.

The important part is that you understand that you have to register your module in the modulehandler and that the modulehandler will call your method. The method will get the following parameters: At first it self and second the arguments of the message. In Table 1-1 is a short summary of the hash.

Table 1-1. Elements of the args hash