File: anyeventirccl

package info (click to toggle)
libanyevent-irc-perl 0.96-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 284 kB
  • sloc: perl: 1,588; makefile: 2
file content (64 lines) | stat: -rwxr-xr-x 1,604 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env perl
use common::sense;
use AnyEvent::IRC::Client;

my $c = AnyEvent->condvar;

my $pc = AnyEvent::IRC::Client->new;

$pc->reg_cb (
   irc_privmsg => sub {
      my ($self, $msg) = @_;

      if ($msg->{params}->[-1] =~ m/net_irc3:\s*(.*)/) {
         $pc->send_chan ("#test", "PRIVMSG", "#test", "yes?");
      }
   }
);

$pc->reg_cb (
   channel_add => sub {
      my ($self, $msg, $chan, @nicks) = @_;
      my $nick = join ",", @nicks;

      print "$chan += $nick\n";
      print "chans: " . (join ";", keys %{$self->channel_list}) ."\n";
      print "nicks: " . (join ";", keys %{$self->channel_list ()->{$chan}}) ."\n";
   },
   channel_remove => sub {
      my ($self, $msg, $chan, @nicks) = @_;
      my $nick = join ",", @nicks;

      print "$chan -= $nick\n";
      print "chans: " . (join ";", keys %{$self->channel_list}) ."\n";
      print "nicks: " . (join ";", keys %{$self->channel_list ()->{$chan}}) ."\n";
   }
);

$pc->reg_cb (
   connect => sub {
      my ($pc, $err) = @_;
      if (defined $err) {
         print "Couldn't connect to server: $err\n";
      }
   },
   registered => sub {
      my ($self) = @_;
      print "registered!\n";
      $pc->enable_ping (60);
   },
   disconnect => sub {
      print "disconnected: $_[1]!\n";
   }
);

# these commands will queue until the connection
# is completly registered and has a valid nick etc.
$pc->send_srv ("JOIN", "#test");
$pc->send_chan ("#test", "PRIVMSG", "#test", "hi, i'm a bot!");

$pc->connect (
   "irc.freenode.net", 6667, { nick => 'net_irc3', user => 'net_irc3', real => 'test bot' }
);

$c->wait;