Posted: Wed May 24, 2006 11:15 pm Post subject: Getting bot to respond
I got my bot to login to aim, but how would i get it to respond to certain phrases. Like is i said hi, how would i get it to say hello? Would i use an if statement?
You could use an if statement, or you could use a module that's specifically made for bot reply sets.
There are a few available on this forum, namely Trigger, Blab, and Banter, and there are some on CPAN.
Here's the two I know of on CPAN:
RiveScript - http://search.span.org/perldoc?RiveScript
This module's a good one for writing responses for your bot, it's a kind of "scripting" language, the source of a RiveScript file can look as simple as this, for your example:
Code:
+ hi
- hello
(+ is human input, - is the bot's reply)
There's a RiveScript forum here on Bot-Depot too. I posted an example of a full bot brain I wrote in RiveScript with lots of replies already. It's under the "RiveScript 0.21" topic. So check that out too.
Chatbot::Eliza - http://search.cpan.org/perldoc?Chatbot::Eliza
This module is the implementation of the classic Eliza therapist bot. It's not very flexible for having custom replies, but it sure pretends to know what you're talking about and acts like it can understand ya. _________________ Current Site (2008) http://www.cuvou.com/
You'd probably create a RiveScript object somewhere before any on_im's are called (probably in your main script, before Net::OSCAR even connects to AIM).
Code:
# Create a global RiveScript object
our $RiveScript = new RiveScript();
# ... connect to aim ...
our $oscar = new Net::OSCAR (...);
And in your on_im event:
Code:
my $reply = $RiveScript->reply ($screenname, $message, scalar => 1);
where $screenname and $message are the user's s/n and message as gotten in the handler.
(see the manpage for RiveScript about what scalar=>1 in the reply() method does; you may want to omit it to have RiveScript return an array)
Then you'd send_im the $reply back.
(if you're not sure how to install modules, a lil trick for pure-Perl modules is to extract the distribution (zip file) somewhere, then copy what's inside its "lib" folder to your Perl/site/lib folder) _________________ Current Site (2008) http://www.cuvou.com/