Bot-Jabbot

 view release on metacpan or  search on metacpan

lib/Bot/Modules.pod  view on Meta::CPAN

#============================================================= -*-perl-*-
#
# Bot::Jabbot::Modules
#
# DESCRIPTION
#
# How to write module for Jabbot
#
# AUTHOR
#   Epifanov Ivan  <isage@aumi.ru>
#
# COPYRIGHT
#
#   This module copyright (c) 2009 Ivan Epifanov.
#   All rights reserved. This module is free software; you can redistribute it
#   and/or modify it under the terms of the Perl Artistic License.
#   (see http://www.perl.com/perl/misc/Artistic.html)
#
#========================================================================

=head1 NAME

Bot::Jabbot::Modules - Jabbot Modules

=head1 Jabbot Modules

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

=head2 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;


=head2 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.

=head2 Methods to override

=head3 init(self,connection, jid)

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

=over 4

=item B<self>

reference to module object

=item B<connection>

An AnyEvent::XMPP::Connection assotiated with bot

=item B<jid>

Bot jid

=back


=head3 help()

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

=head3 muc_help()

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

=head3 muc(self,msg,botnick,bot)

called on MUC message

=over 4

=item B<self>

reference to module object

=item B<msg>

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

=item B<botnick>

nick of bot in MUC room

=item B<bot>

reference to bot object

=back

returns: reply text or undef.

=head3 muc_join(self,user,room,connection);

called when user joins room

=over 4

=item B<self>



( run in 0.537 second using v1.01-cache-2.11-cpan-13bb782fe5a )