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

scope fixes; put hist_max_* to conf()

This commit is contained in:
urlbot
2014-09-27 05:56:39 +02:00
parent 013409d6d8
commit 60285089fe
3 changed files with 8 additions and 7 deletions

View File

@@ -10,6 +10,9 @@ config['src-url'] = 'FIXME'
config['bot_user'] = 'urlbot'
config['bot_owner'] = 'FIXME'
config['hist_max_count'] = 5
config['hist_max_time'] = 10 * 60
# the "dice" feature will use more efficient random data (0) for given users
config['enhanced-random-user'] = ( 'FIXME', 'FIXME' )

View File

@@ -217,7 +217,7 @@ def command_info(args):
if 'info' in args['data']:
logger('info', 'sent long info')
return {
'msg': args['reply_user'] + (''': I'm a bot, my job is to extract <title> tags from posted URLs. In case I'm annoying or for further questions, please talk to my master %s. I'm rate limited and shouldn't post more than %d messages per %d seconds. To make me exit immediately, highlight me with 'hangup' in the message (emergency only, please). For other commands, highlight me with 'command'.''' %(conf('bot_owner'), hist_max_count, hist_max_time))
'msg': args['reply_user'] + (''': I'm a bot, my job is to extract <title> tags from posted URLs. In case I'm annoying or for further questions, please talk to my master %s. I'm rate limited and shouldn't post more than %d messages per %d seconds. To make me exit immediately, highlight me with 'hangup' in the message (emergency only, please). For other commands, highlight me with 'command'.''' %(conf('bot_owner'), conf('hist_max_count'), conf('hist_max_time')))
}
def command_else(args):

View File

@@ -14,8 +14,6 @@ event_files_dir = os.path.join(basedir, 'event_files')
fifo_path = os.path.join(basedir, 'cmdfifo')
# rate limiting to 5 messages per 10 minutes
hist_max_count = 5
hist_max_time = 10 * 60
hist_ts = []
hist_flag = True
uptime = -time.time()
@@ -135,19 +133,19 @@ def ratelimit_touch(ignored=None): # FIXME: separate counters
now = time.time()
hist_ts.append(now)
if hist_max_count < len(hist_ts):
if conf('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):
if conf('hist_max_count') < len(hist_ts):
first = hist_ts.pop(0)
if (now - first) < hist_max_time:
if (now - first) < conf('hist_max_time'):
if hist_flag:
hist_flag = False
chat_write('(rate limited to %d messages in %d seconds, try again at %s)' %(hist_max_count, hist_max_time, time.strftime('%T %Z', time.localtime(hist_ts[0] + hist_max_time))))
chat_write('(rate limited to %d messages in %d seconds, try again at %s)' %(conf('hist_max_count'), conf('hist_max_time'), time.strftime('%T %Z', time.localtime(hist_ts[0] + conf('hist_max_time')))))
logger('warn', 'rate limiting exceeded: ' + pickle.dumps(hist_ts))
return True