File Coverage

blib/lib/POE/Component/IRC/Plugin/BotTraffic.pm
Criterion Covered Total %
statement 48 48 100.0
branch 7 8 87.5
condition n/a
subroutine 10 10 100.0
pod 1 5 20.0
total 66 71 92.9


line stmt bran cond sub pod time code
1             package POE::Component::IRC::Plugin::BotTraffic;
2             our $AUTHORITY = 'cpan:HINRIK';
3             $POE::Component::IRC::Plugin::BotTraffic::VERSION = '6.92';
4 8     8   1754 use strict;
  8         22  
  8         319  
5 8     8   45 use warnings FATAL => 'all';
  8         19  
  8         447  
6 8     8   48 use POE::Component::IRC::Plugin qw( :ALL );
  8         16  
  8         1186  
7 8     8   56 use POE::Filter::IRCD;
  8         18  
  8         296  
8 8     8   86 use POE::Filter::IRC::Compat;
  8         23  
  8         5087  
9              
10             sub new {
11 7     7 1 2192 my ($package) = @_;
12 7         107 return bless { }, $package;
13             }
14              
15             sub PCI_register {
16 7     7 0 1595 my ($self, $irc) = splice @_, 0, 2;
17              
18 7         61 $self->{filter} = POE::Filter::IRCD->new();
19 7         173 $self->{compat} = POE::Filter::IRC::Compat->new();
20 7         48 $irc->plugin_register( $self, 'USER', qw(privmsg notice) );
21 7         293 return 1;
22             }
23              
24             sub PCI_unregister {
25 7     7 0 2372 return 1;
26             }
27              
28             sub U_notice {
29 2     2 0 169 my ($self, $irc) = splice @_, 0, 2;
30 2         5 my $output = ${ $_[0] };
  2         5  
31 2         11 my $line = $self->{filter}->get([ $output ])->[0];
32 2         75 my $text = $line->{params}->[1];
33 2         9 my $targets = [ split(/,/, $line->{params}->[0]) ];
34              
35 2         9 $irc->send_event_next(irc_bot_notice => $targets => $text);
36              
37 2         37 return PCI_EAT_NONE;
38             }
39              
40             sub U_privmsg {
41 6     6 0 535 my ($self, $irc) = splice @_, 0, 2;
42 6         12 my $output = ${ $_[0] };
  6         23  
43 6         32 my $line = $self->{filter}->get([ $output ])->[0];
44 6         299 my $text = $line->{params}->[1];
45              
46 6 100       25 if ($text =~ /^\001/) {
47 3         47 my $ctcp_event = $self->{compat}->get([$line])->[0];
48 3 100       34 return PCI_EAT_NONE if $ctcp_event->{name} ne 'ctcp_action';
49 2         15 $irc->send_event_next(irc_bot_action => @{ $ctcp_event->{args} }[1..2]);
  2         10  
50             }
51             else {
52 3 50       5 my $chantypes = join('', @{ $irc->isupport('CHANTYPES') || ['#', '&']});
  3         13  
53 3         11 for my $recipient ( split(/,/, $line->{params}->[0]) ) {
54 3         7 my $event = 'irc_bot_msg';
55 3 100       44 $event = 'irc_bot_public' if $recipient =~ /^[$chantypes]/;
56 3         19 $irc->send_event_next($event => [ $recipient ] => $text);
57             }
58             }
59              
60 5         140 return PCI_EAT_NONE;
61             }
62              
63             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
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
98              
99             No arguments required. Returns a plugin object suitable for feeding to
100             L's C method.
101              
102             =head1 OUTPUT EVENTS
103              
104             These are the events generated by the plugin. Both events have C set
105             to an arrayref of recipients and C the text that was sent.
106              
107             =head2 C
108              
109             C will be an arrayref of recipients. C will be the text sent.
110              
111             =head2 C
112              
113             C will be an arrayref of recipients. C will be the text sent.
114              
115             =head2 C
116              
117             C will be an arrayref of recipients. C will be the text sent.
118              
119             =head2 C
120              
121             C will be an arrayref of recipients. C 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
130              
131             =cut