From b727a631f3537367c609b1249a93cf923be985cb Mon Sep 17 00:00:00 2001 From: Thorsten S Date: Mon, 21 Dec 2015 00:08:46 +0100 Subject: [PATCH] fix request counter --- local_config.ini.spec | 1 - local_config.py.skel | 65 -------------------------------------- persistent_config.ini.spec | 2 +- plugins.py | 4 +-- urlbot.py | 3 +- 5 files changed, 5 insertions(+), 70 deletions(-) delete mode 100644 local_config.py.skel diff --git a/local_config.ini.spec b/local_config.ini.spec index de182b0..f7b754b 100644 --- a/local_config.ini.spec +++ b/local_config.ini.spec @@ -13,7 +13,6 @@ hist_max_time = integer(default=10*60) # statistics uptime = integer(default=0) -request_counter = integer(default=0) persistent_storage = string(default='urlbot.persistent') persistent_locked = boolean(default=false) diff --git a/local_config.py.skel b/local_config.py.skel deleted file mode 100644 index d7302dc..0000000 --- a/local_config.py.skel +++ /dev/null @@ -1,65 +0,0 @@ -#!/usr/bin/python3 - -import time - -if '__main__' == __name__: - print('''this is a config file, which is not meant to be executed''') - exit(-1) - -config = { - 'jid': 'FIXME', - 'password': 'FIXME', - 'rooms': ['FIXME'], - - 'src-url': 'http://aero2k.de/t/repos/urlbot-native.git', - - 'bot_user': 'native-urlbot', - 'bot_owner': 'FIXME', - - 'hist_max_count': 5, - 'hist_max_time': 10 * 60, - - 'uptime': -time.time(), - 'request_counter': 0, - - 'persistent_storage': 'urlbot.persistent', - 'persistent_locked': False, - - 'url_blacklist': [ - r'^.*heise\.de/.*-[0-9]+\.html$', - r'^.*wikipedia\.org/wiki/.*$', - r'^.*blog\.fefe\.de/\?ts=[0-9a-f]+$', - r'^.*ibash\.de/zitat.*$', - r'^.*golem\.de/news/.*$' - r'^.*paste\.debian\.net/((hidden|plainh?)/)?[0-9a-f]+/?$', - r'^.*example\.(org|net|com).*$', - r'^.*sprunge\.us/.*$', - r'^.*ftp\...\.debian\.org.*$' - ], - - # the "dice" feature will use more efficient random data (0) for given users - 'enhanced-random-user': ('FIXME', 'FIXME'), - - # the "moin" feature will be "disabled" for given users - 'moin-modified-user': (), - 'moin-disabled-user': (), - - 'tea_steep_time': (3 * 60 + 40), - - 'image_preview': True, - 'dsa_watcher_interval': 15 * 60 -} - - -def conf(val): - import logging - logger = logging.getLogger(__name__) - if val in list(config.keys()): - return config[val] - logger.warn('conf(): unknown key ' + str(val)) - return None - - -def set_conf(key, val): - config[key] = val - return None diff --git a/persistent_config.ini.spec b/persistent_config.ini.spec index 84d7439..7286261 100644 --- a/persistent_config.ini.spec +++ b/persistent_config.ini.spec @@ -1,5 +1,5 @@ -# [main] other_bots = string_list(default=list()) +request_counter = integer(default=0) [plugins] [[info]] diff --git a/plugins.py b/plugins.py index f82187b..474e036 100644 --- a/plugins.py +++ b/plugins.py @@ -392,13 +392,13 @@ def command_uptime(argv, **args): if 1 == u: plural_uptime = '' - if 1 == config.conf_get('request_counter'): + if 1 == config.runtimeconf_get('request_counter'): plural_request = '' log.info('sent statistics') return { 'msg': args['reply_user'] + (''': happily serving for %d second%s, %d request%s so far.''' % ( - u, plural_uptime, int(config.conf_get('request_counter')), plural_request)) + u, plural_uptime, int(config.runtimeconf_get('request_counter')), plural_request)) } diff --git a/urlbot.py b/urlbot.py index 20806b0..a11ab2f 100755 --- a/urlbot.py +++ b/urlbot.py @@ -115,7 +115,8 @@ class UrlBot(IdleBot): self.logger.warning("I'm muted! (status: %s)", self.show) return - config.conf_set('request_counter', config.conf_get('request_counter') + 1) + config.runtimeconf_set('request_counter', config.runtimeconf_get('request_counter') + 1) + config.runtime_config_store.write() if str is not type(message): message = '\n'.join(message)