It's been a while since I've done anything useful with Net::AIM, but I remember that it needs to handle some config events before any messages can be sent. I also noticed that AIM will not send messages if the connection is closed too soon (thus the sleep).
This code below does the job. DEBUG is on to show some useful information, but I'd also suggest adding some print statements to gain an even better understanding of how Net::AIM functions.
#!/usr/bin/perl
use strict;
use Net::AIM;
sub DEBUG() { 1 }
my $aim = new Net::AIM;
$aim->debug(1) if (DEBUG); # provides helpful information
$aim->newconn( Screenname => 'my_name', Password => 'my_password' ) or
+ die "Can't connect to AIM server.\n";
my $conn = $aim->getconn();
$conn->set_handler('config', \&on_config);
$aim->set('config_done', 0);
my $done = 0;
while (! $done) {
$aim->do_one_loop();
if ($aim->get('config_done')) {
$aim->send_im('my_buddy', 'my_message');
sleep 5;
$done = 1;
} else {
$aim->do_one_loop();
}
}
sub on_config {
my ($self, $evt, $from, $to) = @_;
my $str = shift @{$evt->args()};
$self->set_config_str($str, 1);
$self->send_config();
$self->set('config_done', 1);
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
|
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
|
|