| 1 | package POE::Component::IRC::Plugin::BotTraffic; | ||||||||||||
| 2 | 8 | $POE::Component::IRC::Plugin::BotTraffic::VERSION = '6.95'; | |||||||||||
| 3 | 8 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 8 | ▶ | use warnings FATAL => 'all'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 8 | ▶ | use POE::Component::IRC::Plugin qw( :ALL ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 8 | ▶ | use POE::Filter::IRCD; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 8 | ▶ | use POE::Filter::IRC::Compat; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | |||||||||||||
| 9 | 7 | ▶ | sub new { | ||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 10 | 7 | my ($package) = @_; | |||||||||||
| 11 | 7 | return bless { }, $package; | |||||||||||
| 12 | } | ||||||||||||
| 13 | |||||||||||||
| 14 | 7 | ▶ | sub PCI_register { | ||||||||||
|
Subroutine
PCI_register: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 15 | 7 | my ($self, $irc) = splice @_, 0, 2; | |||||||||||
| 16 | |||||||||||||
| 17 | 7 | $self->{filter} = POE::Filter::IRCD->new(); | |||||||||||
| 18 | 7 | $self->{compat} = POE::Filter::IRC::Compat->new(); | |||||||||||
| 19 | 7 | $irc->plugin_register( $self, 'USER', qw(privmsg notice) ); | |||||||||||
| 20 | 7 | return 1; | |||||||||||
| 21 | } | ||||||||||||
| 22 | |||||||||||||
| 23 | 7 | ▶ | sub PCI_unregister { | ||||||||||
|
Subroutine
PCI_unregister: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 24 | 7 | return 1; | |||||||||||
| 25 | } | ||||||||||||
| 26 | |||||||||||||
| 27 | 2 | ▶ | sub U_notice { | ||||||||||
|
Subroutine
U_notice: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 28 | 2 | my ($self, $irc) = splice @_, 0, 2; | |||||||||||
| 29 | 2 | my $output = ${ $_[0] }; | |||||||||||
| 30 | 2 | my $line = $self->{filter}->get([ $output ])->[0]; | |||||||||||
| 31 | 2 | my $text = $line->{params}->[1]; | |||||||||||
| 32 | 2 | my $targets = [ split(/,/, $line->{params}->[0]) ]; | |||||||||||
| 33 | |||||||||||||
| 34 | 2 | $irc->send_event_next(irc_bot_notice => $targets => $text); | |||||||||||
| 35 | |||||||||||||
| 36 | 2 | return PCI_EAT_NONE; | |||||||||||
| 37 | } | ||||||||||||
| 38 | |||||||||||||
| 39 | 6 | ▶ | sub U_privmsg { | ||||||||||
|
Subroutine
U_privmsg: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||
| 40 | 6 | my ($self, $irc) = splice @_, 0, 2; | |||||||||||
| 41 | 6 | my $output = ${ $_[0] }; | |||||||||||
| 42 | 6 | my $line = $self->{filter}->get([ $output ])->[0]; | |||||||||||
| 43 | 6 | my $text = $line->{params}->[1]; | |||||||||||
| 44 | |||||||||||||
| 45 | 6 | ▶ | if ($text =~ /^\001/) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 46 | 3 | my $ctcp_event = $self->{compat}->get([$line])->[0]; | |||||||||||
| 47 | 3 | ▶ | return PCI_EAT_NONE if $ctcp_event->{name} ne 'ctcp_action'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 48 | 2 | $irc->send_event_next(irc_bot_action => @{ $ctcp_event->{args} }[1..2]); | |||||||||||
| 49 | } | ||||||||||||
| 50 | else { | ||||||||||||
| 51 | 3 | ▶ | my $chantypes = join('', @{ $irc->isupport('CHANTYPES') || ['#', '&']}); | ||||||||||
|
Condition50%1/2
$irc->isupport('CHANTYPES') || ['#', '&']
MC/DC0%0/1
$irc->isupport('CHANTYPES') || ['#', '&']
$irc->isupport('CHANTYPES')
Truth table50%1/2
A
A= $irc->isupport('CHANTYPES')
| |||||||||||||
| 52 | 3 | for my $recipient ( split(/,/, $line->{params}->[0]) ) { | |||||||||||
| 53 | 3 | my $event = 'irc_bot_msg'; | |||||||||||
| 54 | 3 | ▶ | $event = 'irc_bot_public' if $recipient =~ /^[$chantypes]/; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 55 | 3 | $irc->send_event_next($event => [ $recipient ] => $text); | |||||||||||
| 56 | } | ||||||||||||
| 57 | } | ||||||||||||
| 58 | |||||||||||||
| 59 | 5 | return PCI_EAT_NONE; | |||||||||||
| 60 | } | ||||||||||||
| 61 | |||||||||||||
| 62 | 8 | 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<POE::Component::IRC|POE::Component::IRC> | ||||||||||||
| 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<new> | ||||||||||||
| 97 | |||||||||||||
| 98 | No arguments required. Returns a plugin object suitable for feeding to | ||||||||||||
| 99 | L<POE::Component::IRC|POE::Component::IRC>'s C<plugin_add> method. | ||||||||||||
| 100 | |||||||||||||
| 101 | =head1 OUTPUT EVENTS | ||||||||||||
| 102 | |||||||||||||
| 103 | These are the events generated by the plugin. Both events have C<ARG0> set | ||||||||||||
| 104 | to an arrayref of recipients and C<ARG1> the text that was sent. | ||||||||||||
| 105 | |||||||||||||
| 106 | =head2 C<irc_bot_public> | ||||||||||||
| 107 | |||||||||||||
| 108 | C<ARG0> will be an arrayref of recipients. C<ARG1> will be the text sent. | ||||||||||||
| 109 | |||||||||||||
| 110 | =head2 C<irc_bot_msg> | ||||||||||||
| 111 | |||||||||||||
| 112 | C<ARG0> will be an arrayref of recipients. C<ARG1> will be the text sent. | ||||||||||||
| 113 | |||||||||||||
| 114 | =head2 C<irc_bot_action> | ||||||||||||
| 115 | |||||||||||||
| 116 | C<ARG0> will be an arrayref of recipients. C<ARG1> will be the text sent. | ||||||||||||
| 117 | |||||||||||||
| 118 | =head2 C<irc_bot_notice> | ||||||||||||
| 119 | |||||||||||||
| 120 | C<ARG0> will be an arrayref of recipients. C<ARG1> 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<POE::Component::IRC> | ||||||||||||
| 129 | |||||||||||||
| 130 | =cut | ||||||||||||