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


Bot-Net documentation  | view source Contained in the Bot-Net distribution.

Index


NAME

Top

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

SYNOPSIS

Top

  # 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;
  };

  1;

DESCRIPTION

Top

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:

METHODS

Top

import

Custom exporter for this mixin.

bot

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.

setup

Top

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.

BOT STATES

Top

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.

MIXIN STATES

Top

The base mixin handles the following states.

on _start

Performs a number of setup tasks. Including:

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.

AUTHORS

Top

Andrew Sterling Hanenkamp <hanenkamp@cpan.org>

COPYRIGHT AND LICENSE

Top


Bot-Net documentation  | view source Contained in the Bot-Net distribution.