Subject: | attribute getting lost |
Hello,
I've attached code for a minimal IRC bot - the channel, password, etc
have been replaced by dummy values.
When running this bot I see the following error message:
S_004 call on plugin 'NickServID' failed: Can't call method "yield" on
an undefined value at
/usr/local/share/perl/5.10.0/POE/Component/IRC/Plugin/NickServID.pm line 60.
Password authentication fails on the network.
If I insert the line:
$self->{irc} = $irc;
into the S_004 method the error message is gone and the '/nickserv
identify' succeeds.
I think my code is the same as is described in the POD, but if not I'd
be glad to hear where I've gone wrong.
Thanks,
John O'Brien
Subject: | minimal_bot.pl |
#!/usr/bin/perl
use strict;
use warnings;
use Carp;
use POE;
use POE::Component::Cron;
use POE::Component::IRC::State;
use POE::Component::IRC::Common qw( :ALL );
use POE::Component::IRC::Plugin::Connector;
use POE::Component::IRC::Plugin::NickServID;
use Readonly;
Readonly::Scalar my $BOT_NICK => 'nick';
Readonly::Scalar my $CHANNEL => '#channel_name'; # Autojoin here.
Readonly::Scalar my $NICKSERV_PASSWORD => 'password';
Readonly::Scalar my $USERNAME => 'name';
Readonly::Scalar my $IRCNAME => 'ircname';
Readonly::Scalar my $SERVER => 'server';
Readonly::Scalar my $SERVER_LIST => [ ['server1'],
['server2'] ];
Readonly::Scalar my $PORT => 6668;
print {*STDOUT} "Spawning...\n" || carp;
my $irc = POE::Component::IRC::State->spawn( Raw => 1,
plugin_debug => 1 );
POE::Session->create( inline_states => { _start => \&bot_start,
irc_001 => \&bot_connected,
irc_notice => \&on_notice, }, );
my $nsplugin = POE::Component::IRC::Plugin::NickServID->
new( Password => $NICKSERV_PASSWORD );
$irc->plugin_add( 'NickServID', $nsplugin );
print {*STDOUT} "Connecting...\n" || carp;
$poe_kernel->run();
sub bot_start {
my ($session) = $_[SESSION];
$irc->yield( register => 'all' );
$irc->yield( connect => { Nick => $BOT_NICK,
Username => $USERNAME,
Ircname => $IRCNAME,
Server => $SERVER,
Port => $PORT,
Raw => 1, }
);
return;
}
sub bot_connected {
print {*STDOUT} "Joining $CHANNEL...\n" || carp;
$irc->yield( join => $CHANNEL );
$irc->yield( mode => $BOT_NICK => '+B' );
return;
}
sub on_notice {
my ( $nickhost, $msg ) = @_[ ARG0, ARG2 ];
my $nick = ( split m/!/msx, $nickhost )[0];
print {*STDOUT} "$nick: $msg\n" || carp;
return;
}