Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Net::AIM trouble

by thealienz1 (Pilgrim)
on Nov 12, 2001 at 00:51 UTC ( #124691=perlquestion: print w/replies, xml ) Need Help??

thealienz1 has asked for the wisdom of the Perl Monks concerning the following question:

Alrighty now I am really a bit confused... I am having a little trouble with the Net::AIM module, but I do not think it is the module itself just my code. Of couse why would a module be the problem?

Well anyway I am writing a little bot for AIM just for some basic information retrieval... and it can be expanded because commands be created easily like plugins.

This is my code, which takes an input from a user, and processes the input. For example if they type in "time" it will process it and load the plugin for time.

Here is the main code:

#!C:\perl\bin\perl.exe -w #Need to load these for bot use use strict; use Net::AIM; #Especially if you want to reach out and talk to someone my %CONFIG = ( 'cgi_dir' => 'C:/windows/desktop/scripts/bot', #Exact dir +ectory of script (w/o trailing slash) 'bot_master' => '', #The owner of the bot 'bot_username' => '', #The bot's username to AIM 'bot_password' => '', #The bot's password to AIM ); #Alright here we go my $AIM = Net::AIM->new(); $AIM->newconn(Screenname => $CONFIG{'bot_username'}, Password => $CONF +IG{'bot_password'}); my $connection = $AIM->getconn(); #Now log on to server #Now we need to load the parser sub on_im{ my ($self, $evt, $from, $to) = @_; my $args = $evt->args(); my ($nick, $friend, $msg) = @$args; #Get rid of any HTML in the message, so we can read it as plain te +xt... chomp($msg); my $stripped = $msg; $stripped =~ s/<[^>]+>//g; $stripped =~ s/^\s+//g; #Now we load up the correct plugin for the command specified my($plugin, @lines) = split(/ /, $stripped); my $lines = join(' ',@lines); if(!defined($plugin)) { &send_response('nothing_todo',$nick); } else{ $plugin=lc($plugin); print "$nick requested $plugin - $CONFIG{'cgi_dir'}\n"; if(-e "$CONFIG{'cgi_dir'}/attach/$plugin.lib") { eval { require "$CONFIG{'cgi_dir'}/attach/$plugin.lib"; &main_program($self,$nick,$lines); }; if($@) {$self->send_im($nick,"Fatal Error Occured - $plugi +n - <B>$@<\/B>");} #FATAL ERROR } else{ $self->send_im($nick,"Hey! I can't do that because I do no +t know what $plugin is."); } } } 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"; } #This sets the AIM to the subroutines to handle the EVENT $connection->set_handler('error',\&on_error); $connection->set_handler('im_in',\&on_im); print "Starting the BOT\n"; #Start the connection $AIM->start;

So, if they type in time then this is the plugin that it will load...

The code: time.lib

sub main_program{ my($self,$nick,$args) = $_[0]; my $time = localtime(time); $self->send_im($nick,"The current time is: $time."); } 1;

Now my problem is the $self->send_im in the time code does not work... It loads the function and eveything, but it returns an error, so it never sends the message. This is my error message... I do not know what the hell the problem is. I try to retrace the Net::AIM::Connection module all the way back and they only thing I can figure out is that I should be passing $self somewhere, but where?

Use of uninitialized value in substitution (s///) at C:/Perl/site/lib/ +Net/AIM/Co line 247. Use of uninitialized value in transliteration (tr///) at C:/Perl/site/ +lib/Net/AI M/ line 248. Use of uninitialized value in concatenation (.) or string at C:/Perl/s +ite/lib/Ne t/AIM/ line 267.

If anyone can help me out... It would be greatly appreciated.

Replies are listed 'Best First'.
Re: Net::AIM trouble
by {NULE} (Hermit) on Nov 12, 2001 at 02:55 UTC

    thealienz1 asked us about this node in the CB and we did some research to figure out what the problem was. I don't know if thealienz1 got cut off or what, but I don't want our work to go to waste - so here is what we came up with:

    16:23:11 <thealienz1> can no one answer my post...
    16:23:41 <thealienz1> Is it that hard?
    16:26:41 <{NULE}> I don't know how many people have used Net::AIM, thealienz1. Sundays are often slow here as well.
    16:27:41 <FoxtrotUniform> I'm not at all familiar with the Net::AIM code....
    16:27:41 <{NULE}> Did you look in the Net/AIM/ file to see what was complaining?
    16:29:41 <{NULE}> I'll d/l it real quick to see what I see. :)
    16:30:11 <Zecho> $plugin.lib")
    16:30:11 <Zecho> $plugin\.lib")
    16:33:11 <rchiav> thealienzl those errors usually mean you're not passing something that you're supposed to. I'd look at the module at those lines and figure out what doesn't have a value. Then you can trace it back.
    16:35:41 <{NULE}> The send_im sub in Connection PM calls a method normalize on the $user variable, which in turn does the s/// and tr/// that are complaining. Sounds like $user isn't populated.
    16:36:12 rchiav wanders off to clean up the place..
    16:37:12 <rchiav> {NULE} and his hash he stores that info in is blank. I thought that might be for posting purposes.
    16:37:12 <{NULE}> Which means that somewhere in your code looks like $nick is not defined.
    16:37:42 {NULE} wonders if thealienz1 caught any of that.
    16:38:42 <Zecho> think this might have something to do with it? my($self,$nick,$args) = $_[0];
    <SNIP ... some random stuff happened>
    16:41:42 <{NULE}> I'm tempted to post a snippet of my chat log here to that node in reply. Along with a "Please don't ask questions in the CB and ignore the answer". :)

    Today's CB snippet is brought to you courtesy of the fabulous Curses Chatterbox Client. :)


      Can I get a ... T! Can I get a ... H! Can I get a ... A! Can I get a ... N! Can I get a ... K! Can I get a ... S! What does that spell? Canigetatcanigetahcanigetaacanigetancanigetakcanigetas... And we have no idea what that means.
Re: Net::AIM trouble
by gornox_zx (Priest) on Nov 12, 2001 at 06:57 UTC
    Hello, I just started using net::aim last week to try to make an aim bot. I haven't really had any problems like that; then again, I haven't tried any suave plugins like you are implementing. I just made a function that parsed for commands and executed them.
    My code is not nearly as elegant/cool as yours and I like your idea of plugins. I think that your problem is that your $nick at some point loses it's value.
    Perhaps you could trace the value of it in each function/plugin it is being used in by printing it out, and thus see where you are losing it.
    Perhaps something like this:
    sub main_program{ my($self,$nick,$args) = @_; print "\$nick = $nick"; my $time = localtime(time); $self->send_im($nick,"The current time is: $time."); }

    Another thing to consider, aside from your problem, is how you are storing the login info in the configuration file. I think it would be a good idea to use some kind of encryption for your information in the file, and then decrypting it before you use it to log in. Either that or type it in at the command prompt. I don't know your situation, but I think people are in general too loose with their logins/passwords, and that though this is only an aim password, it is still a habit to get into. ~heise2k~

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://124691]
Approved by root
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2020-02-24 20:07 GMT
Find Nodes?
    Voting Booth?
    What numbers are you going to focus on primarily in 2020?

    Results (107 votes). Check out past polls.