3.2. API introduction

In order to create a module you must start by defining your module class and tell Wollabot to register it. This is done like this:

class MyModule extends Wollabot_Module {

  function MyModule () {
    // Constructor for your module
  }

}

$wollabot->register_module("MyModule");
    

This is pretty much the most simple module you can make. It does completely nothing. In order to add some functionality, we need to use a bind-method. We have quite a few bind-methods, but in our example we will use bind_prefix() for the sake of simplicity. The methods bind_prefix() binds a user-defined method in the current class to a given prefix in a IRC message (either channel, query or notice). It takes two arguments: method and prefix. Let us start out by making a greet function, that greet everyone who writes 'hello' in your channel.

class MyModule extends Wollabot_Module {

  function MyModule () {
    $this->bind_prefix('say_hello', 'hello');
  }

  function say_hello ($data) {
    $this->send_privmsg($data['channel'], "Hello ".$data['nick']);
  }

}

$wollabot->register_module("MyModule");
    

Here we see how the method say_hello() take exactly one argument, being an array of data from the IRC message that triggered it. The data array consists of the following elements:

$data['from']             => The user who sent the message (in the form of nick!user@host
$data['nick']             => The nickname of the user who sent the message
$data['ident']            => The ident of the user who sent the message (username)
$data['host']             => The host of the user who sent the message
$data['channel']          => The channel in which the message was written (if given)
$data['message']          => The actual message
$data['message_exploded'] => The actual mesasge exploded by space
$data['type']             => The message type - refer to WOLLABOT_TYPE_* constants
$data['raw']              => The raw message directly from socket
$data['raw_exploded']     => The raw message directly from socket exploded by space