Banging out an AIM bot

June 25th, 2006 | Filed under Code snippets, Perl

I’m not a Perl developer by any means (Python’s my poison) but I wanted to build a quick AIM bot, and Perl’s OSCAR.pm lets you do it in less than 20 lines of code. It’s insane how simple this is:

use warnings;
use strict;
use Net::OSCAR qw(:standard);
my $oscar;
$oscar = Net::OSCAR->new();
$oscar->set_callback_im_in(&im_in);
$oscar->signon($screenname, $password);
while(1)
{
$oscar->do_one_loop();
}
sub im_in {
my($oscar, $sender, $message, $is_away) = @_;
print "[AWAY] " if $is_away;
print "$sender: $message\n";
$response = "Hello";
$oscar->send_im($sender, $response);
}

I wrote a bot which executes a shell script that reads and writes to your todo.txt (more on that in a minute.) Mark ran with the idea and we discussed keeping a bot that can run other scripts on your computer, like “open VNC port” instead of using port knocking or leaving your server port open at all times. The trick is the bot only runs commands from authorized AIM names. I’m not sure how secure that is, but it is a neat idea.

Build Your Own AIM Answerbot [On LAMP]