User Control Panel
Advertisements

HELP US, HELP YOU!

msn.pl sending message question
Goto page Previous  1, 2
 
Post new topic   Reply to topic    Bot Depot Forum Index -> Perl
View unanswered posts
Author Message
Cer
Upgraded Agent
Upgraded Agent


Joined: 03 Feb 2004
Posts: 3776
Location: Michigan
Reputation: 146.9
votes: 4

PostPosted: Thu Jun 22, 2006 2:55 am    Post subject: Reply with quote

A different approach would be to use threads, and when the Connected event is called, start a thread that would check the database every so often, and do something accordingly.

threads::shared can also be used to share variables between two threads (since the two threads can't otherwise communicate very easily)

Code:
use threads;
use threads::shared;

# Maybe share an array of queued messages to send out?
our @outbox : shared;

#######################
#######################
#######################

sub Connected {
   my $self = shift;

   my $t = threads->create (sub {
      # Check the db every 15 seconds.
      my $timer = time() + 15;
      while (1) {
         if (time() > $timer) {
            # Check the db
            &read_notify;

            # And when you get something to send,
            # you can push(@outbox,"something")
            # and your main loop code could check
            # that array, and handle the most recent
            # item, which might contain a username to
            # send to and a message, e.g.
            # push (@outbox, 'myname@nowhere.net::something to say');

            # Reset the timer
            $timer = time() + 15;
         }
      }
   });
   $t->detach; # separate it from the main process
}

_________________
Current Site (2008) http://www.cuvou.com/
Back to top
chemichon
Newbie
Newbie


Joined: 18 Jun 2006
Posts: 8


PostPosted: Thu Jun 22, 2006 11:53 am    Post subject: Reply with quote

Now I am trying to do something entirely different.
That $i thing was just to easy the debugging process.

Now, the read_notify checks on a DB wheter there is or not a message for the users.

something like:


Code:
while () {
  $i++;
  msn do one loop();
     if ($i == 5) {
         &read_notify();
         undef($i);
     }
}



(I didnt care about the syntax, just for the logic.)
would be ok?
Back to top
eric256
The Keymaker
The Keymaker


Joined: 03 May 2006
Posts: 2292
Location: Colorado
Reputation: 47Reputation: 47Reputation: 47Reputation: 47Reputation: 47

PostPosted: Thu Jun 22, 2006 1:02 pm    Post subject: Reply with quote

Yes that syntax looks okay. Your seriously getting annoying though when you continualy ignore peoples suggestions. Turn on strict and warnings and see what errors you get. I'll bet you get some that when fixed will make this bot work. strict and warnings are GOOD, let them help you.

Just add:
Code:

use strict;
use warnings;

At the top of your code and let us know what perl tells you.

_________________
Eric256
Proud previous owner and current admin of Bot-depot.com
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Bot Depot Forum Index -> Perl All times are GMT
Goto page Previous  1, 2
Page 2 of 2

 



Protected by phpBB Security phpBB-TweakS
phpBB Security Has Blocked 9 Exploit Attempts.
Antispam Captcha Mod by phpbb-security.com
Powered by phpBB © 2001, 2005 phpBB Group