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.93';
4 8     8   1645 use strict;
  8         21  
  8         292  
5 8     8   44 use warnings FATAL => 'all';
  8         15  
  8         366  
6 8     8   46 use POE::Component::IRC::Plugin qw( :ALL );
  8         17  
  8         1092  
7 8     8   61 use POE::Filter::IRCD;
  8         18  
  8         301  
8 8     8   102 use POE::Filter::IRC::Compat;
  8         23  
  8         4913  
9              
10             sub new {
11 7     7 1 2676 my ($package) = @_;
12 7         126 return bless { }, $package;
13             }
14              
15             sub PCI_register {
16 7     7 0 1051 my ($self, $irc) = splice @_, 0, 2;
17              
18 7         37 $self->{filter} = POE::Filter::IRCD->new();
19 7         172 $self->{compat} = POE::Filter::IRC::Compat->new();
20 7         41 $irc->plugin_register( $self, 'USER', qw(privmsg notice) );
21 7         309 return 1;
22             }
23              
24             sub PCI_unregister {
25 7     7 0 1554 return 1;
26             }
27              
28             sub U_notice {
29 2     2 0 203 my ($self, $irc) = splice @_, 0, 2;
30 2         6 my $output = ${ $_[0] };
  2         7  
31 2         15 my $line = $self->{filter}->get([ $output ])->[0];
32 2         100 my $text = $line->{params}->[1];
33 2         11 my $targets = [ split(/,/, $line->{params}->[0]) ];
34              
35 2         12 $irc->send_event_next(irc_bot_notice => $targets => $text);
36              
37 2         50 return PCI_EAT_NONE;
38             }
39              
40             sub U_privmsg {
41 6     6 0 656 my ($self, $irc) = splice @_, 0, 2;
42 6         13 my $output = ${ $_[0] };
  6         27  
43 6         45 my $line = $self->{filter}->get([ $output ])->[0];
44 6         367 my $text = $line->{params}->[1];
45              
46 6 100       31 if ($text =~ /^\001/) {
47 3         42 my $ctcp_event = $self->{compat}->get([$line])->[0];
48 3 100       44 return PCI_EAT_NONE if $ctcp_event->{name} ne 'ctcp_action';
49 2         9 $irc->send_event_next(irc_bot_action => @{ $ctcp_event->{args} }[1..2]);
  2         11  
50             }
51             else {
52 3 50       8 my $chantypes = join('', @{ $irc->isupport('CHANTYPES') || ['#', '&']});
  3         14  
53 3         15 for my $recipient ( split(/,/, $line->{params}->[0]) ) {
54 3         6 my $event = 'irc_bot_msg';
55 3 100       51 $event = 'irc_bot_public' if $recipient =~ /^[$chantypes]/;
56 3         23 $irc->send_event_next($event => [ $recipient ] => $text);
57             }
58             }
59              
60 5         143 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