line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package POE::Component::IRC::Plugin::CTCP; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:HINRIK'; |
3
|
|
|
|
|
|
|
$POE::Component::IRC::Plugin::CTCP::VERSION = '6.92'; |
4
|
7
|
|
|
7
|
|
2795
|
use strict; |
|
7
|
|
|
|
|
19
|
|
|
7
|
|
|
|
|
304
|
|
5
|
7
|
|
|
7
|
|
37
|
use warnings FATAL => 'all'; |
|
7
|
|
|
|
|
16
|
|
|
7
|
|
|
|
|
393
|
|
6
|
7
|
|
|
7
|
|
46
|
use Carp; |
|
7
|
|
|
|
|
50
|
|
|
7
|
|
|
|
|
565
|
|
7
|
7
|
|
|
7
|
|
50
|
use POE::Component::IRC; |
|
7
|
|
|
|
|
18
|
|
|
7
|
|
|
|
|
277
|
|
8
|
7
|
|
|
7
|
|
96
|
use POE::Component::IRC::Plugin qw( :ALL ); |
|
7
|
|
|
|
|
20
|
|
|
7
|
|
|
|
|
1311
|
|
9
|
7
|
|
|
7
|
|
49
|
use POSIX qw(strftime); |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
104
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
3
|
|
|
3
|
1
|
2786
|
my ($package) = shift; |
13
|
3
|
50
|
|
|
|
15
|
croak "$package requires an even number of arguments" if @_ & 1; |
14
|
3
|
|
|
|
|
13
|
my %args = @_; |
15
|
|
|
|
|
|
|
|
16
|
4
|
|
|
|
|
21
|
$args{ lc $_ } = delete $args{ $_ } for keys %args; |
17
|
3
|
50
|
33
|
|
|
25
|
$args{eat} = 1 if !defined ( $args{eat} ) || $args{eat} eq '0'; |
18
|
4
|
|
|
|
|
24
|
return bless \%args, $package; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub PCI_register { |
22
|
3
|
|
|
3
|
0
|
819
|
my ($self,$irc) = splice @_, 0, 2; |
23
|
|
|
|
|
|
|
|
24
|
3
|
|
|
|
|
14
|
$self->{irc} = $irc; |
25
|
3
|
|
|
|
|
16
|
$irc->plugin_register( $self, 'SERVER', qw(ctcp_version ctcp_clientinfo ctcp_userinfo ctcp_time ctcp_ping ctcp_source) ); |
26
|
|
|
|
|
|
|
|
27
|
3
|
|
|
|
|
159
|
return 1; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub PCI_unregister { |
31
|
3
|
|
|
3
|
0
|
889
|
delete $_[0]->{irc}; |
32
|
3
|
|
|
|
|
9
|
return 1; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
## no critic (TestingAndDebugging::ProhibitNoStrict) |
36
|
|
|
|
|
|
|
sub S_ctcp_version { |
37
|
1
|
|
|
1
|
0
|
53
|
my ($self, $irc) = splice @_, 0, 2; |
38
|
1
|
|
|
|
|
3
|
my $nick = ( split /!/, ${ $_[0] } )[0]; |
|
1
|
|
|
|
|
4
|
|
39
|
|
|
|
|
|
|
|
40
|
1
|
|
|
|
|
3
|
my $our_version; |
41
|
|
|
|
|
|
|
{ |
42
|
7
|
|
|
7
|
|
3189
|
no strict 'vars'; |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
5991
|
|
|
1
|
|
|
|
|
3
|
|
43
|
1
|
50
|
33
|
|
|
8
|
if (defined $POE::Component::IRC::VERSION |
44
|
|
|
|
|
|
|
&& $POE::Component::IRC::VERSION ne '1, set by base.pm') { |
45
|
1
|
|
|
|
|
3
|
$our_version = 'dev-git'; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
else { |
48
|
0
|
|
|
|
|
0
|
$our_version = $POE::Component::IRC::VERSION; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
$irc->yield( ctcpreply => $nick => 'VERSION ' . ( defined $self->{version} |
53
|
|
|
|
|
|
|
? $self->{version} |
54
|
1
|
50
|
|
|
|
8
|
: "POE::Component::IRC-$our_version" |
55
|
|
|
|
|
|
|
)); |
56
|
1
|
50
|
|
|
|
139
|
return PCI_EAT_CLIENT if $self->eat(); |
57
|
0
|
|
|
|
|
0
|
return PCI_EAT_NONE; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub S_ctcp_time { |
61
|
1
|
|
|
1
|
0
|
43
|
my ($self, $irc) = splice @_, 0, 2; |
62
|
1
|
|
|
|
|
3
|
my $nick = ( split /!/, ${ $_[0] } )[0]; |
|
1
|
|
|
|
|
4
|
|
63
|
|
|
|
|
|
|
|
64
|
1
|
|
|
|
|
113
|
$irc->yield(ctcpreply => $nick => strftime('TIME %a, %d %b %Y %H:%M:%S %z', localtime)); |
65
|
|
|
|
|
|
|
|
66
|
1
|
50
|
|
|
|
125
|
return PCI_EAT_CLIENT if $self->eat(); |
67
|
0
|
|
|
|
|
0
|
return PCI_EAT_NONE; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub S_ctcp_ping { |
71
|
1
|
|
|
1
|
0
|
44
|
my ($self,$irc) = splice @_, 0, 2; |
72
|
1
|
|
|
|
|
3
|
my $nick = ( split /!/, ${ $_[0] } )[0]; |
|
1
|
|
|
|
|
5
|
|
73
|
1
|
|
|
|
|
4
|
my $timestamp = ${ $_[2] }; |
|
1
|
|
|
|
|
2
|
|
74
|
|
|
|
|
|
|
|
75
|
1
|
|
|
|
|
6
|
$irc->yield( ctcpreply => $nick => 'PING ' . $timestamp ); |
76
|
|
|
|
|
|
|
|
77
|
1
|
50
|
|
|
|
132
|
return PCI_EAT_CLIENT if $self->eat(); |
78
|
0
|
|
|
|
|
0
|
return PCI_EAT_NONE; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub S_ctcp_clientinfo { |
82
|
1
|
|
|
1
|
0
|
47
|
my ($self, $irc) = splice @_, 0, 2; |
83
|
1
|
|
|
|
|
3
|
my $nick = ( split /!/, ${ $_[0] } )[0]; |
|
1
|
|
|
|
|
5
|
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
$irc->yield(ctcpreply => $nick => 'CLIENTINFO ' . ($self->{clientinfo} |
86
|
|
|
|
|
|
|
? $self->{clientinfo} |
87
|
1
|
50
|
|
|
|
9
|
: 'http://search.cpan.org/perldoc?POE::Component::IRC::Plugin::CTCP' |
88
|
|
|
|
|
|
|
)); |
89
|
|
|
|
|
|
|
|
90
|
1
|
50
|
|
|
|
116
|
return PCI_EAT_CLIENT if $self->eat(); |
91
|
0
|
|
|
|
|
0
|
return PCI_EAT_NONE; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub S_ctcp_userinfo { |
95
|
1
|
|
|
1
|
0
|
45
|
my ($self, $irc) = splice @_, 0, 2; |
96
|
1
|
|
|
|
|
3
|
my $nick = ( split /!/, ${ $_[0] } )[0]; |
|
1
|
|
|
|
|
5
|
|
97
|
|
|
|
|
|
|
|
98
|
1
|
50
|
|
|
|
25
|
$irc->yield( ctcpreply => $nick => 'USERINFO ' . ( $self->{userinfo} ? $self->{userinfo} : 'm33p' ) ); |
99
|
|
|
|
|
|
|
|
100
|
1
|
50
|
|
|
|
116
|
return PCI_EAT_CLIENT if $self->eat(); |
101
|
0
|
|
|
|
|
0
|
return PCI_EAT_NONE; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub S_ctcp_source { |
105
|
1
|
|
|
1
|
0
|
45
|
my ($self, $irc) = splice @_, 0, 2; |
106
|
1
|
|
|
|
|
2
|
my $nick = ( split /!/, ${ $_[0] } )[0]; |
|
1
|
|
|
|
|
6
|
|
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
$irc->yield( ctcpreply => $nick => 'SOURCE ' . ($self->{source} |
109
|
|
|
|
|
|
|
? $self->{source} |
110
|
1
|
50
|
|
|
|
8
|
: 'http://search.cpan.org/dist/POE-Component-IRC' |
111
|
|
|
|
|
|
|
)); |
112
|
|
|
|
|
|
|
|
113
|
1
|
50
|
|
|
|
114
|
return PCI_EAT_CLIENT if $self->eat(); |
114
|
0
|
|
|
|
|
0
|
return PCI_EAT_NONE; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub eat { |
118
|
6
|
|
|
6
|
1
|
13
|
my $self = shift; |
119
|
6
|
|
|
|
|
8
|
my $value = shift; |
120
|
|
|
|
|
|
|
|
121
|
6
|
50
|
|
|
|
35
|
return $self->{eat} if !defined $value; |
122
|
0
|
|
|
|
|
|
return $self->{eat} = $value; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
1; |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=encoding utf8 |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 NAME |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
POE::Component::IRC::Plugin::CTCP - A PoCo-IRC plugin that auto-responds to CTCP requests |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 SYNOPSIS |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
use strict; |
136
|
|
|
|
|
|
|
use warnings; |
137
|
|
|
|
|
|
|
use POE qw(Component::IRC Component::IRC::Plugin::CTCP); |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
my $nickname = 'Flibble' . $$; |
140
|
|
|
|
|
|
|
my $ircname = 'Flibble the Sailor Bot'; |
141
|
|
|
|
|
|
|
my $ircserver = 'irc.blahblahblah.irc'; |
142
|
|
|
|
|
|
|
my $port = 6667; |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
my $irc = POE::Component::IRC->spawn( |
145
|
|
|
|
|
|
|
nick => $nickname, |
146
|
|
|
|
|
|
|
server => $ircserver, |
147
|
|
|
|
|
|
|
port => $port, |
148
|
|
|
|
|
|
|
ircname => $ircname, |
149
|
|
|
|
|
|
|
) or die "Oh noooo! $!"; |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
POE::Session->create( |
152
|
|
|
|
|
|
|
package_states => [ |
153
|
|
|
|
|
|
|
main => [ qw(_start) ], |
154
|
|
|
|
|
|
|
], |
155
|
|
|
|
|
|
|
); |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
$poe_kernel->run(); |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
sub _start { |
160
|
|
|
|
|
|
|
# Create and load our CTCP plugin |
161
|
|
|
|
|
|
|
$irc->plugin_add( 'CTCP' => POE::Component::IRC::Plugin::CTCP->new( |
162
|
|
|
|
|
|
|
version => $ircname, |
163
|
|
|
|
|
|
|
userinfo => $ircname, |
164
|
|
|
|
|
|
|
)); |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
$irc->yield( register => 'all' ); |
167
|
|
|
|
|
|
|
$irc->yield( connect => { } ); |
168
|
|
|
|
|
|
|
return: |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head1 DESCRIPTION |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
POE::Component::IRC::Plugin::CTCP is a L |
174
|
|
|
|
|
|
|
plugin. It watches for C, C, |
175
|
|
|
|
|
|
|
C, C and C events and |
176
|
|
|
|
|
|
|
autoresponds on your behalf. |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head1 METHODS |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head2 C |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
Takes a number of optional arguments: |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
B<'version'>, a string to send in response to C. Default is |
185
|
|
|
|
|
|
|
PoCo-IRC and version; |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
B<'clientinfo'>, a string to send in response to C. |
188
|
|
|
|
|
|
|
Default is L. |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
B<'userinfo'>, a string to send in response to C. Default |
191
|
|
|
|
|
|
|
is 'm33p'; |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
B<'source'>, a string to send in response to C. Default is |
194
|
|
|
|
|
|
|
L. |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
B<'eat'>, by default the plugin uses PCI_EAT_CLIENT, set this to 0 to disable |
197
|
|
|
|
|
|
|
this behaviour; |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
Returns a plugin object suitable for feeding to |
200
|
|
|
|
|
|
|
L's C method. |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=head2 C |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
With no arguments, returns true or false on whether the plugin is "eating" CTCP |
205
|
|
|
|
|
|
|
events that it has dealt with. An argument will set "eating" to on or off |
206
|
|
|
|
|
|
|
appropriately, depending on whether the value is true or false. |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=head1 AUTHOR |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
Chris 'BinGOs' Williams |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=head1 SEE ALSO |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
CTCP Specification L. |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=cut |