diff --git a/local_config.py.skel b/local_config.py.skel index a1f3e2d..2451593 100644 --- a/local_config.py.skel +++ b/local_config.py.skel @@ -16,6 +16,8 @@ config['hist_max_count'] = 5 config['hist_max_time'] = 10 * 60 config['uptime'] = -time.time() +config['request_counter'] = 0 + # the "dice" feature will use more efficient random data (0) for given users config['enhanced-random-user'] = ( 'FIXME', 'FIXME' ) @@ -24,3 +26,7 @@ def conf(val): if val in config.keys(): return config[val] return None + +def set_conf(key, val): + config[key] = val + return None diff --git a/plugins.py b/plugins.py index 1207d5b..4196e02 100644 --- a/plugins.py +++ b/plugins.py @@ -175,11 +175,11 @@ def command_uptime(args): plural_request = 's' if 1 == u: plural_uptime = '' - if 1 == request_counter: plural_request = '' + if 1 == conf('request_counter'): plural_request = '' logger('info', 'sent statistics') return { - 'msg': args['reply_user'] + (''': happily serving for %d second%s, %d request%s so far.''' %(u, plural_uptime, request_counter, plural_request)) + 'msg': args['reply_user'] + (''': happily serving for %d second%s, %d request%s so far.''' %(u, plural_uptime, conf('request_counter'), plural_request)) } def command_ping(args): diff --git a/urlbot.py b/urlbot.py index 8dc8c4e..61fbd70 100755 --- a/urlbot.py +++ b/urlbot.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- import sys, os, re, time, urllib, pickle, random, HTMLParser, stat -from local_config import conf +from local_config import conf, set_conf BUFSIZ = 8192 delay = 0.100 # seconds @@ -16,7 +16,6 @@ fifo_path = os.path.join(basedir, 'cmdfifo') # rate limiting to 5 messages per 10 minutes hist_ts = [] hist_flag = True -request_counter = 0 parser = None @@ -106,8 +105,7 @@ def extract_title(url): return (-1, 'error') def chat_write(message, prefix='/say '): - global request_counter - request_counter += 1 + set_conf('request_counter', conf('request_counter') + 1) if debug_enabled(): print message @@ -243,8 +241,6 @@ plugins.ratelimit_touch = ratelimit_touch plugins.random = random plugins.time = time -plugins.request_counter = request_counter - plugins.register_all() if '__main__' == __name__: