POE::Component::IRC::Plugin::YouAreDoingItWrong - show people what they are doing wrong by giving links to http://doingitwrong.com images.
use strict; use warnings; use POE qw(Component::IRC Component::IRC::Plugin::YouAreDoingItWrong); my $irc = POE::Component::IRC->spawn( nick => 'WrongBot', server => 'irc.freenode.net', port => 6667, ircname => 'You Are Doing It Wrong Bot', ) or die "Oh noes :( $!"; POE::Session->create( package_states => [ main => [ qw( _start irc_001 ) ], ], ); $poe_kernel->run(); sub _start { $irc->yield( register => 'all' ); # register our plugin $irc->plugin_add( 'Wrong' => POE::Component::IRC::Plugin::YouAreDoingItWrong->new ); $irc->yield( connect => { } ); undef; } sub irc_001 { my ( $kernel, $sender ) = @_[ KERNEL, SENDER ]; $kernel->post( $sender => join => '#zofbot' ); undef; } -- [13:00:27] <Zoffix> WrongBot, doing it wrong Zoffix [13:00:27] <WrongBot> Zoffix, you are doing it wrong: http://www.doingitwrong.com/wrong/20070527-113353.jpg [13:00:41] <Zoffix> WrongBot, doing it wrong [13:00:42] <WrongBot> You are doing it wrong: http://www.doingitwrong.com/wrong/1487_kolo.jpg
The module is a POE::Component::IRC plugin which, when triggered, fetches links to images from http://doingitwrong.com and posts them into the channel, optionally addressing a specific person.
$irc->plugin_add( 'Wrong' => POE::Component::IRC::Plugin::YouAreDoingItWrong->new ); $irc->plugin_add( 'Wrong' => POE::Component::IRC::Plugin::YouAreDoingItWrong->new( auto => 0, # do not auto respond trigger => qr/^wrong/i, # trigger banned => [ qr/aol\.com$/ ], # ignore AOL users response_event => 'diw_event', # event to send response to debug => 1, # enable some debug output ) );
Returns a POE::Component::IRC::Plugin object suitable to be fed to POE::Component::IRC plugin_add() method. Takes a few arguments, all of which are optional. The arguments may be as follows:
plugin_add()
->new( auto => 1 );
Optional. The auto argument specifies whether or not the plugin should auto respond with privmsg to the channel when triggered. If auto is set to a true value the plugin will automatically respond when triggered, when auto is set to a false value the plugin will not send any messages to the server and you'll have to listen to the event emitted by the plugin (see below). In other words, if you are unhappy with the default behaviour you may turn auto off (by setting it to a false value) and set up a handler on the plugin event to do exactly what you want. Defaults to: 1
auto
privmsg
1
->new( trigger => qr/^doing it wrong/i );
Optional. Takes a regex as an argument which specifies the trigger for the plugin. Defaults to: qr/^doing it wrong/i Note: plugin responds to addressed messages, In other words, if you set the trigger to qr/^diw/i and your bot's nick name is WrongBot the plugin will be triggered by saying WrongBot, diw. Note 2: if after removing bot's nickname and the trigger the left over will match m/(\S+)\s*$/ the capture will be prepended to the output, this is so you could address a specific person:
qr/^doing it wrong/i
qr/^diw/i
WrongBot
WrongBot, diw
m/(\S+)\s*$/
[13:00:27] <Zoffix> WrongBot, doing it wrong Zoffix [13:00:27] <WrongBot> Zoffix, you are doing it wrong: http://www.doingitwrong.com/wrong/20070527-113353.jpg [13:00:41] <Zoffix> WrongBot, doing it wrong [13:00:42] <WrongBot> You are doing it wrong: http://www.doingitwrong.com/wrong/1487_kolo.jpg
->new( banned => [ qr/aol\.com$/ ] );
Optional. Takes an arrayref of regexes as an argument. If the user mask of the person who triggered the plugin matches any of the regexes in the banned arrayref the plugin will ignore that person. Defaults to: [] (no bans are set)
banned
[]
->new( response_event => 'diw_event' );
Optional. Specifies the name of the event to emit when plugin is triggered. See EMITTED EVENTS section for details. Defaults to: irc_you_are_doing_it_wrong_response
irc_you_are_doing_it_wrong_response
->new( debug => 1 );
Optional. When set to a true value plugin will print out a bit of debug information. Defaults to: 0 (no debug info is printed out)
0
->new( eat => 0 );
If set to a false value plugin will return a PCI_EAT_NONE after responding. If eat is set to a true value, plugin will return a PCI_EAT_ALL after responding. See POE::Component::IRC::Plugin documentation for more information if you are interested. Defaults to: 1
PCI_EAT_NONE
PCI_EAT_ALL
$VAR1 = { 'what' => 'WrongBot, doing it wrong', 'who' => 'Zoffix!n=Zoffix@unaffiliated/zoffix', 'channel' => '#zofbot', 'nick_to_address' => undef, 'error' => undef, 'pic' => bless( do{\(my $o = 'http://www.doingitwrong.com/wrong/20070929-012129.jpg')}, 'URI::http' ) };
The event handler set up to handle the event, name of which you can specify in the response_event of the constructor (it defaults to irc_you_are_doing_it_wrong_response) will receive input from the plugin every time it's triggered. The input will come in the form of a hashref in ARG0. The keys of that hashref are as follows:
response_event
ARG0
{ 'what' => 'WrongBot, doing it wrong' }
The what key will contain the message which triggered the plugin.
what
{ 'who' => 'Zoffix!n=Zoffix@unaffiliated/zoffix' }
The who key will contain the mask of the user who triggered the plugin.
who
{ 'nick_to_address' => undef }
The nick_to_address key will contain the nick of the person to address if the plugin was triggered in the "address someone" mode (see description of the trigger argument to the constructor) or undef if plugin was triggered in normal mode.
nick_to_address
trigger
undef
{ error => undef }
If an error occurred during while fetching the link to a random image on http://doingitwrong.com the error key will contain the error message, otherwise it will be undef.
error
{ 'pic' => bless( do{\(my $o = 'http://www.doingitwrong.com/wrong/20070929-012129.jpg')}, 'URI::http' ) }
If no errors occurred (see error above), the pic key will contain a URI object pointing to one of the images on http://www.doingitwrong.com.
pic
Fork this module on GitHub: https://github.com/zoffixznet/POE-Component-IRC-PluginBundle-Toys
To report bugs or request features, please use https://github.com/zoffixznet/POE-Component-IRC-PluginBundle-Toys/issues
If you can't access GitHub, you can email your request to bug-POE-Component-IRC-PluginBundle-Toys at rt.cpan.org
bug-POE-Component-IRC-PluginBundle-Toys at rt.cpan.org
Zoffix Znet <zoffix at cpan.org> (http://zoffix.com/, http://haslayout.net/)
You can use and distribute this module under the same terms as Perl itself. See the LICENSE file included in this distribution for complete details.
LICENSE
To install POE::Component::IRC::PluginBundle::Toys, copy and paste the appropriate command in to your terminal.
cpanm
cpanm POE::Component::IRC::PluginBundle::Toys
CPAN shell
perl -MCPAN -e shell install POE::Component::IRC::PluginBundle::Toys
For more information on module installation, please visit the detailed CPAN module installation guide.