use strict;
use warnings;
use AnyEvent;
use AnyEvent::IRC;
use AnyEvent::IRC::Connection;
use AnyEvent::IRC::Client;
use Test::More;
use YAML;
my $chan = shift @ARGV or die "Usage: $0 #chan";
# -------------------------------------------------------------------------
my $c = AnyEvent->condvar;
my $con;
my $t;
$t = AnyEvent->timer (after => 40, cb => sub {
fail "timeout";
$con->disconnect ("Timeout exceeded");
undef $t;
});
diag 'start connection';
$con = AnyEvent::IRC::Client->new;
$con->reg_cb(
'connect' => sub {
my ( $con, $err ) = @_;
if ( defined $err ) {
BAIL_OUT "Connect ERROR! => $err\n";
$c->broadcast;
}
else {
note "Connected! Yay!\n";
}
$con->send_msg ("NICK", 'test');
$con->send_msg ("USER", 'test', "*", "0", 'test');
},
registered => sub {
my ($self) = @_;
note "registered!\n";
$con->enable_ping (60);
$con->send_srv("JOIN", $chan);
$con->send_chan($chan, "PRIVMSG", $chan, "hi, i'm a bot!");
},
irc_001 => sub {
note 'irc_001';
},
irc_privmsg => sub {
my ($self, $msg) = @_;
print Dump($msg);
},
disconnect => sub {
BAIL_OUT "Oh, got a disconnect: $_[1], exiting...\n";
}
);
$con->connect( 'irc.freenode.net', 6667,
{ nick => 'bee', 'user' => 'bee', real => 'the bot' } );
local $SIG{INT} = sub { BAIL_OUT "SIGINT" };
$c->recv;
done_testing;