NAME
Net::Ewtoo::Bot - a Ewtoo-compatible talker robot client module
SYNOPSIS
use Net::Ewtoo::Bot;
my $NAME = 'jodbot';
my $bot = new Net::Ewtoo::Bot;
$bot->add_trigger("(.+?) says '$NAME, (.+?)'", \&handle_say);
$bot->set_delay('range', 0, 5);
$bot->login($host, $port, $user, $pass);
$bot->say("Hi! I'm the $NAME robot!");
$bot->listen();
$bot->logout();
exit;
sub handle_say {
my ($sayer, $said) = @_;
if ($said eq 'hello') {
$bot->say("Why hello $sayer!");
} elsif ($said eq 'please go away') {
$bot->say("OK, bye!");
$bot->logout();
}
return;
}
DESCRIPTION
Net::Ewtoo::Bot provides an object-oriented interface to Ewtoo (http://www.ewtoo.org/) type talker systems. The module provides support for the most common Ewtoo talker commands, as well as input pattern matching and callback triggers and timers.
INSTALLATION
To install this package, just change to the directory which you created by untarring the package, and type the following:
perl Makefile.PL
make test
make
make install
This will copy Bot.pm to your perl library directory for use by all perl scripts. You probably must be root to do this, unless you have installed a personal copy of perl.
METHODS
$bot->login($host, $port, $user, $pass);
This logs the bot into the $host:$port talker using $user and $pass. The bot will send extra carriage returns to bypass MOTDs and saved messages.
Any defined login subroutines are executed at this point.
$bot->logout($message);
Sends the "QUIT" command (in capitals for compatability with MBA4), and closes the socket. Any defined logout subroutines are executed beforehand. If $message is defined, the bot calls the "mquit" command with $message as its argument.
$bot->set_delay($type, $lower, $upper);
This method sets the delay between between the calling of a method and its execution. This is useful for adding a realistic delay during communications with another user. $type can be either 'fixed', in which case the delay is always $lower (in seconds) and $upper is ignored, or 'range', in which case the delay will be a random number of seconds between $lower and $upper.
$bot->add_trigger($pattern, $callback);
This method adds a trigger used by the listen() method. When a line of input is received that matches $pattern, $callback is executed. The arguments to $callback are any captured substrings you define in your pattern, which is a regular perl regexp (without the trailing and leading slashes).
$bot->delete_trigger($pattern);
Removes the trigger associated with $pattern from the trigger list.
$bot->def_login($callback);
Specifies a subroutine with $callback that will be executed after the bot logs in.
$bot->def_logout($callback);
Specifies a subroutine with $callback that will be executed before the bot logs out.
$bot->listen($verbose);
listen() reads input from the talker and executes triggers as necessary. If $verbose is set to 1, then any input received is printed to STDOUT.
$bot->break();
$break() sets a flag that tells the listen() method to finish and return.
$bot->say($str);
A convenience function that makes the bot say $str.
$bot->think($str);
A convenience function that makes the bot think $str.
$bot->shout($str);
A convenience function that makes the bot shout $str.
$bot->tell($user, $str);
A convenience function that makes the bot tell $str to $user.
$bot->command($cmd);
Allows the calling of an arbitrary talker command.
$bot->getline();
Reads a single line of input from the talker.
COPYRIGHT
This module is (c) 2001,2002 Gavin Brown (gavin.brown@uk.com), with additional input and advice from Richard Lawrence (richard@fourteenminutes.com).
This module is licensed under the same terms as Perl itself.
TO DO
Implement a timing mechanism for scheduled stuff.
SEE ALSO
The Ewtoo website at http://www.ewtoo.org, and the PlayGround Plus website at http://pgplus.ewtoo.org/.