User Control Panel
Advertisements

HELP US, HELP YOU!

MSN.PM and the threads

 
Post new topic   Reply to topic    Bot Depot Forum Index -> MSN Protocol modules
View unanswered posts
Author Message
malco
Newbie
Newbie


Joined: 06 Dec 2006
Posts: 3


PostPosted: Wed Dec 06, 2006 9:24 pm    Post subject: MSN.PM and the threads Reply with quote

Hi,

I'm trying to use MSN.PM ; but I would like to have my bot in a different thread.
In fact, I want the main script will launch the thread containing the bot (with MSN.PM), and this main script will sleep a minute before calling MSN.PM to send a message to some user.

For example :
main.pl :

    1. start a thread
    2. start the bot in the thread
    3. sleep 10 secondes
    4. send a message to user1@domain.com
    5. sleep 10 secondes
    6. send a message to user2@domain.com


Please, howa can I do that ?

_________________
Math
Back to top
Cer
Upgraded Agent
Upgraded Agent


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

PostPosted: Wed Dec 06, 2006 10:16 pm    Post subject: Reply with quote

You don't need threads to do that. Just set up a timer.

Code:
# setup your $msn object
#...

my $called = {}; # only call users once

my $time = time(); # get current time
while (1) {
   $msn->do_one_loop; # loop with MSN

   if (time() - $time >= 10 && !exists $called->{user1}) {
      $msn->call ($user1,'hello');
      $called->{user1} = 'yes';
   }
   if (time() - $time >= 20 && !exists $called->{user2}) {
      $msn->call ($user2,'hello');
      $called->{user2} = 'yes';
   }
   # and so-on, if each user is to be IM'd 10 seconds
   # apart, use 10,20,30,40,... as in this example, where
   # the number is how many seconds since the bot signed
   # on
}


If you want this to continuously IM people with no end, I'm not going to help you with that, because we have a word for it: flooding. And flooding is totally uncool.

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


Joined: 06 Dec 2006
Posts: 3


PostPosted: Thu Dec 07, 2006 10:08 am    Post subject: Reply with quote

Cer wrote:
You don't need threads to do that. Just set up a timer.

Ok, but the timer is for the example an for simplify my post.
In reality, there is no timer, but the script run an calculate something with file on the server (and this take time). Then, after that calcul reach a certain value, it'll call the user by IM

Edit : I already have developped the part witch calculate values.

Cer wrote:
If you want this to continuously IM people with no end, I'm not going to help you with that, because we have a word for it: flooding. And flooding is totally uncool.

I agree, but my bot will only IM user that subscribe to that function, and they can unsubscribe when they want.

Ps : I could implement a function in a bot : when user says "!unsubscribe me", then the bot neither call this user.

Is it more clear now ? And really thanks for helping me. Smile

_________________
Math
Back to top
Cer
Upgraded Agent
Upgraded Agent


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

PostPosted: Thu Dec 07, 2006 2:21 pm    Post subject: Reply with quote

The first concept to understand is that in Perl, threads are run like separate processes, and they can't communicate with eachother. You can use the module threads::shared which can share specific variables, but for large complex data structures (hashes of hashes, hashes of arrays, arrays of hashes, etc) you have to explicitely share each level of the structure. The $msn object is a complex structure and, unless you want to dissect every corner of the $msn object, you won't be able to share it very easily.

My suggestion is to share an array as a kind of queue of events for the main bot thread to react to.

Code:
use threads;
use threads::shared;

our @QUEUE : shared;

threads->create (sub {
   # do stuff
   push (@QUEUE, "for $user: $message");
})->detach;

use MSN;

# set up MSN connection

while (1) {
   $msn->do_one_loop;
   if (scalar(@QUEUE)) {
      my $next = shift(@QUEUE);
      my ($for,$msg) = $next =~ /^for (.+?): (.+?)$/i;
      $msn->call ($for, $msg);
   }
}


Notice that I didn't load MSN until I created the other thread. When a new thread is created, a new Perl process is created with the current state of the script. So if you load modules and set variables before creating a new thread, the new thread will have these modules and variables to begin with (but neither of them are shared by default). Since the thread doesn't need to use the MSN module, I didn't load MSN until after the thread was created.

I generally think it's more efficient to have a new thread spawn to do something small (ie check an RSS feed periodically or something) and have the main thread do all the big stuff (run an MSN bot), otherwise you'd have a thread with a lot of stuff in it and then just a small while(1) loop outside the thread to check RSS feeds. But you can do it any way you want to.

Hope that'll help ya.

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


Joined: 06 Dec 2006
Posts: 3


PostPosted: Fri Dec 08, 2006 9:45 am    Post subject: Reply with quote

Thanks you, your example is very good.. so, It's works well for me now ! Smile
_________________
Math
Back to top
Muhammad
Newbie
Newbie


Joined: 19 Aug 2007
Posts: 4


PostPosted: Tue Aug 21, 2007 12:42 am    Post subject: Reply with quote

This is not out-dated. Why have the administrators written that most msn.pms are out of date. This is going to keep users from joining and discussing.
Back to top
JTW
God Like
God Like


Joined: 07 Mar 2004
Posts: 579
Location: Maidstone
Reputation: 67.1
votes: 4

PostPosted: Tue Aug 21, 2007 7:40 am    Post subject: Reply with quote

This has been written as the MSN.pm has not been developed for a few years now. In addition most of the earlier releases (such as the ones included in templates) do not work. People also started releasing their own little 'tweaks' which added bits of functionality, but since these people were not alway sure what they were doing many of these modules broke easily.
_________________
"Help us, Help you" - BotDepot
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Bot Depot Forum Index -> MSN Protocol modules All times are GMT
Page 1 of 1

 



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