22 August 2002

Eliza Gaim Plugin

This is a small perl plugin I have made for Gaim. It uses the Chatbot::Eliza module by (download from CPAN) which imitates a phychotherapist, and responds to all instant messages that arrives. I read an article by Randal L. Schwartz, and wanted to have some fun with my buddies. Try it if you like, it doesn't matter, it's all the same.

use Chatbot::Eliza;
GAIM::register("Eliza", "0.0.1", "end", "");

my($myname) = "Per Henrik";
my($elizaname) = "Eliza";

my(@ids) = GAIM::get_info(1);

my(%buddy) = ();

foreach $id (@ids) {
my($pro) = GAIM::get_info(7, $id);
my($nam) = GAIM::get_info(3, $id);
$msg .= "\n$nam using $pro";

GAIM::print("Eliza activated.", "$elizaname signing on. Responding on behalf of $msg");

GAIM::add_event_handler("event_im_recv", "doEliza");

sub doEliza {
my($index) = $_[0];
my($who) = $_[1];
my($text) = $_[2];
my($flags) = $_[3];

if(defined($buddy{$who})) {
my($eliza) = $buddy{$who};
my($eliza_says) = $eliza->transform($text);
GAIM::print_to_conv($index, $who, $eliza_says, 0);
} else { # first time $who sends a message to me
GAIM::print_to_conv($index, $who, "Hello, how are you?", 0);
GAIM::print_to_conv($index, $who, "$myname is not here right now.", 0);
GAIM::print_to_conv($index, $who, "He is probably working, sleeping, eating or whatever.",
GAIM::print_to_conv($index, $who, "You can chat with me if you like.", 0);
GAIM::print_to_conv($index, $who, "My name is $elizaname.", 0);
GAIM::print_to_conv($index, $who, "How are you feeling today?", 0);
$buddy{$who} = new Chatbot::Eliza();

sub end {
GAIM::print("Eliza unload", "$elizaname signing off.");