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 AnyEvent::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.
muc_join(self,user,room,connection);
called when user joins room
- self
-
reference to module object
- user
-
reference to object of joined user
- room
-
AnyEvent::XMPP::Ext::MUC::Room object
- connection
-
An AnyEvent::XMPP::Connection assotiated with bot
muc_part(self,user,room,connection);
called when user parts room (or banned, or kicked).
- self
-
reference to module object
- user
-
reference to object of parted user
- room
-
AnyEvent::XMPP::Ext::MUC::Room object
- connection
-
An AnyEvent::XMPP::Connection assotiated with bot
muc_subject_change(self,room,msg,connection);
called when someone changes conference subject.
- self
-
reference to module object
- room
-
AnyEvent::XMPP::Ext::MUC::Room object
- msg
-
AnyEvent::XMPP::Message object
- connection
-
An AnyEvent::XMPP::Connection assotiated with bot
muc_presence(self,user,room,connection);
called when someone changes conference subject.
- self
-
reference to module object
- room
-
AnyEvent::XMPP::Ext::MUC::Room object
- user
-
AnyEvent::XMPP::Ext::MUC::User object
- connection
-
An AnyEvent::XMPP::Connection assotiated with bot
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.