Debian Codegraph @

samples/anyeventirccl

raw
1 #!/usr/bin/env perl
2 use common::sense;
3 use AnyEvent::IRC::Client;
4
5 my $c = AnyEvent->condvar;
6
7 my $pc = AnyEvent::IRC::Client->new;
8
9 $pc->reg_cb (
10 irc_privmsg => sub {
11 my ($self, $msg) = @_;
12
13 if ($msg->{params}->[-1] =~ m/net_irc3:\s*(.*)/) {
14 $pc->send_chan ("#test", "PRIVMSG", "#test", "yes?");
15 }
16 }
17 );
18
19 $pc->reg_cb (
20 channel_add => sub {
21 my ($self, $msg, $chan, @nicks) = @_;
22 my $nick = join ",", @nicks;
23
24 print "$chan += $nick\n";
25 print "chans: " . (join ";", keys %{$self->channel_list}) ."\n";
26 print "nicks: " . (join ";", keys %{$self->channel_list ()->{$chan}}) ."\n";
27 },
28 channel_remove => sub {
29 my ($self, $msg, $chan, @nicks) = @_;
30 my $nick = join ",", @nicks;
31
32 print "$chan -= $nick\n";
33 print "chans: " . (join ";", keys %{$self->channel_list}) ."\n";
34 print "nicks: " . (join ";", keys %{$self->channel_list ()->{$chan}}) ."\n";
35 }
36 );
37
38 $pc->reg_cb (
39 connect => sub {
40 my ($pc, $err) = @_;
41 if (defined $err) {
42 print "Couldn't connect to server: $err\n";
43 }
44 },
45 registered => sub {
46 my ($self) = @_;
47 print "registered!\n";
48 $pc->enable_ping (60);
49 },
50 disconnect => sub {
51 print "disconnected: $_[1]!\n";
52 }
53 );
54
55 # these commands will queue until the connection
56 # is completly registered and has a valid nick etc.
57 $pc->send_srv ("JOIN", "#test");
58 $pc->send_chan ("#test", "PRIVMSG", "#test", "hi, i'm a bot!");
59
60 $pc->connect (
61 "irc.freenode.net", 6667, { nick => 'net_irc3', user => 'net_irc3', real => 'test bot' }
62 );
63
64 $c->wait;