line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package POE::Component::IRC::Plugin::BaseWrap; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
204360
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
4
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
39
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '1.001001'; # VERSION |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
64
|
|
9
|
1
|
|
|
1
|
|
5
|
use POE; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
10
|
1
|
|
|
1
|
|
306
|
use POE::Component::IRC::Plugin qw(:ALL); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1550
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
0
|
|
|
0
|
0
|
|
my $package = shift; |
14
|
0
|
0
|
|
|
|
|
croak "Even number of arguments must be specified" |
15
|
|
|
|
|
|
|
if @_ & 1; |
16
|
0
|
|
|
|
|
|
my %args = @_; |
17
|
0
|
|
|
|
|
|
$args{ lc $_ } = delete $args{ $_ } for keys %args; |
18
|
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
my $self = bless {}, $package; |
20
|
|
|
|
|
|
|
# fill in the defaults |
21
|
0
|
|
|
|
|
|
%args = ( |
22
|
|
|
|
|
|
|
debug => 0, |
23
|
|
|
|
|
|
|
auto => 1, |
24
|
|
|
|
|
|
|
response_event => 'irc_basewrap', |
25
|
|
|
|
|
|
|
banned => [], |
26
|
|
|
|
|
|
|
addressed => 1, |
27
|
|
|
|
|
|
|
eat => 1, |
28
|
|
|
|
|
|
|
response_types => { |
29
|
|
|
|
|
|
|
public => 'public', |
30
|
|
|
|
|
|
|
privmsg => 'privmsg', |
31
|
|
|
|
|
|
|
notice => 'notice', |
32
|
|
|
|
|
|
|
}, |
33
|
|
|
|
|
|
|
listen_for_input => [ qw(public notice privmsg) ], |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
$self->_make_default_args, |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
%args, |
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
0
|
|
|
|
$args{response_types}{public} ||= 'public'; |
41
|
0
|
|
0
|
|
|
|
$args{response_types}{privmsg} ||= 'privmsg'; |
42
|
0
|
|
0
|
|
|
|
$args{response_types}{notice} ||= 'notice'; |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
$args{listen_for_input} = { |
45
|
0
|
0
|
|
|
|
|
map { $_ => 1 } @{ $args{listen_for_input} || [] } |
|
0
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
}; |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
for ( keys %{ $args{triggers} } ) { |
|
0
|
|
|
|
|
|
|
49
|
0
|
0
|
0
|
|
|
|
if ( $_ ne 'public' and $_ ne 'notice' and $_ ne 'privmsg' ) { |
|
|
|
0
|
|
|
|
|
50
|
0
|
|
|
|
|
|
croak "Invalid key [$_] in {triggers}, must be either" |
51
|
|
|
|
|
|
|
. " 'public', 'privmsg' or 'notice'"; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
0
|
0
|
0
|
|
|
|
if ( not exists $args{trigger} and ref $args{triggers} ne 'HASH' ) { |
56
|
0
|
|
|
|
|
|
croak "Neither 'trigger' nor 'triggers' arguments were specified"; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
$self->{ $_ } = delete $args{ $_ } for keys %args; |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
return $self; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub PCI_register { |
65
|
0
|
|
|
0
|
0
|
|
my ( $self, $irc ) = splice @_, 0, 2; |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
$self->{irc} = $irc; |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
$irc->plugin_register( $self, 'SERVER', qw(public notice msg) ); |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
return 1; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub PCI_unregister { |
75
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
delete $self->{irc}; |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
return 1; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub S_public { |
83
|
0
|
|
|
0
|
0
|
|
my ( $self, $irc ) = splice @_, 0, 2; |
84
|
0
|
|
|
|
|
|
my $who = ${ $_[0] }; |
|
0
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
my $channel = ${ $_[1] }->[0]; |
|
0
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
my $message = ${ $_[2] }; |
|
0
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
return $self->_parse_input( $irc, $who, $channel, $message, 'public' ); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub S_notice { |
91
|
0
|
|
|
0
|
0
|
|
my ( $self, $irc ) = splice @_, 0, 2; |
92
|
0
|
|
|
|
|
|
my $who = ${ $_[0] }; |
|
0
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
my $channel = ${ $_[1] }->[0]; |
|
0
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
my $message = ${ $_[2] }; |
|
0
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
return $self->_parse_input( $irc, $who, $channel, $message, 'notice' ); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub S_msg { |
99
|
0
|
|
|
0
|
0
|
|
my ( $self, $irc ) = splice @_, 0, 2; |
100
|
0
|
|
|
|
|
|
my $who = ${ $_[0] }; |
|
0
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
my $channel = ${ $_[1] }->[0]; |
|
0
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
my $message = ${ $_[2] }; |
|
0
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
|
return $self->_parse_input( $irc, $who, $channel, $message, 'privmsg' ); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub _parse_input { |
107
|
0
|
|
|
0
|
|
|
my ( $self, $irc, $who, $channel, $message, $type ) = @_; |
108
|
|
|
|
|
|
|
|
109
|
0
|
0
|
|
|
|
|
warn "Got input: [ who => $who, channel => $channel, " |
110
|
|
|
|
|
|
|
. "mesage => $message ]" |
111
|
|
|
|
|
|
|
if $self->{debug}; |
112
|
|
|
|
|
|
|
|
113
|
0
|
0
|
|
|
|
|
return PCI_EAT_NONE |
114
|
|
|
|
|
|
|
unless exists $self->{listen_for_input}{ $type }; |
115
|
|
|
|
|
|
|
|
116
|
0
|
|
|
|
|
|
my $what; |
117
|
0
|
0
|
0
|
|
|
|
if ( $self->{addressed} and $type eq 'public' ) { |
118
|
0
|
|
|
|
|
|
my $my_nick = $irc->nick_name(); |
119
|
0
|
|
|
|
|
|
($what) = $message =~ m/^\s*\Q$my_nick\E[\:\,\;\.]?\s*(.*)$/i; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
else { |
122
|
0
|
|
|
|
|
|
$what = $message; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
0
|
0
|
|
|
|
|
return PCI_EAT_NONE |
126
|
|
|
|
|
|
|
unless defined $what; |
127
|
|
|
|
|
|
|
|
128
|
0
|
0
|
0
|
|
|
|
return PCI_EAT_NONE |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
129
|
|
|
|
|
|
|
unless ( |
130
|
|
|
|
|
|
|
( exists $self->{triggers}{ $type } |
131
|
|
|
|
|
|
|
and $what =~ s/$self->{triggers}{$type}// |
132
|
|
|
|
|
|
|
) |
133
|
|
|
|
|
|
|
or |
134
|
|
|
|
|
|
|
( exists $self->{trigger} and $what =~ s/$self->{trigger}// ) |
135
|
|
|
|
|
|
|
); |
136
|
|
|
|
|
|
|
|
137
|
0
|
|
|
|
|
|
$what =~ s/^\s+|\s+$//g; |
138
|
|
|
|
|
|
|
|
139
|
0
|
0
|
|
|
|
|
warn "Matched trigger: [ who => $who, channel => $channel, " |
140
|
|
|
|
|
|
|
. "what => $what ]" |
141
|
|
|
|
|
|
|
if $self->{debug}; |
142
|
|
|
|
|
|
|
|
143
|
0
|
0
|
|
|
|
|
if ( exists $self->{root} ) { |
144
|
0
|
|
|
|
|
|
return PCI_EAT_NONE |
145
|
0
|
0
|
|
|
|
|
unless grep { $who =~ /$_/ } @{ $self->{root} || [] }; |
|
0
|
0
|
|
|
|
|
|
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
0
|
0
|
|
|
|
|
foreach my $ban_re ( @{ $self->{banned} || [] } ) { |
|
0
|
|
|
|
|
|
|
149
|
0
|
0
|
|
|
|
|
return PCI_EAT_NONE |
150
|
|
|
|
|
|
|
if $who =~ /$ban_re/; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
$self->_do_response( { |
154
|
0
|
|
|
|
|
|
what => $what, |
155
|
|
|
|
|
|
|
who => $who, |
156
|
|
|
|
|
|
|
channel => $channel, |
157
|
|
|
|
|
|
|
message => $message, |
158
|
|
|
|
|
|
|
type => $type, |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
); |
161
|
|
|
|
|
|
|
|
162
|
0
|
0
|
|
|
|
|
return $self->{eat} ? PCI_EAT_ALL : PCI_EAT_NONE; |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
sub _do_response { |
166
|
0
|
|
|
0
|
|
|
my ( $self, $in_ref ) = @_; |
167
|
|
|
|
|
|
|
|
168
|
0
|
|
|
|
|
|
my $response_message = $self->_make_response_message( $in_ref ); |
169
|
|
|
|
|
|
|
|
170
|
0
|
|
|
|
|
|
my $event_response; |
171
|
0
|
0
|
|
|
|
|
if ( my $key = $self->_message_into_response_event( $in_ref ) ) { |
172
|
0
|
0
|
|
|
|
|
if ( ref $key eq 'ARRAY' ) { |
173
|
0
|
|
|
|
|
|
$in_ref->{ $key->[0] } = $response_message; |
174
|
0
|
|
|
|
|
|
%$in_ref = ( |
175
|
|
|
|
|
|
|
%$in_ref, |
176
|
0
|
|
|
|
|
|
%{ $key->[1] }, |
177
|
|
|
|
|
|
|
); |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
else { |
180
|
0
|
|
|
|
|
|
$in_ref->{ $key } = $response_message; |
181
|
|
|
|
|
|
|
} |
182
|
0
|
|
|
|
|
|
$event_response = $in_ref; |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
else { |
185
|
0
|
|
|
|
|
|
$event_response = $self->_make_response_event( $in_ref ); |
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
|
188
|
0
|
|
|
|
|
|
$self->{irc}->send_event( |
189
|
|
|
|
|
|
|
$self->{response_event} => $event_response, |
190
|
|
|
|
|
|
|
); |
191
|
|
|
|
|
|
|
|
192
|
0
|
0
|
|
|
|
|
if ( $self->{auto} ) { |
193
|
0
|
|
|
|
|
|
$in_ref->{type} = $self->{response_types}{ $in_ref->{type} }; |
194
|
|
|
|
|
|
|
|
195
|
0
|
0
|
|
|
|
|
my $response_type = $in_ref->{type} eq 'public' |
196
|
|
|
|
|
|
|
? 'privmsg' |
197
|
|
|
|
|
|
|
: $in_ref->{type}; |
198
|
|
|
|
|
|
|
|
199
|
0
|
0
|
|
|
|
|
my $where = $in_ref->{type} eq 'public' |
200
|
|
|
|
|
|
|
? $in_ref->{channel} |
201
|
|
|
|
|
|
|
: (split /!/, $in_ref->{who})[0]; |
202
|
|
|
|
|
|
|
|
203
|
0
|
0
|
|
|
|
|
for ( |
204
|
|
|
|
|
|
|
ref $response_message eq 'ARRAY' ? @$response_message |
205
|
|
|
|
|
|
|
: ( $response_message ) |
206
|
|
|
|
|
|
|
) { |
207
|
0
|
|
|
|
|
|
$poe_kernel->post( $self->{irc} => |
208
|
|
|
|
|
|
|
$response_type => |
209
|
|
|
|
|
|
|
$where => |
210
|
|
|
|
|
|
|
$_ |
211
|
|
|
|
|
|
|
); |
212
|
|
|
|
|
|
|
} |
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
|
215
|
0
|
|
|
|
|
|
undef; |
216
|
|
|
|
|
|
|
} |
217
|
|
|
|
|
|
|
|
218
|
0
|
|
|
0
|
|
|
sub _message_into_response_event { undef; } |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
1; |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
__END__ |