LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   NET::OSCAR perl script (https://www.linuxquestions.org/questions/programming-9/net-oscar-perl-script-524875/)

icetomyst 02-02-2007 12:15 AM

NET::OSCAR perl script
 
first off i must say that I have never used anything like net::oscar or net::aim before....what im trying to do is write a small perl script that will login to AIM via net::oscar send an IM to a a couple people, then logout....this script will be invoked by a command on a game server.

Now, I managed to get the game server to run the script, but I cant seem to get Net::OSCAR to login and send the message...heres what i have:

Code:

#!/usr/bin/perl -w

        use Net::OSCAR qw(:standard);


        $oscar = Net::OSCAR->new();
        $oscar->set_callback_im_in(\&im_in);
        $oscar->signon('USERNAME', 'PASSWORD');
        while(1) {
    $oscar->do_one_loop();
$oscar->send_im('PERSON#1', 'test message test message');
$oscar->send_im('PERSON#2', 'test message test message');
$oscar->send_im('PERSON#3', 'test message test message');

  exit();
        }

I know i have to be doing something wrong, but what it is is beyond me. In all honesty the script would work better with my gameserver if it was shell, but that is beyond me as well.
I also have NET::AIM installed and would work just fine for what I need, if someone reading this is more familiar with that.
If anyone can be of any assistance I would appreciate it very much. Thanks in advance.

chrism01 02-02-2007 01:25 AM

Exactly what error do you get?
try
use strict;
at the top after the use cmd.
Also, looks like you are calling a sub im_in() that isn't defined.

icetomyst 02-02-2007 02:53 AM

thanks for replying.

removed im_in and added use strict and added my before defining $oscar...still doesn't work, it never gave me any errors, just didnt work altogether.
so i decided to start over and came up with this:

Code:

#!/usr/bin/perl -w
 
use Net::OSCAR qw(:standard);

$screenname = UNAME;
$password = PASS;

        $oscar = Net::OSCAR->new();
        $oscar->signon($screenname, $password);

        while(1) {
                $oscar->do_one_loop();
  $oscar->send_im(PERSON1, 'hello');
        }

Now that actually signed on and sent the message, only problem is it sends the message repeatedly and never stops and never signs off and it will crash if the person is not logged on, i tried adding $oscar->signoff; after send_im(PERSON1...); but that caused it to not be able to login at all...tried with and without strict...I added exit(); but then it wouldnt login at all. I know its repeating because it's in a while loop, but im not sure of another way to do it

Quigi 02-02-2007 04:14 PM

Well, that
Code:

while (1) {...}
is an explicitly infinite loop, so it makes sense that it never stops sending. What was your intention when you coded that while loop? It looks like in normal use of Net::OSCAR, you have to repeatedly call do_one_loop() to let it do its thing. I don't know this module, but 'perldoc Net::OSCAR' should provide some documentation. :study:


All times are GMT -5. The time now is 04:46 AM.