Bot::Net::Mixin::Bot::IRC - mixin class for building IRC bots
# Build an Eliza chatbot for IRC use strict; use warnings; package MyBotNet::Bot::Eliza; 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 $event = get ARG0; my $reply = recall('eliza')->transform( $event->message ); yield reply_to_sender => $message, $reply; }; 1;
This is the mixin-class for Bot::Net IRC bots. You "inherit" all the features of this mixin by using the class:
use Bot::Net::Bot; # define a Bot::Net bot use Bot::Net::Mixin::Bot::IRC; # become an IRC bot
Adds the IRC component to the bot's memory on setup.
Returns a base configuration for an IRC bot.
The following states are avaiable for your bot to implement.
This is automatically yielded by "on _start" unless the auto_connect configuration option is set to "0". If it is set to "0", you may emit this state to cause the bot to connect to the IRC server.
auto_connect
This state is emitted as soon as the bot has connected to the server and the server has passed back a message. This means it is now safe to communicate with the server.
This state occurs when the bot observes a message sent to a channel it is in, but the message is not directed at the bot (i.e., is not prefixed with "MyNick:").
The EVENT is a Bot::Net::Message object setup to contain the group message.
EVENT
This state occurs when either the bot observes a message sent to a channel that it is in that has been prefixed with "MyNick:" or a private message was sent directly to the bot.
The EVENT is a Bot::Net::Message object setup for either a group or private message depending on which occurred. If a pblic message the "MyNick:" part of the message will have been stripped.
Sets up the IRC client.
Tells the IRC component to connect to the IRC server using the configuration stored in the irc_connect option of the configuration.
irc_connect
Connects to the channels that the bot has been configured to join. This then fires the "on bot connected" event which indicates that it is now safe to issue IRC commands, if your bot needs to do so.
Handles bot disconnections. If the bot becomes disconnected it will automatically attempt to reconnect until the server returns or lets the bot back. It will attempt to do so in a way that will not cause it to be blocked for flooding.
This state is invoked by "on irc_disconnected" and related states. This tells the IRC client to attempt ot reconnect. This will be called repeatedly (on a delay) until a connection is reestablished.
Handles IRC messages sent directly to the bot. This emits:
See "bot message_to_me".
Handles IRC messages sent to a public channel. This then emits additional bot states:
Reports that a message was sent to a channel the bot is in. See "bot message_to_group".
Reports that a messages was sent to me publically in a channel. See "bot message_to_me".
This sends the given MESSAGE to the given DESTINATION.
MESSAGE
DESTINATION
The DESTINATION may be one of the following:
#channel
The name of a channel to send to. In this case, no special modifications will be made to the message.
nick
The name of a nick to send to. In this case, no special modifications will be made to the message.
[ #channel1, #channel2, nick1, nick2 ]
A list of channels and nicks to send to. In this case, no special modifications will be made to the message.
{ #channel1 => nick1, #channel2 => [ nick1, nick2 ] }
A hash of channels pointing to nicks. The nicks may be either a single nick or an array of nicks. In this case, the messages will have the given nick (or nicks) prepended to every message sent (except continuations).
If MESSAGE contains new lines (\n), then the message will be broken up and sent in pieces.
If any message that would be sent to the server approaches the 512 byte limit on IRC messages, the line will be broken. The broken line will have a backslash (\) appended at the break point of the message to signal the recipient that the line was broken. A line may be broken multiple times.
Sends the MESSAGE back to the nick that sent the given EVENT. The EVENT should be a Bot::Net::Message object. The MESSAGE may be broken up and chunked as specified in "send_to".
This method will reply back to a user in all the channels it received the message in if the EVENT was sent to a channel (or group of channels) or will send privately back if the EVENT was private.
Sends the MESSAGE back to the nick that sent the given EVENT, but via a private message directly to their nick, even if the original EVENT took place as a channel message.
Sends the MESSAGE back to the nick that sent the given EVENT, but via the public group name in the CHANNEL argument.
CHANNEL
This is similar to "reply_to_sender", except that if sent to a channel, the sender will not be identified by nick.
This causes the IRC client to close down the connection and quit.
Andrew Sterling Hanenkamp <hanenkamp@cpan.org>
<hanenkamp@cpan.org>
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.
To install Bot::Net, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Bot::Net
CPAN shell
perl -MCPAN -e shell install Bot::Net
For more information on module installation, please visit the detailed CPAN module installation guide.