line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package UnazuSan; |
2
|
2
|
|
|
2
|
|
33628
|
use 5.010; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
79
|
|
3
|
2
|
|
|
2
|
|
11
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
78
|
|
4
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
2
|
|
|
|
|
12
|
|
|
2
|
|
|
|
|
91
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = "0.03"; |
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
1909
|
use AnySan; |
|
2
|
|
|
|
|
32324
|
|
|
2
|
|
|
|
|
67
|
|
9
|
2
|
|
|
2
|
|
1914
|
use AnySan::Provider::IRC; |
|
2
|
|
|
|
|
233376
|
|
|
2
|
|
|
|
|
146
|
|
10
|
2
|
|
|
2
|
|
24
|
use Encode qw/decode_utf8/; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
2197
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
0
|
|
|
0
|
0
|
0
|
my $class = shift; |
14
|
0
|
0
|
|
|
|
0
|
my %args = @_ == 1 ? %{$_[0]} : @_; |
|
0
|
|
|
|
|
0
|
|
15
|
0
|
|
|
|
|
0
|
my $self = bless \%args, $class; |
16
|
|
|
|
|
|
|
|
17
|
0
|
|
0
|
|
|
0
|
$self->{nickname} //= 'unazu_san'; |
18
|
0
|
|
0
|
|
|
0
|
$self->{port} ||= 6667; |
19
|
0
|
|
0
|
|
|
0
|
$self->{post_interval} //= 2; |
20
|
0
|
|
0
|
|
|
0
|
$self->{reconnect_interval} //= 3; |
21
|
0
|
|
0
|
|
|
0
|
$self->{receive_commands} //= ['PRIVMSG']; |
22
|
|
|
|
|
|
|
|
23
|
0
|
|
|
|
|
0
|
my ($irc, $is_connect, $connector); |
24
|
|
|
|
|
|
|
$connector = sub { |
25
|
|
|
|
|
|
|
irc |
26
|
|
|
|
|
|
|
$self->{host}, |
27
|
|
|
|
|
|
|
port => $self->{port}, |
28
|
|
|
|
|
|
|
key => $self->{keyword}, |
29
|
|
|
|
|
|
|
password => $self->{password}, |
30
|
|
|
|
|
|
|
nickname => $self->{nickname}, |
31
|
|
|
|
|
|
|
user => $self->{user}, |
32
|
|
|
|
|
|
|
interval => $self->{post_interval}, |
33
|
|
|
|
|
|
|
enable_ssl => $self->{enable_ssl}, |
34
|
|
|
|
|
|
|
recive_commands => $self->{receive_commands}, |
35
|
|
|
|
|
|
|
on_connect => sub { |
36
|
0
|
|
|
|
|
0
|
my ($con, $err) = @_; |
37
|
0
|
0
|
|
|
|
0
|
if (defined $err) { |
38
|
0
|
|
|
|
|
0
|
warn "connect error: $err\n"; |
39
|
0
|
0
|
|
|
|
0
|
exit 1 unless $self->{reconnect_interval}; |
40
|
0
|
|
|
|
|
0
|
sleep $self->{reconnect_interval}; |
41
|
0
|
|
|
|
|
0
|
$con->disconnect('try reconnect'); |
42
|
|
|
|
|
|
|
} else { |
43
|
0
|
|
|
|
|
0
|
warn 'connect'; |
44
|
0
|
|
|
|
|
0
|
$is_connect = 1; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
}, |
47
|
|
|
|
|
|
|
on_disconnect => sub { |
48
|
0
|
|
|
|
|
0
|
warn 'disconnect'; |
49
|
|
|
|
|
|
|
# XXX: bad hack... |
50
|
0
|
|
|
|
|
0
|
undef $irc->{client}; |
51
|
0
|
|
|
|
|
0
|
undef $irc->{SEND_TIMER}; |
52
|
0
|
|
|
|
|
0
|
undef $irc; |
53
|
0
|
|
|
|
|
0
|
$is_connect = 0; |
54
|
0
|
|
|
|
|
0
|
$irc = $connector->(); |
55
|
|
|
|
|
|
|
}, |
56
|
0
|
|
|
|
|
0
|
channels => { |
57
|
0
|
0
|
|
0
|
|
0
|
map { my $chan = $_; $chan = '#'.$chan unless $chan =~ /^#/; ;($chan => +{}) } @{ $self->{join_channels} || [] }, |
|
0
|
0
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
58
|
|
|
|
|
|
|
}; |
59
|
0
|
|
|
|
|
0
|
}; |
60
|
0
|
|
|
|
|
0
|
$irc = $connector->(); |
61
|
0
|
|
|
|
|
0
|
$self->{irc} = $irc; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
AnySan->register_listener( |
64
|
|
|
|
|
|
|
echo => { |
65
|
|
|
|
|
|
|
cb => sub { |
66
|
0
|
|
|
0
|
|
0
|
my $receive = shift; |
67
|
0
|
|
|
|
|
0
|
$receive->{message} = decode_utf8 $receive->{message}; |
68
|
0
|
|
|
|
|
0
|
$self->_respond($receive); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
0
|
|
|
|
|
0
|
); |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
0
|
$self; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub on_message { |
77
|
0
|
|
|
0
|
0
|
0
|
my ($self, @jobs) = @_; |
78
|
0
|
|
|
|
|
0
|
while (my ($reg, $sub) = splice @jobs, 0, 2) { |
79
|
0
|
|
|
|
|
0
|
push @{ $self->_reactions }, [$reg, $sub]; |
|
0
|
|
|
|
|
0
|
|
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub on_command { |
84
|
0
|
|
|
0
|
0
|
0
|
my ($self, @jobs) = @_; |
85
|
0
|
|
|
|
|
0
|
while (my ($command, $sub) = splice @jobs, 0, 2) { |
86
|
0
|
|
|
|
|
0
|
my $reg = _build_command_reg($self->{nickname}, $command); |
87
|
0
|
|
|
|
|
0
|
push @{ $self->_reactions }, [$reg, $sub, $command]; |
|
0
|
|
|
|
|
0
|
|
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub _build_command_reg { |
92
|
1
|
|
|
1
|
|
10
|
my ($nick, $command) = @_; |
93
|
|
|
|
|
|
|
|
94
|
1
|
|
|
|
|
9
|
my $prefix = '^\s*'.quotemeta($nick). '_*[:\s]\s*' . quotemeta($command); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub run { |
98
|
0
|
|
|
0
|
0
|
0
|
AnySan->run; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
0
|
0
|
0
|
sub respond_all { shift->{respond_all} } |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub _reactions { |
104
|
0
|
|
0
|
0
|
|
0
|
shift->{_reactions} ||= []; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub _respond { |
108
|
0
|
|
|
0
|
|
0
|
my ($self, $receive) = @_; |
109
|
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
0
|
my $message = $receive->message; |
111
|
0
|
|
|
|
|
0
|
$message =~ s/^\s+//; $message =~ s/\s+$//; |
|
0
|
|
|
|
|
0
|
|
112
|
0
|
|
|
|
|
0
|
for my $reaction (@{ $self->_reactions }) { |
|
0
|
|
|
|
|
0
|
|
113
|
0
|
|
|
|
|
0
|
my ($reg, $sub, $command) = @$reaction; |
114
|
|
|
|
|
|
|
|
115
|
0
|
0
|
|
|
|
0
|
if (my @matches = $message =~ $reg) { |
116
|
0
|
0
|
|
|
|
0
|
if (defined $command) { |
117
|
0
|
|
|
|
|
0
|
@matches = _build_command_args($reg, $message); |
118
|
|
|
|
|
|
|
} |
119
|
0
|
|
|
|
|
0
|
$sub->($receive, @matches); |
120
|
0
|
0
|
|
|
|
0
|
return unless $self->respond_all; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub _build_command_args { |
126
|
2
|
|
|
2
|
|
3348
|
my ($reg, $mes) = @_; |
127
|
2
|
|
|
|
|
43
|
$mes =~ s/$reg//; |
128
|
2
|
|
|
|
|
6
|
$mes =~ s/^\s+//; $mes =~ s/\s+$//; |
|
2
|
|
|
|
|
7
|
|
129
|
2
|
|
|
|
|
16
|
split /\s+/, $mes; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
package # hide from pause |
133
|
|
|
|
|
|
|
AnySan::Receive; |
134
|
|
|
|
|
|
|
|
135
|
2
|
|
|
2
|
|
14
|
use Encode qw/encode_utf8/; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
204
|
|
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub reply { |
138
|
0
|
|
|
0
|
0
|
|
my ($self, $msg) = @_; |
139
|
0
|
|
|
|
|
|
$self->send_reply(encode_utf8 $msg); |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
1; |
143
|
|
|
|
|
|
|
__END__ |