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