| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package LiBot::Provider::IRC; |
|
2
|
1
|
|
|
1
|
|
2223
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
42
|
|
|
3
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
34
|
|
|
4
|
1
|
|
|
1
|
|
5
|
use utf8; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
8
|
|
|
5
|
1
|
|
|
1
|
|
1450
|
use AnyEvent::IRC::Client; |
|
|
1
|
|
|
|
|
132339
|
|
|
|
1
|
|
|
|
|
65
|
|
|
6
|
1
|
|
|
1
|
|
14
|
use Encode qw(decode encode); |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
9204
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
14
|
use Mouse; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
15
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has irc => ( |
|
11
|
|
|
|
|
|
|
is => 'rw', |
|
12
|
|
|
|
|
|
|
); |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has [qw(host port)] => ( |
|
15
|
|
|
|
|
|
|
is => 'ro', |
|
16
|
|
|
|
|
|
|
required => 1, |
|
17
|
|
|
|
|
|
|
); |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
has nick => ( |
|
20
|
|
|
|
|
|
|
is => 'ro', |
|
21
|
|
|
|
|
|
|
default => sub { 'libot' }, |
|
22
|
|
|
|
|
|
|
); |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
has encoding => ( |
|
25
|
|
|
|
|
|
|
is => 'ro', |
|
26
|
|
|
|
|
|
|
default => sub { 'utf-8' }, |
|
27
|
|
|
|
|
|
|
); |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
has channels => ( |
|
30
|
|
|
|
|
|
|
is => 'rw', |
|
31
|
|
|
|
|
|
|
); |
|
32
|
|
|
|
|
|
|
|
|
33
|
1
|
|
|
1
|
|
624
|
no Mouse; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
8
|
|
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub _connect { |
|
36
|
0
|
|
|
0
|
|
|
my ($self, $bot) = @_; |
|
37
|
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
my $irc = AnyEvent::IRC::Client->new; |
|
39
|
|
|
|
|
|
|
$irc->reg_cb( |
|
40
|
|
|
|
|
|
|
connect => sub { |
|
41
|
0
|
|
|
0
|
|
|
my ( $con, $err ) = @_; |
|
42
|
0
|
0
|
|
|
|
|
if ( defined $err ) { |
|
43
|
0
|
|
|
|
|
|
warn "connect error: $err\n"; |
|
44
|
0
|
|
|
|
|
|
return; |
|
45
|
|
|
|
|
|
|
} |
|
46
|
0
|
|
|
|
|
|
for (@{Data::OptList::mkopt($self->channels)}) { |
|
|
0
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
$con->send_srv(JOIN => $_->[0], $_->[1]->{key}); |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
} |
|
50
|
0
|
|
|
|
|
|
); |
|
51
|
0
|
|
|
0
|
|
|
$irc->reg_cb( registered => sub { print "I'm in!\n"; } ); |
|
|
0
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
$irc->reg_cb( disconnect => sub { |
|
53
|
0
|
|
|
0
|
|
|
print "I'm out!\n"; |
|
54
|
0
|
|
|
|
|
|
$self->_connect($bot); |
|
55
|
0
|
|
|
|
|
|
} ); |
|
56
|
|
|
|
|
|
|
$irc->reg_cb( |
|
57
|
|
|
|
|
|
|
publicmsg => sub { |
|
58
|
0
|
|
|
0
|
|
|
my ( $irc, $channel, $msg ) = @_; |
|
59
|
0
|
|
|
|
|
|
my $text = decode( $self->encoding, $msg->{params}->[1] ); |
|
60
|
0
|
|
0
|
|
|
|
my ( $nickname, ) = split '!', ( $msg->{prefix} || '' ); |
|
61
|
0
|
|
|
|
|
|
my $message = LiBot::Message->new( |
|
62
|
|
|
|
|
|
|
text => $text, |
|
63
|
|
|
|
|
|
|
nickname => $nickname, |
|
64
|
|
|
|
|
|
|
); |
|
65
|
0
|
|
|
|
|
|
my $proceeded = eval { |
|
66
|
|
|
|
|
|
|
$bot->handle_message( |
|
67
|
|
|
|
|
|
|
sub { |
|
68
|
0
|
|
|
|
|
|
warn $_[0]; |
|
69
|
0
|
|
|
|
|
|
for (grep /\S/, split /\n/, $_[0]) { |
|
70
|
0
|
|
|
|
|
|
$irc->send_chan( $channel, "NOTICE", $channel, encode($self->encoding, $_) ); |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
}, |
|
73
|
0
|
|
|
|
|
|
$message |
|
74
|
|
|
|
|
|
|
); |
|
75
|
|
|
|
|
|
|
}; |
|
76
|
0
|
0
|
|
|
|
|
if ($@) { |
|
77
|
0
|
|
|
|
|
|
print STDERR $@; |
|
78
|
0
|
|
|
|
|
|
die $@; |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
else { |
|
81
|
0
|
0
|
|
|
|
|
if ($proceeded) { |
|
82
|
0
|
|
|
|
|
|
return; |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
} |
|
86
|
0
|
|
|
|
|
|
); |
|
87
|
0
|
|
|
|
|
|
$irc->connect( $self->host, $self->port, { nick => $self->nick } ); |
|
88
|
0
|
|
|
|
|
|
$irc->enable_ping(10); |
|
89
|
0
|
|
|
|
|
|
$self->irc($irc); |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub run { |
|
93
|
0
|
|
|
0
|
0
|
|
my ($self, $bot) = @_; |
|
94
|
0
|
|
|
|
|
|
$self->_connect($bot); |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
1; |
|
98
|
|
|
|
|
|
|
|