| POE-Component-IRC documentation | Contained in the POE-Component-IRC distribution. |
POE::Component::IRC::Plugin::BotAddressed - A PoCo-IRC plugin that generates events when you are addressed
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";
}
POE::Component::IRC::Plugin::BotAddressed is a
POE::Component::IRC plugin. It watches for public
channel traffic (i.e. irc_public and irc_ctcp_action) and will generate
an irc_bot_addressed, irc_bot_mentioned or irc_bot_mentioned_action
event if its name comes up in channel discussion.
newOne optional argument:
'eat', set to true to make the plugin eat the irc_public /
irc_ctcp_action
event and only generate an appropriate event, default is false.
Returns a plugin object suitable for feeding to
POE::Component::IRC's plugin_add method.
irc_bot_addressedHas the same parameters passed as irc_ctcp_public|POE::Component::IRC/irc_public.
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'.
irc_bot_mentionedHas the same parameters passed as irc_public|POE::Component::IRC/irc_public.
irc_bot_mentioned_actionHas the same parameters passed as irc_ctcp_action|POE::Component::IRC/irc_ctcp_*.
Chris 'BinGOs' Williams <chris@bingosnet.co.uk>
| POE-Component-IRC documentation | Contained in the POE-Component-IRC distribution. |
package POE::Component::IRC::Plugin::BotAddressed; BEGIN { $POE::Component::IRC::Plugin::BotAddressed::AUTHORITY = 'cpan:HINRIK'; } BEGIN { $POE::Component::IRC::Plugin::BotAddressed::VERSION = '6.68'; } 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;