| 1 |
#!/usr/bin/env perl |
| 2 |
use common::sense; |
| 3 |
use AnyEvent; |
| 4 |
use AnyEvent::IRC::Client; |
| 5 |
|
| 6 |
my $c = AnyEvent->condvar; |
| 7 |
|
| 8 |
my $con = new AnyEvent::IRC::Client; |
| 9 |
|
| 10 |
$con->reg_cb ( |
| 11 |
connect => sub { |
| 12 |
my ($con, $err) = @_; |
| 13 |
|
| 14 |
if (defined $err) { |
| 15 |
warn "Couldn't connect: $err\n"; |
| 16 |
$c->send; |
| 17 |
} else { |
| 18 |
print "Connected!\n"; |
| 19 |
} |
| 20 |
|
| 21 |
$con->register (qw/testbot testbot testbot/); |
| 22 |
}, |
| 23 |
registered => sub { |
| 24 |
my ($con) = @_; |
| 25 |
print "I'm in!\n"; |
| 26 |
|
| 27 |
$con->reg_cb (buffer_empty => sub { |
| 28 |
my ($con) = @_; |
| 29 |
$con->unreg_me; |
| 30 |
$con->disconnect ("Message delivered!"); |
| 31 |
}); |
| 32 |
$con->send_msg ( |
| 33 |
PRIVMSG => 'elmex', "Hello there i'm the cool AnyEvent::IRC test script!" |
| 34 |
); |
| 35 |
}, |
| 36 |
disconnect => sub { |
| 37 |
print "I'm out ($_[1])!\n"; |
| 38 |
$c->send |
| 39 |
}, |
| 40 |
); |
| 41 |
|
| 42 |
$con->connect ("localhost", 6667); |
| 43 |
|
| 44 |
$c->recv; |