poe::component::irc::plugin::botaddressed(3pm) [debian man page]
POE::Component::IRC::Plugin::BotAddressed(3pm) User Contributed Perl Documentation POE::Component::IRC::Plugin::BotAddressed(3pm)NAME
POE::Component::IRC::Plugin::BotAddressed - A PoCo-IRC plugin that generates events when you are addressed
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'
";
}
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'
";
}
DESCRIPTION
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.
METHODS
"new"
One 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.
OUTPUT EVENTS
"irc_bot_addressed"
Has the same parameters passed as "irc_ctcp_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_mentioned"
Has the same parameters passed as "irc_public".
"irc_bot_mentioned_action"
Has the same parameters passed as "irc_ctcp_action".
AUTHOR
Chris 'BinGOs' Williams <chris@bingosnet.co.uk>
perl v5.14.2 2011-12-07 POE::Component::IRC::Plugin::BotAddressed(3pm)
Check Out this Related Man Page
POE::Component::IRC::Cookbook::Translator(3pm) User Contributed Perl Documentation POE::Component::IRC::Cookbook::Translator(3pm)NAME
POE::Component::IRC::Cookbook::Translator - A bot that can translate text
SYNOPSIS
This bot uses POE::Component::Lingua::Translate to translate text for channel members. It makes use of the "BotCommand" plugin to handle
the translate command.
DESCRIPTION
#!/usr/bin/env perl
use strict;
use warnings;
use Encode qw(decode);
use Encode::Guess;
use IRC::Utils qw(decode_irc parse_user);
use POE;
use POE::Component::IRC::State;
use POE::Component::IRC::Plugin::AutoJoin;
use POE::Component::IRC::Plugin::BotCommand;
use POE::Component::Lingua::Translate;
POE::Session->create(
package_states => [
main => [ qw(_start irc_botcmd_trans translated) ]
],
heap => {
translators => { },
}
);
$poe_kernel->run();
sub _start {
my $heap = $_[HEAP];
my $irc = POE::Component::IRC::State->spawn(
Nick => 'translator_bot',
Server => 'irc.freenode.net',
);
$heap->{irc} = $irc;
$irc->plugin_add('AutoJoin', POE::Component::IRC::Plugin::AutoJoin->new(
Channels => [ '#test_channel1', '#test_channel2' ]
));
$irc->plugin_add('BotCommand', POE::Component::IRC::Plugin::BotCommand->new(
Commands => {
trans => 'Usage: trans <from>,<to> <text>'
}
));
$irc->yield(register => 'botcmd_trans');
$irc->yield('connect');
return;
}
sub irc_botcmd_trans {
my $heap = $_[HEAP];
my $irc = $heap->{irc};
my $nick = parse_user( $_[ARG0] );
my $channel = $_[ARG1];
my ($from, $to, $text) = split /,|s+/, $_[ARG2], 3;
if (!exists $heap->{translators}->{$from . $to}) {
eval {
$heap->{translators}->{$from . $to} = POE::Component::Lingua::Translate->new(
alias => $from . $to,
back_end => 'Babelfish',
src => $from,
dest => $to,
);
};
if ($@) {
$irc->yield(privmsg => $channel, "$nick: There was an error: $@");
return;
}
}
$poe_kernel->post($from . $to => translate =>
decode_irc($text),
{
channel => $channel,
nick => $nick,
}
);
return;
}
sub translated {
my $irc = $_[HEAP]->{irc};
my ($text, $context, $error) = @_[ARG0, ARG1, ARG2];
if ($error) {
$irc->yield(
'privmsg',
$context->{channel},
$context->{nick} . ": There was an error: $error",
);
return;
}
$irc->yield(
'privmsg',
$context->{channel},
$context->{nick} . ': ' . $text,
);
return;
}
AUTHOR
Hinrik Oern Sigur`sson, hinrik.sig@gmail.com
perl v5.14.2 2011-12-07 POE::Component::IRC::Cookbook::Translator(3pm)