Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

AIM Offline Messaging Bot

by mousey (Scribe)
on Jul 22, 2002 at 21:49 UTC ( [id://184247]=sourcecode: print w/replies, xml ) Need Help??
Category: Miscellaneous
Author/Contact Info Sean Murphy (mrmaam-at-subzion.com
Description: This bot will stay online. People can contact the bot and leave messages for someone. When the person that the message was left for signs on, the message will be sent with the screenname of the person who left it. Stats of the bot are stored in the profile.
#!D:\Perl\bin\perl.exe

# Sorry everyone, but I did a little commenting,
# you should be able to get the jist of it.

use Net::AIM;
require 'getopts.pl';

my $username = "";  # Put your screenname here
my $password = "";  # Put your password here

my @to_queue;
my @message_queue;
my @from_queue;
my @time_queue;
my $total = 0;
my $queue = 0;
my $good = 0;

### Make starting timestamp...
my ($min,$hour,$mday,$mon,$year)=(localtime)[1,2,3,4,5];
my $minc;
if ($min < 10){ $minc = ('01','02','03','04','05','06','07','08','09')
+[$min]; } else { $minc = $min; }
my $monc = (Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec)[$mon];
my $yearc = $year + 1900;
my $timestamp = "$hour:$minc on $monc $mday, $yearc";
###

my $aim = new Net::AIM;

### Connecting...
$aim->newconn(Screenname => $username, Password => $password) or die "
+Can't connect to AIM server.\n";
my $aim_connection = $aim->getconn;
###

### Setting Handlers...
$aim_connection->set_handler('config', \&on_config);
$aim_connection->set_handler('error', \&on_error);
$aim_connection->set_handler('im_in', \&on_im);
$aim_connection->set_handler('update_buddy', \&on_update_buddy);
###

$aim->start;

# This happens when you sign in...
sub on_config {
  my ($self, $evt, $from, $to) = @_;
  my $str = shift @{$evt->args()};

  $self->set_config_str($str, 1);
  $self->send_config();
  $aim->set_info("<font face=\"Verdana\" size=1>Welcome to DumbProxy, 
+an AIM bot that allows you to leave messages for your AIM buddies tha
+t are not online at the moment.  Feel free to use it anytime you want
+ to leave a message for someone.<br>Your syntax should be:<br>    Bud
+dyName:Message <br> <br> Since DumbProxy was started at $timestamp, i
+t has recived $total messages.  $good of which were formated corectly
+ and have been placed in the queue.  There are $queue messages left i
+n the queue</font>");
}

# Uh-oh, Pasgettios!
sub on_error {
  my ($self, $evt) = @_;
  my ($error, @stuff) = @{$evt->args()};
  my $errstr = $evt->trans($error);
  $errstr =~ s/\$(\d+)/$stuff[$1]/ge;
  print STDERR "ERROR: $errstr\n";
}

# What we do when we get an instant message,
sub on_im {
  my ($self, $evt, $from, $to) = @_;
  my $args = $evt->args();
  my ($nick, $friend, $msg) = @$args;
  $total++;
  chomp($msg);
  my $stripped = $msg;
  $stripped =~ s/<[^>]+>//g;
  $stripped =~ s/^\s+//g;
  my ($min,$hour,$mday,$mon,$year)=(localtime)[1,2,3,4,5];
  my $minc;
  if ($min < 10){ $minc = ('01','02','03','04','05','06','07','08','09
+')[$min]; } else { $minc = $min; }
  $monc = (Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec)[$mon];
  my $yearc=$year+1900;
  my $time_stamp = "$hour:$minc on $monc $mday, $yearc";
  $self->{_last_msg_dest} = $from;
  $nick = $self->normalize($from);
  print "Message recieved from $nick at $time_stamp\n";
  if ($stripped =~ /\w+:/){
    $bud = $&;
    $stripped =~ s/$bud//;
    $bud =~ s/://;
    $budn= $self->normalize($bud);
    print "    Message is good\n";
    push @to_queue,$budn;
    push @message_queue,$stripped;
    push @from_queue,$nick;
    push @time_queue,$time_stamp;
    $aim_connection->send_im($nick,"<font face=\"Verdana\" size=2>You'
+re message has been recieved and will be sent to $bud as soon as they
+ are online.  There is no guarantee that the message will get to your
+ buddy.  The server could go down, or be bounced or anything else tha
+t would prevent the message from getting to 

them.</font>");
    $aim->add_buddy(1,'Buddies', @to_queue);
    $aim->set_info("<font face=\"Verdana\" size=1>Welcome to DumbProxy
+, an AIM bot by Sean Murphy that allows you to leave messages for you
+r AIM buddies that are not online at the moment.  Feel free to use it
+ anytime you want to leave a message for someone.<br>Your syntax shou
+ld be:<br>    BuddyName:Message <br> <br> Since DumbProxy was started
+ at $timestamp, it has recived $total messages.  $good of which were 
+formatted corectly and have been placed in the queue.  There are $que
+ue messages left in the queue</font>");
    $good++;
    $queue++;
  } else{
    $aim_connection->send_im($nick,"<font face=\"Verdana\" size=1>Welc
+ome to DumbProxy, an AIM bot by Sean Murphy that allows you to leave 
+messages for your AIM buddies that are not online at the moment.  If 
+you were trying to send a message, your syntax was wrong otherwise fe
+el free to use it anytime you want to leave a message for someone.<br
+>Your syntax should be:<br>    BuddyName:Message</font>");
    $aim->set_info("<font face=\"Verdana\" size=1>Welcome to DumbProxy
+, an AIM bot by Sean Murphy that allows you to leave messages for you
+r AIM buddies that are not online at the moment.  Feel free to use it
+ anytime you want to leave a message for someone.<br>Your syntax shou
+ld be:<br>    BuddyName:Message <br> <br> Since DumbProxy was started
+ at $timestamp, it has recived $total messages.  $good of which were 
+formatted corectly and have been placed in the queue.  There are $que
+ue messages left in the queue</font>");
  }
}

sub on_update_buddy {
  my ($self, $evt, $from, $to) = @_;
  my ($nick) = $from;
  my ($bud, $online, $evil, $signon_time, $idle_amount, $user_class) =
+ @{$evt->args()};
  $budn = $self->normalize($bud);
  if($online eq 'T'){
    print "$bud has logged on\n";
    $queue_num = 0;
    while ($queue_num <= $#to_queue){
      if ($budn eq @to_queue[$queue_num]){
        $aim_connection->send_im($bud,"<font face=\"Verdana\" size=2><
+a href=\"aim:goim?screenname=@from_queue[$queue_num]\&message=I\+got\
++your\+message\">@from_queue[$queue_num]</a> left a message for you w
+hile you were away at @time_queue[$queue_num].  The message reads: <b
+r> <br> @message_queue[$queue_num] <br> <br> Thanks for using DumbPro
+xy, an AIM bot that allows you to leave messages for your AIM buddies
+ that are not online at the moment. If <a href=\"aim:goim?screenname=
+@from_queue[$queue_num]\&message=I\+got\+your\+message\">@from_queue[
+$queue_num]</a> or anyone else you want to talk to is not online at t
+he moment please feel free to leave a message for them with it.</font
+>");
        print "    sending queued message to $bud\n";
        splice (@to_queue,$queue_num,1);
        splice (@message_queue,$queue_num,1);
        splice (@from_queue,$queue_num,1);
        splice (@time_queue,$queue_num,1);
        $queue--;
      }
      $queue_num++;
    }
  }
  $aim->set_info("<font face=\"Verdana\" size=1>Welcome to DumbProxy, 
+an AIM bot by Sean Murphy that allows you to leave messages for your 
+AIM buddies that are not online at the moment.  Feel free to use it a
+nytime you want to leave a message for someone.<br>Your syntax should
+ be:<br>    BuddyName:Message <br> <br> Since DumbProxy was started a
+t $timestamp, it has recived $total messages.  $good of which were fo
+rmated corectly and have been placed in the queue.  There are $queue 
+messages left in the queue</font>");
}
Replies are listed 'Best First'.
Re: AIM Offline Messaging Bot
by theorbtwo (Prior) on Jul 22, 2002 at 23:06 UTC

    I like the idea. It's a decent implementation of it too, though there are a few places where it could be improved upon: First, there's a bug in your timestamp generation (minutes 0..9 will show up as 01..10, if it's started at exactly 10 minutes after the hour you'll get a warning and nothing after the : in the time.) But it's better done with POSIX::strftime or with localtime(). Also, you should put some of your common text into vairables and use a sepperate sub for your repeated calls to set_info. Remember, when you cut-and-paste a lot, you're probably better off using some form of abstraction to get one master copy and a bunch of references to it.


    Confession: It does an Immortal Body good.

Re: AIM Offline Messaging Bot
by Anonymous Monk on Nov 11, 2004 at 19:33 UTC
    Hi. I was just wondering if it is possible to check if someone is online. For example if someone isn't on your buddy list and you just want to see if they are on AIM before you send them an IM. I don't see a specific example of it anywhere in the source. Is the only way to add them to the buddy list and wait for AIM to send you status info on them, or can you do it 'on the fly'? Thanks.
      you right click on someone that is already on your buddylist, goto their info, then type in the persons s/n you are seeking to whether they are online or not and then click ok
      A reply falls below the community's threshold of quality. You may see it by logging in.
Re: AIM Offline Messaging Bot
by OxYgEn (Acolyte) on Mar 01, 2004 at 02:36 UTC
    Do I just execute it as a regular perl script from the command prompt?
    These are the errors I get when I try to:

    C:\>perl aimbot.pl
    Can't locate Net/AIM.pm in @INC (@INC contains: C:/Perl/lib C:/Perl/site/lib .)
    at aimbot.pl line 6.
    BEGIN failed--compilation aborted at aimbot.pl line 6.

    C:\>
      well, you have to install Net::AIM first!!!
Re: AIM Offline Messaging Bot
by Anonymous Monk on Feb 23, 2005 at 23:07 UTC
    How Do you get the robot thing?
Re: AIM Offline Messaging Bot
by Anonymous Monk on Mar 14, 2005 at 20:21 UTC
    it is failing on me saying that there is an undefined value in the net::aim script
Re: AIM Offline Messaging Bot
by Anonymous Monk on Jun 26, 2005 at 22:20 UTC
    yeah i dont get this code thing at all. can you just give me a sn that i can use to contact the person i need to

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: sourcecode [id://184247]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-04-24 08:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found