1. Technology

Perl Module Net::OSCAR

How to create an AIM or ICQ Bot in Perl with the Net::OSCAR Perl module.

By

Man working on a laptop
Hemant Mehta/Getty Images
Ever wanted to create your own 'bot to automate chatting over instant messaging? It sounds like a complex task, but it's as easy as downloading a single Perl module from CPAN and writing a short script. You will need an AIM or ICQ account as well, and it will be taken over by the bot when it is active, so you won't be able to use the same account for yourself at the same time.

First, like all non-standard Perl modules, you will need to install Net::OSCAR from CPAN, and then you can include it at the top of your Perl programs with the use statement:

 use Net::OSCAR qw(:standard); 
You can then use the module to create and activate a new bot:
 my $aimbot = Net::OSCAR->new(capabilities => [qw(extended_status typing_status)]);
 $aimbot->signon(SCREEN_NAME, PASSWORD); 
The real power of the module is in it's capability to create callback subroutines that run on a specific action. For instance, let's say I want my bot to respond with the text 'hello there' every time it receives a message from someone else. First, I'll need to set a callback function for the on_im action.
 $aim->set_callback_im_in (\&say_hello); 
Then, later in the script, we define the say_hello function that is called on every reception of an instant message.
 sub on_im {
   my ($aim, $sender, $message, $away) = @_;
   $aim->send_im($sender, 'hello there');
 } 
Module Links:
  1. Net::OSCAR on CPAN
  2. Net::OSCAR Documentation
  3. Matthew Sachs
  1. About.com
  2. Technology
  3. Perl
  4. Programming Perl
  5. Packages & Modules
  6. Perl Module Net::OSCAR - How to create an AIM or ICQ Bot in Perl with the Net::OSCAR Perl module.

©2014 About.com. All rights reserved.