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

replace direct write with proxy function for future locking

This commit is contained in:
Thorsten S
2015-12-21 10:41:58 +01:00
parent ff11d522b1
commit 0127a9cf26
4 changed files with 14 additions and 11 deletions

View File

@@ -51,7 +51,7 @@ def conf_set(key, val):
def runtimeconf_set(key, value): def runtimeconf_set(key, value):
runtime_config_store[key] = value runtime_config_store[key] = value
runtime_config_store.write() runtimeconf_persist()
def runtimeconf_get(key, default=None): def runtimeconf_get(key, default=None):
@@ -61,6 +61,10 @@ def runtimeconf_get(key, default=None):
return runtime_config_store.get(key, default=default) return runtime_config_store.get(key, default=default)
def runtimeconf_persist():
runtime_config_store.write()
def runtimeconf_deepget(key, default=None): def runtimeconf_deepget(key, default=None):
if '.' not in key: if '.' not in key:
return runtimeconf_get(key, default) return runtimeconf_get(key, default)

View File

@@ -52,7 +52,7 @@ class IdleBot(ClientXMPP):
)) ))
self.hangup() self.hangup()
return False return False
elif msg_obj['mucnick'] in config.runtime_config_store["other_bots"]: elif msg_obj['mucnick'] in config.runtimeconf_get("other_bots"):
# not talking to the other bot. # not talking to the other bot.
return False return False
else: else:

View File

@@ -46,7 +46,7 @@ def plugin_enabled_set(plugin, enabled):
config.runtime_config_store['plugins'][plugin.plugin_name] = {} config.runtime_config_store['plugins'][plugin.plugin_name] = {}
config.runtime_config_store['plugins'][plugin.plugin_name]['enabled'] = enabled config.runtime_config_store['plugins'][plugin.plugin_name]['enabled'] = enabled
config.runtime_config_store.write() config.runtimeconf_persist()
config.conf_set('persistent_locked', False) config.conf_set('persistent_locked', False)
@@ -594,7 +594,7 @@ def command_usersetting(argv, **args):
config.runtime_config_store['user_pref'][arg_user][arg_key] = 'on' == arg_val config.runtime_config_store['user_pref'][arg_user][arg_key] = 'on' == arg_val
config.runtime_config_store.write() config.runtimeconf_persist()
config.conf_set('persistent_locked', False) config.conf_set('persistent_locked', False)
# display value written to db # display value written to db
@@ -822,7 +822,7 @@ def command_record(argv, **args):
config.runtime_config_store['user_records'][target_user].append(message) config.runtime_config_store['user_records'][target_user].append(message)
config.runtime_config_store.write() config.runtimeconf_persist()
config.conf_set('persistent_locked', False) config.conf_set('persistent_locked', False)
return { return {
@@ -961,7 +961,7 @@ def recognize_bots(**args):
def _add_to_list(username, message): def _add_to_list(username, message):
if username not in config.runtime_config_store['other_bots']: if username not in config.runtime_config_store['other_bots']:
config.runtime_config_store['other_bots'].append(username) config.runtime_config_store['other_bots'].append(username)
config.runtime_config_store.write() config.runtimeconf_persist()
return { return {
'event': { 'event': {
'time': time.time() + 3, 'time': time.time() + 3,
@@ -988,7 +988,7 @@ def remove_from_botlist(argv, **args):
if argv[1] in config.runtime_config_store['other_bots']: if argv[1] in config.runtime_config_store['other_bots']:
config.runtime_config_store['other_bots'].remove(argv[1]) config.runtime_config_store['other_bots'].remove(argv[1])
config.runtime_config_store.write() config.runtimeconf_persist()
return {'msg': '%s was removed from the botlist.' % argv[1]} return {'msg': '%s was removed from the botlist.' % argv[1]}
else: else:
return False return False

View File

@@ -73,7 +73,7 @@ class UrlBot(IdleBot):
# TODO: move this to a undirected plugin, maybe new plugin type # TODO: move this to a undirected plugin, maybe new plugin type
arg_user = msg_obj['muc']['nick'] arg_user = msg_obj['muc']['nick']
arg_user_key = arg_user.lower() arg_user_key = arg_user.lower()
user_records = config.runtime_config_store['user_records'] user_records = config.runtimeconf_get('user_records')
if arg_user_key in user_records: if arg_user_key in user_records:
records = user_records[arg_user_key] records = user_records[arg_user_key]
@@ -102,7 +102,7 @@ class UrlBot(IdleBot):
config.conf_set('persistent_locked', True) config.conf_set('persistent_locked', True)
user_records.pop(arg_user_key) user_records.pop(arg_user_key)
config.runtime_config_store.write() config.runtimeconf_persist()
config.conf_set('persistent_locked', False) config.conf_set('persistent_locked', False)
@@ -116,7 +116,6 @@ class UrlBot(IdleBot):
return return
config.runtimeconf_set('request_counter', config.runtimeconf_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): if str is not type(message):
message = '\n'.join(message) message = '\n'.join(message)
@@ -141,7 +140,7 @@ class UrlBot(IdleBot):
@cached @cached
def get_bots_present(room): def get_bots_present(room):
other_bots = config.runtime_config_store["other_bots"] other_bots = config.runtimeconf_get("other_bots")
if not other_bots: if not other_bots:
return False return False
users = self.plugin['xep_0045'].getRoster(room) users = self.plugin['xep_0045'].getRoster(room)