visible message for rate limiting added
This commit is contained in:
@@ -16,6 +16,7 @@ fifo_path = os.path.join(basedir, 'cmdfifo')
|
|||||||
hist_max_count = 5
|
hist_max_count = 5
|
||||||
hist_max_time = 10 * 60
|
hist_max_time = 10 * 60
|
||||||
hist_ts = []
|
hist_ts = []
|
||||||
|
hist_flag = True
|
||||||
|
|
||||||
def debug_enabled():
|
def debug_enabled():
|
||||||
# return True
|
# return True
|
||||||
@@ -63,15 +64,22 @@ def chat_write(message, prefix='/say '):
|
|||||||
logger('err', "couldn't print to fifo " + fifo_path)
|
logger('err', "couldn't print to fifo " + fifo_path)
|
||||||
|
|
||||||
def ratelimit_exceeded():
|
def ratelimit_exceeded():
|
||||||
|
global hist_flag
|
||||||
|
|
||||||
now = time.time()
|
now = time.time()
|
||||||
hist_ts.append(now)
|
hist_ts.append(now)
|
||||||
|
|
||||||
if hist_max_count < len(hist_ts):
|
if hist_max_count < len(hist_ts):
|
||||||
first = hist_ts.pop(0)
|
first = hist_ts.pop(0)
|
||||||
if (now - first) < hist_max_time:
|
if (now - first) < hist_max_time:
|
||||||
|
if hist_flag:
|
||||||
|
hist_flag = False
|
||||||
|
chat_write('(rate limited to %d messages in %d seconds)' %(hist_max_count, hist_max_time))
|
||||||
|
|
||||||
logger('warn', 'rate limiting exceeded: ' + pickle.dumps(hist_ts))
|
logger('warn', 'rate limiting exceeded: ' + pickle.dumps(hist_ts))
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
hist_flag = True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def extract_url(data):
|
def extract_url(data):
|
||||||
|
|||||||
Reference in New Issue
Block a user