Component/IRC/Plugin/BotTraffic.pm

filter: Statementstmt 35.2% 18 / 51 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 5 / 10 Podpod 20.0% 1 / 5 totaltotal 32.4% 24 / 74 CC 6 SCAR 28.7
CC
6
Cov
31%
U_privmsg
42.0
new
2.0
PCI_register
2.0
CRAP 17.7
« Component/IRC/Plugin/NickReclaim.pm ↑ Summary Component/IRC/Plugin/ISupport.pm »
1 package POE::Component::IRC::Plugin::BotTraffic;
2 1 our $AUTHORITY = 'cpan:HINRIK';
3 1 $POE::Component::IRC::Plugin::BotTraffic::VERSION = '6.92';
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use POE::Component::IRC::Plugin qw( :ALL );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use POE::Filter::IRCD;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use POE::Filter::IRC::Compat;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 sub new {
11 0 ▶ my ($package) = @_;
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
12 0 return bless { }, $package;
13 }
14  
15 sub PCI_register {
16 0 ▶ my ($self, $irc) = splice @_, 0, 2;
Subroutine PCI_register: not called CC=1 SCAR=6.9
Pod undocumented
17  
18 0 $self->{filter} = POE::Filter::IRCD->new();
19 0 $self->{compat} = POE::Filter::IRC::Compat->new();
20 0 $irc->plugin_register( $self, 'USER', qw(privmsg notice) );
21 0 return 1;
22 }
23  
24 sub PCI_unregister {
25 0 ▶ return 1;
Subroutine PCI_unregister: not called CC=1 SCAR=6.9
Pod undocumented
26 }
27  
28 sub U_notice {
29 0 ▶ my ($self, $irc) = splice @_, 0, 2;
Subroutine U_notice: not called CC=1 SCAR=6.9
Pod undocumented
30 0 my $output = ${ $_[0] };
31 0 my $line = $self->{filter}->get([ $output ])->[0];
32 0 my $text = $line->{params}->[1];
33 0 my $targets = [ split(/,/, $line->{params}->[0]) ];
34  
35 0 $irc->send_event_next(irc_bot_notice => $targets => $text);
36  
37 0 return PCI_EAT_NONE;
38 }
39  
40 sub U_privmsg {
41 0 ▶ my ($self, $irc) = splice @_, 0, 2;
Subroutine U_privmsg: not called CC=6 SCAR=37.4
Pod undocumented
42 0 my $output = ${ $_[0] };
43 0 my $line = $self->{filter}->get([ $output ])->[0];
44 0 my $text = $line->{params}->[1];
45  
46 0 ▶ if ($text =~ /^\001/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ /^\001/) { } 0 0 0
47 0 my $ctcp_event = $self->{compat}->get([$line])->[0];
48 0 ▶ return PCI_EAT_NONE if $ctcp_event->{name} ne 'ctcp_action';
Branch: 1 branch
BranchTrueFalseTotal
if $ctcp_event->{"name"} ne "ctcp_action" 0 0 0
49 0 $irc->send_event_next(irc_bot_action => @{ $ctcp_event->{args} }[1..2]);
50 }
51 else {
52 0 ▶ my $chantypes = join('', @{ $irc->isupport('CHANTYPES') || ['#', '&']});
Branch: 1 branch
BranchTrueFalseTotal
$irc->isupport("CHANTYPES") or ["#", "&"] 0 0 0
53 0 for my $recipient ( split(/,/, $line->{params}->[0]) ) {
54 0 my $event = 'irc_bot_msg';
55 0 ▶ $event = 'irc_bot_public' if $recipient =~ /^[$chantypes]/;
Branch: 1 branch
BranchTrueFalseTotal
if $recipient =~ /^[$chantypes]/ 0 0 0
56 0 $irc->send_event_next($event => [ $recipient ] => $text);
57 }
58 }
59  
60 0 return PCI_EAT_NONE;
61 }
62  
63 1 1;
64  
65 =encoding utf8
66  
67 =head1 NAME
68  
69 POE::Component::IRC::Plugin::BotTraffic - A PoCo-IRC plugin that generates
70 events when you send messages
71  
72 =head1 SYNOPSIS
73  
74 use POE::Component::IRC::Plugin::BotTraffic;
75  
76 $irc->plugin_add( 'BotTraffic', POE::Component::IRC::Plugin::BotTraffic->new() );
77  
78 sub irc_bot_public {
79 my ($kernel, $heap) = @_[KERNEL, HEAP];
80 my $channel = $_[ARG0]->[0];
81 my $what = $_[ARG1];
82  
83 print "I said '$what' on channel $channel\n";
84 return;
85 }
86  
87 =head1 DESCRIPTION
88  
89 POE::Component::IRC::Plugin::BotTraffic is a L<POE::Component::IRC|POE::Component::IRC>
90 plugin. It watches for when your bot sends PRIVMSGs and NOTICEs to the server
91 and generates the appropriate events.
92  
93 These events are useful for logging what your bot says.
94  
95 =head1 METHODS
96  
97 =head2 C<new>
98  
99 No arguments required. Returns a plugin object suitable for feeding to
100 L<POE::Component::IRC|POE::Component::IRC>'s C<plugin_add> method.
101  
102 =head1 OUTPUT EVENTS
103  
104 These are the events generated by the plugin. Both events have C<ARG0> set
105 to an arrayref of recipients and C<ARG1> the text that was sent.
106  
107 =head2 C<irc_bot_public>
108  
109 C<ARG0> will be an arrayref of recipients. C<ARG1> will be the text sent.
110  
111 =head2 C<irc_bot_msg>
112  
113 C<ARG0> will be an arrayref of recipients. C<ARG1> will be the text sent.
114  
115 =head2 C<irc_bot_action>
116  
117 C<ARG0> will be an arrayref of recipients. C<ARG1> will be the text sent.
118  
119 =head2 C<irc_bot_notice>
120  
121 C<ARG0> will be an arrayref of recipients. C<ARG1> will be the text sent.
122  
123 =head1 AUTHOR
124  
125 Chris 'BinGOs' Williams [chris@bingosnet.co.uk]
126  
127 =head1 SEE ALSO
128  
129 L<POE::Component::IRC>
130  
131 =cut
« Component/IRC/Plugin/NickReclaim.pm ↑ Summary Component/IRC/Plugin/ISupport.pm »