Bot::Net::Bot - the base class for all Bot::Net bots


  # An example for building an Eliza-based chatbot
  use strict;
  use warnings;

  use Bot::Net::Bot;
  use Bot::Net::Mixin::Bot::IRC;
  use Chatbot::Eliza; # available separately on CPAN

  on bot startup => run {
      remember eliza => Chatbot::Eliza->new;

  on bot message_to_me => run {
      my $message = get ARG0;

      my $reply = recall('eliza')->transform( $message->text );
      yield reply_to_sender, $message, $reply;



This is the primary mixin-class for all Bot::Net bots. You "inherit" all the features of this mixin by using the class:

  use Bot::Net::Bot; # This is a bot class now

Some things to know about how Bot::Net bots work:

  • There is a one-to-one relationship between packages and bot instances. If you want two bots that do the same thing, you will need two different packages. Fortunately, it's easy to clone a bot:

      package MyBotNet::Bot::Chatbot;
      use Bot::Net::Bot;
      # define some state handlers...
      package MyBotNet::Bot::Chatbot::Larry;
      use MyBotNet::Bot::Chatbot;
      package MyBotNet::Bot::Chatbot::Bob;
      use MyBotNet::Bot::Chatbot;

    This defines three bots that all do the same thing--in this case, we probably only intend to invoke Larry and Bob, but you can do whatever you like.

  • TODO FIXME XXX Implement these things...

    Make sure you use the botnet command to help you out in this process.

      bin/botnet bot create Chatbot
      bin/botnet bot create Chatbot::Larry Chatbot
      bin/botnet bot create Chatbot::Bob Chatbot

    This will create the scaffolding required to setup the classes mentioned in the previous bullet. You can then configure them to run:

      bin/botnet bot host Chatbot::Larry ServerA
      bin/botnet bot host Chatbot::Bob ServerB



Custom exporter for this mixin.


This is a helper for POE::Declarative. That lets you prefix "bot_" to your POE states. For example:

  on bot message_to_me => run { ... };

is the same as:

  on bot_message_to_me => run { ... };

It can also be used to yield messages:

  yield bot 'startup';

You may choose to use it or not.


This method is called to tell the bot to startup. It finds all the mixins that have been added into the class and calls the "setup" method for each.

default_configuration PACKAGE

Returns a base configuration appropriate for all bots.


on bot startup

Bots should implement this event to perform any startup tasks. This is bot-specific and mixins should not do anything with this event.

on bot quit MESSAGE

Bots may emit this state to ask the protocol client and all resources attached to the bot to close. The MESSAGE parameter allows you to pass a human readable message that can be passed on as part of the protocol quit or logged or whatever...

If all mixins are implemented correctly, this should very quickly result in the bot entering the "on _stop" state and "on bot shutdown". (If not, the bot may be stuck in a sort of zombie state unable to die.)

on bot shtudown

This is called (synchronously) during teh "on _stop" handler immediately before shutdown to handle any last second clean up.


The base mixin handles the following states.

on _start

Performs a number of setup tasks. Including:

  • Register to receive messages from the IRC component.

  • Connect to the IRC server.

  • When finished, it fires the "on bot startup" event.

on _default

Performs logging of unhandled events. All these logs are put into the DEBUG log, so they won't show up unless DEBUG logging is enabled in your Log::Log4perl configuration.

on _stop

This calls (synchronously) the "on bot shutdown" state, to handle any final clean up before quitting.


Andrew Sterling Hanenkamp <>


Copyright 2007 Boomer Consulting, Inc. All Rights Reserved.

This program is free software and may be modified and distributed under the same terms as Perl itself.