| 1 | package POE::Component::IRC::Plugin::BotAddressed; | ||||||||||||||||||||||||||||
| 2 | 1 | our $AUTHORITY = 'cpan:HINRIK'; | |||||||||||||||||||||||||||
| 3 | 1 | $POE::Component::IRC::Plugin::BotAddressed::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 Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use POE::Component::IRC::Plugin qw( :ALL ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | sub new { | ||||||||||||||||||||||||||||
| 10 | 0 | ▶ | my ($package) = shift; | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 11 | 0 | ▶ | croak "$package requires an even number of arguments" if @_ & 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 12 | 0 | my %args = @_; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 0 | $args{lc $_} = delete $args{$_} for keys %args; | |||||||||||||||||||||||||||
| 15 | 0 | return bless \%args, $package; | |||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | sub PCI_register { | ||||||||||||||||||||||||||||
| 19 | 0 | ▶ | my ($self, $irc) = splice @_, 0, 2; | ||||||||||||||||||||||||||
|
Subroutine
PCI_register: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 20 | 0 | $irc->plugin_register( $self, 'SERVER', qw(ctcp_action public) ); | |||||||||||||||||||||||||||
| 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 S_ctcp_action { | ||||||||||||||||||||||||||||
| 29 | 0 | ▶ | my ($self, $irc) = splice @_, 0, 2; | ||||||||||||||||||||||||||
|
Subroutine
S_ctcp_action: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 30 | 0 | my $who = ${ $_[0] }; | |||||||||||||||||||||||||||
| 31 | 0 | my $recipients = ${ $_[1] }; | |||||||||||||||||||||||||||
| 32 | 0 | my $what = ${ $_[2] }; | |||||||||||||||||||||||||||
| 33 | 0 | my $me = $irc->nick_name(); | |||||||||||||||||||||||||||
| 34 | 0 | ▶ | my $chantypes = join('', @{ $irc->isupport('CHANTYPES') || ['#', '&']}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 0 | my $eat = PCI_EAT_NONE; | |||||||||||||||||||||||||||
| 37 | 0 | ▶ | return $eat if $what !~ /$me/i; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 0 | for my $recipient (@{ $recipients }) { | |||||||||||||||||||||||||||
| 40 | 0 | ▶ | if ($recipient =~ /^[$chantypes]/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 0 | ▶ | $eat = PCI_EAT_ALL if $self->{eat}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | 0 | $irc->send_event_next(irc_bot_mentioned_action => $who => [$recipient] => $what); | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 0 | return $eat; | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | sub S_public { | ||||||||||||||||||||||||||||
| 50 | 0 | ▶ | my ($self, $irc) = splice @_, 0, 2; | ||||||||||||||||||||||||||
|
Subroutine
S_public: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 51 | 0 | my $who = ${ $_[0] }; | |||||||||||||||||||||||||||
| 52 | 0 | my $channels = ${ $_[1] }; | |||||||||||||||||||||||||||
| 53 | 0 | my $what = ${ $_[2] }; | |||||||||||||||||||||||||||
| 54 | 0 | my $me = $irc->nick_name(); | |||||||||||||||||||||||||||
| 55 | 0 | my ($cmd) = $what =~ m/^\s*[@%]?\Q$me\E[:,;.!?~]?\s*(.*)$/i; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 0 | ▶ | return PCI_EAT_NONE if !defined $cmd && $what !~ /$me/i; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $cmd or $what =~ /$me/i
MC/DC0%0/2
defined $cmd or $what =~ /$me/i
defined $cmd
$what =~ /$me/i
Truth table0%0/3
A or B
A= defined $cmdB= $what =~ /$me/i
| |||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | for my $channel (@{ $channels }) { | |||||||||||||||||||||||||||
| 60 | 0 | ▶ | if (defined $cmd) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 0 | $irc->send_event_next(irc_bot_addressed => $who => [$channel] => $cmd ); | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | else { | ||||||||||||||||||||||||||||
| 64 | 0 | $irc->send_event_next(irc_bot_mentioned => $who => [$channel] => $what); | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | ▶ | return $self->{eat} ? PCI_EAT_ALL : PCI_EAT_NONE; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 1 | 1; | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | =encoding utf8 | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | =head1 NAME | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | POE::Component::IRC::Plugin::BotAddressed - A PoCo-IRC plugin that generates | ||||||||||||||||||||||||||||
| 78 | events when you are addressed | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | use POE::Component::IRC::Plugin::BotAddressed; | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | $irc->plugin_add( 'BotAddressed', POE::Component::IRC::Plugin::BotAddressed->new() ); | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | sub irc_bot_addressed { | ||||||||||||||||||||||||||||
| 87 | my ($kernel, $heap) = @_[KERNEL, HEAP]; | ||||||||||||||||||||||||||||
| 88 | my $nick = ( split /!/, $_[ARG0] )[0]; | ||||||||||||||||||||||||||||
| 89 | my $channel = $_[ARG1]->[0]; | ||||||||||||||||||||||||||||
| 90 | my $what = $_[ARG2]; | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | print "$nick addressed me in channel $channel with the message '$what'\n"; | ||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | sub irc_bot_mentioned { | ||||||||||||||||||||||||||||
| 96 | my ($nick) = ( split /!/, $_[ARG0] )[0]; | ||||||||||||||||||||||||||||
| 97 | my ($channel) = $_[ARG1]->[0]; | ||||||||||||||||||||||||||||
| 98 | my ($what) = $_[ARG2]; | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | print "$nick mentioned my name in channel $channel with the message '$what'\n"; | ||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | POE::Component::IRC::Plugin::BotAddressed is a | ||||||||||||||||||||||||||||
| 106 | L<POE::Component::IRC|POE::Component::IRC> plugin. It watches for public | ||||||||||||||||||||||||||||
| 107 | channel traffic (i.e. C<irc_public> and C<irc_ctcp_action>) and will generate | ||||||||||||||||||||||||||||
| 108 | an C<irc_bot_addressed>, C<irc_bot_mentioned> or C<irc_bot_mentioned_action> | ||||||||||||||||||||||||||||
| 109 | event if its name comes up in channel discussion. | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | =head1 METHODS | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | =head2 C<new> | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | One optional argument: | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | B<'eat'>, set to true to make the plugin eat the C<irc_public> / | ||||||||||||||||||||||||||||
| 118 | C<irc_ctcp_action> | ||||||||||||||||||||||||||||
| 119 | event and only generate an appropriate event, default is false. | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | Returns a plugin object suitable for feeding to | ||||||||||||||||||||||||||||
| 122 | L<POE::Component::IRC|POE::Component::IRC>'s C<plugin_add> method. | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | =head1 OUTPUT EVENTS | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | =head2 C<irc_bot_addressed> | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | Has the same parameters passed as L<C<irc_ctcp_public>|POE::Component::IRC/irc_public>. | ||||||||||||||||||||||||||||
| 129 | C<ARG2> contains the message with the addressed nickname removed, ie. Assuming | ||||||||||||||||||||||||||||
| 130 | that your bot is called LameBOT, and someone says 'LameBOT: dance for me', | ||||||||||||||||||||||||||||
| 131 | you will actually get 'dance for me'. | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | =head2 C<irc_bot_mentioned> | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | Has the same parameters passed as L<C<irc_public>|POE::Component::IRC/irc_public>. | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | =head2 C<irc_bot_mentioned_action> | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | Has the same parameters passed as L<C<irc_ctcp_action>|POE::Component::IRC/irc_ctcp_*>. | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | Chris 'BinGOs' Williams <chris@bingosnet.co.uk> | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | =cut | ||||||||||||||||||||||||||||