NAME

Bot::Jabbot::Modules - Jabbot Modules

Jabbot Modules

This documentation provides an overview of writing new module for Bot::Jabbot.

Basic example

  package Bot::Jabbot::Module::Replier;
  use base qw(Bot::Jabbot::Module);
  use warnings;
  use strict;
  
  use AnyEvent;

  sub help
  {
      return "some help text";
  }
  
  sub init
  {
      my ($self,$cl,$jid)=@_;
      $self->{timer} = AnyEvent->timer (after => 5, interval => 10, cb => sub {
          $self->timer($cl,$jid);
       });
      return 0;
  }
  
  sub timer
  {
      #do something good
  }
  
  sub message {
      my ($self,$from,$body) = @_;
      return unless defined $body;
      return "wtf?";
  }
  
  sub muc {
      my ($self,$from,$body) = @_;
      return unless defined $body;
      return "wtf?";
  }
  1;

Basics

Any Bot::Jabbot module should use Bot::Jabbot::Module as it's base

  package Bot::Jabbot::Module::Replier;
  use base qw(Bot::Jabbot::Module);

or provide a new() and init() methods.

Methods to override

init(self,connection, jid)

Called on bot start, usefull for defining a timers, getting data from db, etc. Should return 0 on success, or error text on error

self

reference to module object

connection

An AnyEcent::XMPP::Connection assotiated with bot

jid

Bot jid

help()

If your module provides any private command, this method should return description on how to use it

muc_help()

If your module provides any MUC command, this method should return description on how to use it

muc(self,msg,botnick,bot)

called on MUC message

self

reference to module object

msg

AnyEvent::XMPP::Ext::MUC::Message object

botnick

nick of bot in MUC room

bot

reference to bot object

returns: reply text or undef.

message(self,msg,bot);

called on private message

self

reference to module object

msg

AnyEvent::XMPP::Message object

bot

reference to bot object

returns: reply text or undef.

Localisation

You can (and should) use $self->loc() method for retrieving localized strings Translations should be placed into ModuleName/I18N/ subdirectory in the directory that contains module.