Bot-BasicBot
view release on metacpan or search on metacpan
lib/Bot/BasicBot.pm view on Meta::CPAN
package Bot::BasicBot;
our $AUTHORITY = 'cpan:BIGPRESH';
$Bot::BasicBot::VERSION = '0.93';
use strict;
use warnings;
use Carp;
use Encode qw(encode);
use Exporter;
use IRC::Utils qw(decode_irc);
use POE::Kernel;
use POE::Session;
use POE::Wheel::Run;
use POE::Filter::Line;
use POE::Component::IRC::State;
use POE::Component::IRC::Plugin::Connector;
use Text::Wrap ();
use base 'Exporter';
our @EXPORT = qw(say emote);
sub new {
my $class = shift;
my $self = bless {}, $class;
$self->{IRCNAME} = 'wanna'.int(rand(100000));
$self->{ALIASNAME} = 'pony'.int(rand(100000));
# call the set methods
my %args = @_;
for my $method (keys %args) {
if ($self->can($method)) {
$self->$method($args{$method});
}
else {
$self->{$method} = $args{$method};
#croak "Invalid argument '$method'";
}
}
$self->{charset} = 'utf8' if !defined $self->{charset};
$self->init or die "init did not return a true value - dying";
return $self;
}
sub run {
my $self = shift;
# create the callbacks to the object states
POE::Session->create(
object_states => [
$self => {
_start => "start_state",
die => "die_state",
irc_001 => "irc_001_state",
irc_msg => "irc_said_state",
irc_public => "irc_said_state",
irc_ctcp_action => "irc_emoted_state",
irc_notice => "irc_noticed_state",
irc_disconnected => "irc_disconnected_state",
irc_error => "irc_error_state",
irc_join => "irc_chanjoin_state",
irc_part => "irc_chanpart_state",
irc_kick => "irc_kicked_state",
irc_nick => "irc_nick_state",
irc_quit => "irc_quit_state",
irc_mode => "irc_mode_state",
fork_close => "fork_close_state",
fork_error => "fork_error_state",
irc_366 => "names_done_state",
irc_332 => "topic_raw_state",
irc_topic => "topic_state",
irc_shutdown => "shutdown_state",
irc_raw => "irc_raw_state",
irc_raw_out => "irc_raw_out_state",
tick => "tick_state",
}
]
);
# and say that we want to recive said messages
$poe_kernel->post($self->{IRCNAME}, 'register', 'all');
# run
$poe_kernel->run() if !$self->{no_run};
return;
}
sub init { return 1; }
sub said { return }
sub emoted {
return shift->said(@_);
}
sub noticed {
return shift->said(@_);
}
( run in 2.110 seconds using v1.01-cache-2.11-cpan-140bd7fdf52 )