#!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>");
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.