NAME

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

SYNOPSIS

# 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

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

METHODS

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

MyBotNet::Bot::BotName->start;

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.

BOT STATES

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.

TRIGGERS

These triggers may be handled by mixin trigger handlers.

on_setup BRAIN

This is called before the POE kernel has started running. It is passed a reference to the brain plugin that will be stored in the session heap. Instead of calling the functional interface of Data::Remember, mixins will need to make method calls instead (and make sure that the que's past are already normalized into arrays).

on_start

Called just after the kernel has started. The bot should be fully initialized by the time this trigger is called.

MIXIN STATES

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.

AUTHORS

Andrew Sterling Hanenkamp <hanenkamp@cpan.org>

COPYRIGHT AND LICENSE

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.