scope fixes; put hist_max_* to conf()
This commit is contained in:
@@ -10,6 +10,9 @@ config['src-url'] = 'FIXME'
|
|||||||
config['bot_user'] = 'urlbot'
|
config['bot_user'] = 'urlbot'
|
||||||
config['bot_owner'] = 'FIXME'
|
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
|
# the "dice" feature will use more efficient random data (0) for given users
|
||||||
config['enhanced-random-user'] = ( 'FIXME', 'FIXME' )
|
config['enhanced-random-user'] = ( 'FIXME', 'FIXME' )
|
||||||
|
|
||||||
|
|||||||
@@ -217,7 +217,7 @@ def command_info(args):
|
|||||||
if 'info' in args['data']:
|
if 'info' in args['data']:
|
||||||
logger('info', 'sent long info')
|
logger('info', 'sent long info')
|
||||||
return {
|
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):
|
def command_else(args):
|
||||||
|
|||||||
10
urlbot.py
10
urlbot.py
@@ -14,8 +14,6 @@ event_files_dir = os.path.join(basedir, 'event_files')
|
|||||||
fifo_path = os.path.join(basedir, 'cmdfifo')
|
fifo_path = os.path.join(basedir, 'cmdfifo')
|
||||||
|
|
||||||
# rate limiting to 5 messages per 10 minutes
|
# rate limiting to 5 messages per 10 minutes
|
||||||
hist_max_count = 5
|
|
||||||
hist_max_time = 10 * 60
|
|
||||||
hist_ts = []
|
hist_ts = []
|
||||||
hist_flag = True
|
hist_flag = True
|
||||||
uptime = -time.time()
|
uptime = -time.time()
|
||||||
@@ -135,19 +133,19 @@ def ratelimit_touch(ignored=None): # FIXME: separate counters
|
|||||||
now = time.time()
|
now = time.time()
|
||||||
hist_ts.append(now)
|
hist_ts.append(now)
|
||||||
|
|
||||||
if hist_max_count < len(hist_ts):
|
if conf('hist_max_count') < len(hist_ts):
|
||||||
hist_ts.pop(0)
|
hist_ts.pop(0)
|
||||||
|
|
||||||
|
|
||||||
def ratelimit_exceeded(ignored=None): # FIXME: separate counters
|
def ratelimit_exceeded(ignored=None): # FIXME: separate counters
|
||||||
global hist_flag
|
global hist_flag
|
||||||
|
|
||||||
if hist_max_count < len(hist_ts):
|
if conf('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) < conf('hist_max_time'):
|
||||||
if hist_flag:
|
if hist_flag:
|
||||||
hist_flag = False
|
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))
|
logger('warn', 'rate limiting exceeded: ' + pickle.dumps(hist_ts))
|
||||||
return True
|
return True
|
||||||
|
|||||||
Reference in New Issue
Block a user