This file is indexed.

/usr/share/perl5/POE/Component/IRC/Plugin/BotAddressed.pm is in libpoe-component-irc-perl 6.78+dfsg-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package POE::Component::IRC::Plugin::BotAddressed;
BEGIN {
  $POE::Component::IRC::Plugin::BotAddressed::AUTHORITY = 'cpan:HINRIK';
}
BEGIN {
  $POE::Component::IRC::Plugin::BotAddressed::VERSION = '6.78';
}

use strict;
use warnings FATAL => 'all';
use Carp;
use POE::Component::IRC::Plugin qw( :ALL );

sub new {
    my ($package) = shift;
    croak "$package requires an even number of arguments" if @_ & 1;
    my %args = @_;

    $args{lc $_} = delete $args{$_} for keys %args;
    return bless \%args, $package;
}

sub PCI_register {
    my ($self, $irc) = splice @_, 0, 2;
    $irc->plugin_register( $self, 'SERVER', qw(ctcp_action public) );
    return 1;
}

sub PCI_unregister {
    return 1;
}

sub S_ctcp_action {
    my ($self, $irc) = splice @_, 0, 2;
    my $who = ${ $_[0] };
    my $recipients = ${ $_[1] };
    my $what = ${ $_[2] };
    my $me = $irc->nick_name();
    my $chantypes = join('', @{ $irc->isupport('CHANTYPES') || ['#', '&']});

    my $eat = PCI_EAT_NONE;
    return $eat if $what !~ /$me/i;

    for my $recipient (@{ $recipients }) {
        if ($recipient =~ /^[$chantypes]/) {
            $eat = PCI_EAT_ALL if $self->{eat};
            $irc->send_event_next(irc_bot_mentioned_action => $who => [$recipient] => $what);
        }
    }

    return $eat;
}

sub S_public {
    my ($self, $irc) = splice @_, 0, 2;
    my $who = ${ $_[0] };
    my $channels = ${ $_[1] };
    my $what = ${ $_[2] };
    my $me = $irc->nick_name();
    my ($cmd) = $what =~ m/^\s*\Q$me\E[:,;.!?~]?\s*(.*)$/i;

    return PCI_EAT_NONE if !defined $cmd && $what !~ /$me/i;

    for my $channel (@{ $channels }) {
        if (defined $cmd) {
            $irc->send_event_next(irc_bot_addressed => $who => [$channel] => $cmd );
        }
        else {
            $irc->send_event_next(irc_bot_mentioned => $who => [$channel] => $what);
        }
    }

    return $self->{eat} ? PCI_EAT_ALL : PCI_EAT_NONE;
}

1;

=encoding utf8

=head1 NAME

POE::Component::IRC::Plugin::BotAddressed - A PoCo-IRC plugin that generates
events when you are addressed

=head1 SYNOPSIS

 use POE::Component::IRC::Plugin::BotAddressed;

 $irc->plugin_add( 'BotAddressed', POE::Component::IRC::Plugin::BotAddressed->new() );

 sub irc_bot_addressed {
     my ($kernel, $heap) = @_[KERNEL, HEAP];
     my $nick = ( split /!/, $_[ARG0] )[0];
     my $channel = $_[ARG1]->[0];
     my $what = $_[ARG2];

     print "$nick addressed me in channel $channel with the message '$what'\n";
 }

 sub irc_bot_mentioned {
     my ($nick) = ( split /!/, $_[ARG0] )[0];
     my ($channel) = $_[ARG1]->[0];
     my ($what) = $_[ARG2];

     print "$nick mentioned my name in channel $channel with the message '$what'\n";
 }

=head1 DESCRIPTION

POE::Component::IRC::Plugin::BotAddressed is a
L<POE::Component::IRC|POE::Component::IRC> plugin. It watches for public
channel traffic (i.e. C<irc_public> and C<irc_ctcp_action>) and will generate
an C<irc_bot_addressed>, C<irc_bot_mentioned> or C<irc_bot_mentioned_action>
event if its name comes up in channel discussion.

=head1 METHODS

=head2 C<new>

One optional argument:

B<'eat'>, set to true to make the plugin eat the C<irc_public> /
C<irc_ctcp_action>
event and only generate an appropriate event, default is false.

Returns a plugin object suitable for feeding to
L<POE::Component::IRC|POE::Component::IRC>'s C<plugin_add> method.

=head1 OUTPUT EVENTS

=head2 C<irc_bot_addressed>

Has the same parameters passed as L<C<irc_ctcp_public>|POE::Component::IRC/irc_public>.
C<ARG2> contains the message with the addressed nickname removed, ie. Assuming
that your bot is called LameBOT, and someone says 'LameBOT: dance for me',
you will actually get 'dance for me'.

=head2 C<irc_bot_mentioned>

Has the same parameters passed as L<C<irc_public>|POE::Component::IRC/irc_public>.

=head2 C<irc_bot_mentioned_action>

Has the same parameters passed as L<C<irc_ctcp_action>|POE::Component::IRC/irc_ctcp_*>.

=head1 AUTHOR

Chris 'BinGOs' Williams <chris@bingosnet.co.uk>

=cut