sockets - the time() function (python) -


    if data.find('!google') != -1:      nick = data.split('!')[ 0 ].replace(':','')      if last_google + 5 > time.time():         sck.send('privmsg ' + chan + " :" + ' wait few seconds' + "\r\n")      else:            last_google = time.time()            try:                 gs = googlesearch(args)                 gs.results_per_page = 1                 results = gs.get_results()                 res in results:                     sck.send('privmsg ' + chan + " " + res.title.encode("utf8") + '\r\n')                     sck.send('privmsg ' + chan + " " + res.url.encode("utf8") + '\r\n')                     print            except searcherror, e:                     sck.send('privmsg ' + chan + " " + "search failed: %s" % e + " " + '\r\n') 

ok i'm trying make script wait few seconds before user can "!google" prevent users flooding channel or bot.. script doesnt work, i'm implementing time function wrong or i'm missing something

is in loop?

one issue set last_google time.time() @ beginning of request. if request slow, of time may gone time if statement again.

a typical 'waiting' block might this:

while time.time() < last_google + 5:     sleep(1) # don't want keep using cpu, let process sleep 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -