line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package POE::Component::IRC::Plugin::BotAddressed; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:HINRIK'; |
3
|
|
|
|
|
|
|
$POE::Component::IRC::Plugin::BotAddressed::VERSION = '6.93'; |
4
|
3
|
|
|
3
|
|
3140
|
use strict; |
|
3
|
|
|
|
|
59
|
|
|
3
|
|
|
|
|
113
|
|
5
|
3
|
|
|
3
|
|
17
|
use warnings FATAL => 'all'; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
171
|
|
6
|
3
|
|
|
3
|
|
19
|
use Carp; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
216
|
|
7
|
3
|
|
|
3
|
|
102
|
use POE::Component::IRC::Plugin qw( :ALL ); |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
2715
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
10
|
2
|
|
|
2
|
1
|
2490
|
my ($package) = shift; |
11
|
2
|
50
|
|
|
|
10
|
croak "$package requires an even number of arguments" if @_ & 1; |
12
|
2
|
|
|
|
|
41
|
my %args = @_; |
13
|
|
|
|
|
|
|
|
14
|
2
|
|
|
|
|
13
|
$args{lc $_} = delete $args{$_} for keys %args; |
15
|
2
|
|
|
|
|
13
|
return bless \%args, $package; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub PCI_register { |
19
|
2
|
|
|
2
|
0
|
1229
|
my ($self, $irc) = splice @_, 0, 2; |
20
|
2
|
|
|
|
|
10
|
$irc->plugin_register( $self, 'SERVER', qw(ctcp_action public) ); |
21
|
2
|
|
|
|
|
99
|
return 1; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub PCI_unregister { |
25
|
2
|
|
|
2
|
0
|
875
|
return 1; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub S_ctcp_action { |
29
|
1
|
|
|
1
|
0
|
45
|
my ($self, $irc) = splice @_, 0, 2; |
30
|
1
|
|
|
|
|
3
|
my $who = ${ $_[0] }; |
|
1
|
|
|
|
|
3
|
|
31
|
1
|
|
|
|
|
3
|
my $recipients = ${ $_[1] }; |
|
1
|
|
|
|
|
21
|
|
32
|
1
|
|
|
|
|
4
|
my $what = ${ $_[2] }; |
|
1
|
|
|
|
|
3
|
|
33
|
1
|
|
|
|
|
6
|
my $me = $irc->nick_name(); |
34
|
1
|
50
|
|
|
|
11
|
my $chantypes = join('', @{ $irc->isupport('CHANTYPES') || ['#', '&']}); |
|
1
|
|
|
|
|
8
|
|
35
|
|
|
|
|
|
|
|
36
|
1
|
|
|
|
|
4
|
my $eat = PCI_EAT_NONE; |
37
|
1
|
50
|
|
|
|
22
|
return $eat if $what !~ /$me/i; |
38
|
|
|
|
|
|
|
|
39
|
1
|
|
|
|
|
4
|
for my $recipient (@{ $recipients }) { |
|
1
|
|
|
|
|
4
|
|
40
|
1
|
50
|
|
|
|
17
|
if ($recipient =~ /^[$chantypes]/) { |
41
|
1
|
50
|
|
|
|
6
|
$eat = PCI_EAT_ALL if $self->{eat}; |
42
|
1
|
|
|
|
|
5
|
$irc->send_event_next(irc_bot_mentioned_action => $who => [$recipient] => $what); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
1
|
|
|
|
|
24
|
return $eat; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub S_public { |
50
|
3
|
|
|
3
|
0
|
145
|
my ($self, $irc) = splice @_, 0, 2; |
51
|
3
|
|
|
|
|
6
|
my $who = ${ $_[0] }; |
|
3
|
|
|
|
|
7
|
|
52
|
3
|
|
|
|
|
7
|
my $channels = ${ $_[1] }; |
|
3
|
|
|
|
|
5
|
|
53
|
3
|
|
|
|
|
11
|
my $what = ${ $_[2] }; |
|
3
|
|
|
|
|
7
|
|
54
|
3
|
|
|
|
|
13
|
my $me = $irc->nick_name(); |
55
|
3
|
|
|
|
|
93
|
my ($cmd) = $what =~ m/^\s*[@%]?\Q$me\E[:,;.!?~]?\s*(.*)$/i; |
56
|
|
|
|
|
|
|
|
57
|
3
|
50
|
66
|
|
|
30
|
return PCI_EAT_NONE if !defined $cmd && $what !~ /$me/i; |
58
|
|
|
|
|
|
|
|
59
|
3
|
|
|
|
|
6
|
for my $channel (@{ $channels }) { |
|
3
|
|
|
|
|
9
|
|
60
|
3
|
100
|
|
|
|
12
|
if (defined $cmd) { |
61
|
2
|
|
|
|
|
16
|
$irc->send_event_next(irc_bot_addressed => $who => [$channel] => $cmd ); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
else { |
64
|
1
|
|
|
|
|
7
|
$irc->send_event_next(irc_bot_mentioned => $who => [$channel] => $what); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
3
|
50
|
|
|
|
82
|
return $self->{eat} ? PCI_EAT_ALL : PCI_EAT_NONE; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
1; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=encoding utf8 |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 NAME |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
POE::Component::IRC::Plugin::BotAddressed - A PoCo-IRC plugin that generates |
78
|
|
|
|
|
|
|
events when you are addressed |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 SYNOPSIS |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
use POE::Component::IRC::Plugin::BotAddressed; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
$irc->plugin_add( 'BotAddressed', POE::Component::IRC::Plugin::BotAddressed->new() ); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub irc_bot_addressed { |
87
|
|
|
|
|
|
|
my ($kernel, $heap) = @_[KERNEL, HEAP]; |
88
|
|
|
|
|
|
|
my $nick = ( split /!/, $_[ARG0] )[0]; |
89
|
|
|
|
|
|
|
my $channel = $_[ARG1]->[0]; |
90
|
|
|
|
|
|
|
my $what = $_[ARG2]; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
print "$nick addressed me in channel $channel with the message '$what'\n"; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub irc_bot_mentioned { |
96
|
|
|
|
|
|
|
my ($nick) = ( split /!/, $_[ARG0] )[0]; |
97
|
|
|
|
|
|
|
my ($channel) = $_[ARG1]->[0]; |
98
|
|
|
|
|
|
|
my ($what) = $_[ARG2]; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
print "$nick mentioned my name in channel $channel with the message '$what'\n"; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 DESCRIPTION |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
POE::Component::IRC::Plugin::BotAddressed is a |
106
|
|
|
|
|
|
|
L plugin. It watches for public |
107
|
|
|
|
|
|
|
channel traffic (i.e. C and C) and will generate |
108
|
|
|
|
|
|
|
an C, C or C |
109
|
|
|
|
|
|
|
event if its name comes up in channel discussion. |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 METHODS |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head2 C |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
One optional argument: |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
B<'eat'>, set to true to make the plugin eat the C / |
118
|
|
|
|
|
|
|
C |
119
|
|
|
|
|
|
|
event and only generate an appropriate event, default is false. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Returns a plugin object suitable for feeding to |
122
|
|
|
|
|
|
|
L's C method. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 OUTPUT EVENTS |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head2 C |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Has the same parameters passed as L|POE::Component::IRC/irc_public>. |
129
|
|
|
|
|
|
|
C contains the message with the addressed nickname removed, ie. Assuming |
130
|
|
|
|
|
|
|
that your bot is called LameBOT, and someone says 'LameBOT: dance for me', |
131
|
|
|
|
|
|
|
you will actually get 'dance for me'. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head2 C |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Has the same parameters passed as L|POE::Component::IRC/irc_public>. |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head2 C |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Has the same parameters passed as L|POE::Component::IRC/irc_ctcp_*>. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head1 AUTHOR |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
Chris 'BinGOs' Williams |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=cut |