brengo has asked for the wisdom of the Perl Monks concerning the following question:

My irc bot shall have the possibility to do things at a certain time. Users need to be able to set (show and delete) alarms and get spoken to at the desired time.

Working with Bot::BasicBot::Pluggable I had the idea of using alarms of a POE::Kernel session. Should I go with that idea or is there a simpler/better way to achieve my goal?

When calling run() on the BasicBot object, I don't get the POE object back in any way, to start another session (at least, I didn't see a way). Could you point me into the right direction? How can I start two POE sessions, where one of them is the BasicBot which handles the irc conversations and the other session just takes care about alarms?

Thanks for your help!

This is how the bot is started:
#!/usr/bin/perl use Modern::Perl; use Bot::BasicBot::Pluggable; my $bot = Bot::BasicBot::Pluggable->new( channels => ["#bottest"], server => "irc.test.test", port => "6667", nick => "bot", ); $bot->load('MyModule'); $bot->run();

...and the module where the bot reacts to things said/done in irc looks like this (excerpt):

package Bot::BasicBot::Pluggable::Module::MyModule; use warnings; use strict; use base qw(Bot::BasicBot::Pluggable::Module); sub init { my $self = shift; $self->config( { sc => 2 } ); } sub help { return "Does wild things"; } sub admin { my ($self, $msg) = @_; my $who = $msg->{who}; my $body = $msg->{body}; my $channel = $msg->{channel}; my $address = $msg->{address}; # if($address) { # return "you talk to me"; # } # ... } 1;

Replies are listed 'Best First'.
Re: schedule alarms with POE and Bot::BasicBot::Pluggable ?
by Hinrik (Novice) on Jul 05, 2011 at 03:35 UTC

    In the init method of your plugin module, create a POE session with object states, so that its event handlers will have access to the plugin module (as $self). Then store the session id in the object so that your pluggable handlers can easily send events to the session like this:

    $poe_kernel->post($self->{session_id}, 'add_timer', 'something');

      Thank you Hinrik! Great that you as the maintainer find the time to help me out!

      I am having troubles though. I really tried to get some code out of your words but I failed. The documentation on POE was no help for me (do you have any other suggestions on where to read/learn about poe than on the POE website?). I added to the init method:

      sub init { my $self = shift; $self->config( { user_sc => 2, } ); POE::Session->create( inline_states => { _start => sub { my ($kernel, $heap) = @_[KERNEL, HEAP]; my $session_id = $_[SESSION] -> ID; $self->config( { user_session_id => $session_id, } ); }, test => sub { }, } ); }

      This, however, returns the following error:

      Error loading Can't load MyModule: Bareword "KERNEL" not allowed while + "strict subs" in use at ./MyModule.pm line 34.

      So apart from this error (how do I get rid of it?):
      Did I get the session id the right way? Did I use the right way to store it in $self?