chevron_left chevron_right
Login Register invert_colors photo_library


Stay updated and chat with others! - Join the Discord!
Thread Rating:
  • 0 Vote(s) - 0 Average


small problem with my code filter_list
Author
Message
small problem with my code #1
Hi all.
I have my own jabber bot and today i make new plugin which is to send message for all users. my code was working good but i have small problem thats when i give my bot command to send message my bot get stuck and disconected.
I know my bot get stuck and disconected because i have more than 2000 users so my bot can not send MSG in the same time for all users.
now i need to ask you if there are any method by python to make my code send the MSG for each user after N second i mean bot send MSG for user1 then wait for N second and send for user2 and like that...

Hope my idea is clear and this is my code.

Code:
def send_msg(type, source, parameters):
    ADMINFILE = 'modules/xmpp/users.cfg'
    fp = open(ADMINFILE, 'r')
    users = eval(fp.read())
    if parameters:
        for z in users:
            msg(z, u"MSG from Admin:\n" +parameters)
            reply(type, source, u"MSG has been sent!")
        else:
            reply(type, source, u"Error! please try again.")
            
            
register_command_handler(send_msg, 'msg', ['all','amsg'], 0,'Sends a message to all users')

Reply

RE: small problem with my code #2
loop through each user in the list and use something like http://www.tutorialspoint.com/python/time_sleep.htm after each message is sent

Reply

RE: small problem with my code #3
(05-16-2014, 10:32 PM)Geoff Wrote: loop through each user in the list and use something like http://www.tutorialspoint.com/python/time_sleep.htm after each message is sent

Hi, Thank you for your reply.:Grin:
hmmm i know about Python time sleep() Method but in my code how i can use it to make my bot send MSG for each user after N second?
That's what i need:Smile:

Thanks again.:Thumbs-Up:

Reply

RE: small problem with my code #4
(05-17-2014, 07:57 AM)yuyboy Wrote:
(05-16-2014, 10:32 PM)Geoff Wrote: loop through each user in the list and use something like http://www.tutorialspoint.com/python/time_sleep.htm after each message is sent

Hi, Thank you for your reply.:Grin:
hmmm i know about Python time sleep() Method but in my code how i can use it to make my bot send MSG for each user after N second?
That's what i need:Smile:

Thanks again.:Thumbs-Up:

I am not a python coder but based on general programming knowledge I would probably place it right after this code:

Code:
msg(z, u"MSG from Admin:\n" +parameters)
            reply(type, source, u"MSG has been sent!")

Reply

RE: small problem with my code #5
No, its wrong.
If i put time.sleep(x) in that place thats mean when my bot send MSG then sleep for N time after that stop to do my command.

Thank you for your time.
Hope anyone help me..

Reply

RE: small problem with my code #6
(05-17-2014, 04:22 PM)yuyboy Wrote: No, its wrong.
If i put time.sleep(x) in that place thats mean when my bot send MSG then sleep for N time after that stop to do my command.

Thank you for your time.
Hope anyone help me..

As far as I can tell, like every other language sleep() only pauses the execution of your program. It will never terminate. If your program terminates after a sleep its probably because you are doing something wrong.

Reply

RE: small problem with my code #7
I don't say my programme will stope i say my bot will stop to do my command.

Any way thanks alot bro..

Reply

RE: small problem with my code #8
So, no solution for my problem.?

Reply

RE: small problem with my code #9
@Geoff has recommend the correct solution, Since you are using it inside a loop that iterates through all the members, the sleep function will simply halt for say 10 sec then after 10 sec it will continue to iterate to the other person, it will not exit or break the loop, it will simply halt if for the given time and then continue.

So your code would be like:

Code:
import time

for users in list:
    send message to the user
    
    //Halt for 5 seconds before iterating to the next user
    time.sleep(5)

//Rest of your code
My Blog: http://www.procurity.wordpress.com
Donations: 1HLjiSbnWMpeQU46eUVCrYdbkrtduX7snG

Reply

RE: small problem with my code #10
(05-24-2014, 06:43 AM)Ex094 Wrote: @Geoff has recommend the correct solution, Since you are using it inside a loop that iterates through all the members, the sleep function will simply halt for say 10 sec then after 10 sec it will continue to iterate to the other person, it will not exit or break the loop, it will simply halt if for the given time and then continue.

So your code would be like:

Code:
import time

for users in list:
    send message to the user
    
    //Halt for 5 seconds before iterating to the next user
    time.sleep(5)

//Rest of your code

@Ex094 I try it but i got the same problem.
please can you edit my code and do what you mean..

Thanks

Reply






Users browsing this thread: 1 Guest(s)