#!/usr/bin/perl
use strict;
use POE;
use POE::Component::IRC;
POE::Component::IRC->new("irc_client");
POE::Session->new ( _start => \&irc_start,
irc_join => \&irc_join,
irc_part => \&irc_part,
irc_nick => \&irc_nick,
irc_quit => \&irc_quit,
irc_376 => \&irc_connect,
irc_372 => \&irc_motd,
irc_353 => \&irc_names,
irc_public => \&irc_pub_msg, );
sub irc_start {
my $kernel = $_[KERNEL];
my $heap = $_[HEAP];
my $session = $_[SESSION];
$kernel->refcount_increment( $session->ID(), "my bot");
$kernel->post(irc_client=> register=> "all");
$kernel->post(irc_client=>connect=> { Nick => 'ircbot024',
Username => 'username',
Ircname => 'Metal Shell',
Server => 'irc.homelien.no',
Port => '6667',
}
);
}
sub irc_connect {
my $kernel = $_[KERNEL];
$kernel->post(irc_client=>join=>'#metalshell');
}
sub irc_motd {
my $msg = $_[ARG1];
print "MOTD: $msg\n";
}
sub irc_names {
my $names = (split /:/, $_[ARG1])[1];
my $channel = (split /:/, $_[ARG1])[0];
$channel =~ s/[@|=] (.*?) /$1/;
print "#-> Users on $channel [ $names ]\n";
}
sub irc_nick {
my $oldnick = (split /!/, $_[ARG0])[0];
my $newnick = $_[ARG1];
print "#-> $oldnick is now known as $newnick\n";
}
sub irc_part {
my $nick = (split /!/, $_[ARG0])[0];
my $channel = $_[ARG1];
print "#-> $nick has parted $channel\n";
}
sub irc_join {
my $nick = (split /!/, $_[ARG0])[0];
my $channel = $_[ARG1];
print "#-> $nick has joined $channel\n";
}
sub irc_quit {
my $nick = $_[ARG0];
my $reason = $_[ARG1];
print "#-> $nick has quit ($reason)\n";
}
sub irc_pub_msg{
my $kernel = $_[KERNEL];
my $nick = (split /!/, $_[ARG0])[0];
my $channel = $_[ARG1]->[0];
my $msg = $_[ARG2];
print "$channel: <$nick> $msg\n";
}
$poe_kernel->run();