1
0
mirror of http://aero2k.de/t/repos/urlbot-native.git synced 2017-09-06 15:25:38 +02:00

ratelimit fix/split up; bot_user fixes

This commit is contained in:
urlbot
2014-09-27 05:51:18 +02:00
parent c3ddeaecdc
commit 294408c4fe
2 changed files with 22 additions and 8 deletions

View File

@@ -131,12 +131,17 @@ def chat_write(message, prefix='/say '):
except IOError:
logger('err', "couldn't print to fifo " + fifo_path)
def ratelimit_exceeded(ignored=None): # FIXME: separate counters
global hist_flag
def ratelimit_touch(ignored=None): # FIXME: separate counters
now = time.time()
hist_ts.append(now)
if hist_max_count < len(hist_ts):
hist_ts.pop(0)
def ratelimit_exceeded(ignored=None): # FIXME: separate counters
global hist_flag
if hist_max_count < len(hist_ts):
first = hist_ts.pop(0)
if (now - first) < hist_max_time:
@@ -155,6 +160,7 @@ def extract_url(data):
result = re.findall("(https?://[^\s>]+)", data)
if result:
for r in result:
ratelimit_touch()
if ratelimit_exceeded():
return False
@@ -197,7 +203,7 @@ def parse_delete(filepath):
fd.close()
os.remove(filepath) # probably better crash here
if content[1:1+len(bot_user)] == bot_user:
if content[1:1+len(conf('bot_user'))] == conf('bot_user'):
return
if 'has set the subject to:' in content:
@@ -234,6 +240,7 @@ plugins.chat_write = chat_write
plugins.conf = conf
plugins.logger = logger
plugins.ratelimit_exceeded = ratelimit_exceeded
plugins.ratelimit_touch = ratelimit_touch
plugins.register_all()