http://www.cnn.com/2000/TECH/computing/08/29/aoliza.idg/index.html http://fury.com/aoliza/ First, the story: a guy wrote a bot using AOL Instant Messenger, some AppleScripts, and Perl to respond to Instant Messenges with Eliza. So I was curious how he did it, and I wrote my own version, since he didn't (yet) make the source available. He apparently did his with tailing the output of some log files. I did my original version that way and sent it to the list a few days ago. Then I figured out I could set AOL IM to execute an AppleScript every time a new IM was received. So I wrote a little AppleScript that says (where << and >> are « and »): on <<event OscrNuIM>> theIM tell application "MacPerl" to <<event OscrNuIM>> theIM end <<event OscrNuIM>> Then I have my bot running in MacPerl, waiting for incoming IMs. At first I used the standard %AppleEvent hash: $AppleEvent{'Oscr', 'NuIM'} = \&handler; The problem was that I would then have to take the incoming Apple event descriptor record and pull out the items and I just didn't want to bother. So I added handle_event() to Mac::AppleEvents::Simple, which looks similar: handle_event('Oscr', 'NuIM', \&handler); But its handler function is passed a Mac::AppleEvents::Simple object. So the handler can do: sub handler { my $evt = shift; my @data = $evt->get; So the new version works pretty well. Check it out below. Requires Mac::Glue, Chatbot::Eliza, and a version of Mac::AppleEvents::Simple not yet on CPAN, but linked to below. --Chris #!perl -w =head1 NAME aoliza_ripoff.plx =head1 SYNOPSIS Watch silly users talk to Eliza. =head1 DESCRIPTION I read about this AOLiza thing where someone used AppleScript and Perl to set up an Eliza bot on AOL Instant Messenger. http://fury.com/aoliza/ I couldn't find the source and wrote my own. You need AOL Instant Messenger and MacPerl (with Chatbot::Eliza, Mac::Glue, and the latest Mac::AppleEvents::Simple). If Mac::AppleEvents::Simple 0.83 is not yet on CPAN yet, get it here: http://pudge.net/files/macperl/temp/Simple.pm Also, you need a short little AppleScript that contains this: on «event OscrNuIM» theIM tell application "MacPerl" to «event OscrNuIM» theIM end «event OscrNuIM» Save the script in your Scripts folders and set it as the handler for "New message arrives" and "message arrives". Also set your prefs to open incoming IMs and not require the knock-knock thingy. =cut use Chatbot::Eliza; use Mac::AppleEvents::Simple 0.83; # for handle_event use Mac::Glue ':all'; use strict; =pod Create a glue for AOL IM (I called my glue "AOLIM"). Give your bot the same name as your AOL IM user. Decide if you want separate bots for each user that sends you an IM (which makes the bot seem a bit more reasonable), or to share one for all users. Run the script, and leave it running, and enjoy. You could use a separate copy of MacPerl to leave it running if you don't want to dedicate MacPerl to this full-time. =cut my $aolim = new Mac::Glue 'AOLIM'; # name of my AOLIM glue my $botname = 'MYUSER'; # AOL IM user name my $separate = 1; # separate bots for each nick my(@im_out, %bots); handle_event('Oscr', 'NuIM', \&handler); while (1) { if (my $im = shift @im_out) { sleep(rand 8); my($nick, $text) = @$im; my $bot = get_bot($nick); # print "[$nick] [$text] [$bot]\n"; $aolim->sendim( screenname => $nick, message => $bot->transform($text), sendnow => 1 ); } } sub get_bot { my $nick = $separate ? shift : 1; if (!exists $bots{$nick}) { my $bot = new Chatbot::Eliza; $bot->name($botname); $bots{$nick} = $bot; # add stuff to Eliza for ('asl', 'a/s/l') { $bot->{keyranks}{$_} = 10; push @{$bot->{decomplist}{$_}}, '*'; push @{$bot->{reasmblist}{$_, '*'}}, "I don't tell strangers my age.", "I don't tell strangers where I live.", "How old do you want me to be?", "Female, of course. Men don't think.", "You first.", "23/m/pa", "99/q/mars", "33/yes/where should I be?"; } } return $bots{$nick}; } sub handler { my($evt) = @_; my @im = $evt->get; my $id = $im[0]; my $text = strip_html($im[9]); push @im_out, [$id, $text] if $id && $text; } # yes, should be improved sub strip_html { local $_ = shift; s/<[^>]*>//g; return $_; } __END__ =head1 HISTORY =over 4 =item v1.0.0, Tuesday, August 29, 2000 First version. Basically just tailed existing log files looking for new IMs. =item v2.0.0, Wednesday, August 30, 2000 Rewrite using an Apple event handler (wow, it is cool that AOL IM does some of this stuff). =back =head1 AUTHOR Chris Nandor E<lt>pudge@pobox.comE<gt>, http://pudge.net/ Copyright (c) 2000 Chris Nandor. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the Artistic License, distributed with Perl. =head1 VERSION 2.0.2, Friday, September 1, 2000 # ===== Want to unsubscribe from this list? # ===== Send mail with body "unsubscribe" to macperl-request@macperl.org