diff --git a/common.py b/common.py index a4423e2..4123560 100644 --- a/common.py +++ b/common.py @@ -32,36 +32,21 @@ def logger(severity, message): sys.stderr.write('%s %s %s: %s\n' % args) def conf_save(obj): + if conf('persistent_locked'): + return False + + set_conf('persistent_locked', True) + with open(conf('persistent_storage'), 'wb') as fd: return pickle.dump(obj, fd) + set_conf('persistent_locked', False) + def conf_load(): with open(conf('persistent_storage'), 'rb') as fd: fd.seek(0) return pickle.load(fd) -def levenshtein(a, b, return_table=False): - '''returns the levenshtein distance between a and b''' - # initialisize a table with 0, but the 0-rows/cols with their index - d = [[(i if 0 == j else j if 0 == i else 0) for j in range(len(b)+1)] for i in range(len(a)+1)] - - i = j = 0 - for i in range(1, len(a)+1): - for j in range(1, len(b)+1): - if a[i-1] == b[j-1]: - d[i][j] = d[i-1][j-1] - else: - d[i][j] = min( - d[i-1][j] + 1, # deletion - d[i][j-1] + 1, # insertion - d[i-1][j-1] + 1, # substitution - ) - - if return_table: - return (d, d[i][j]) - else: - return d[i][j] - def get_version_git(): import subprocess diff --git a/local_config.py.skel b/local_config.py.skel index 71c27c2..3b79229 100644 --- a/local_config.py.skel +++ b/local_config.py.skel @@ -31,6 +31,7 @@ config = { 'request_counter': 0, 'persistent_storage': 'urlbot.persistent', + 'persistent_locked': False, 'url_blacklist': [ r'^.*heise\.de/[^/]+/meldung/.*$', diff --git a/plugins.py b/plugins.py index 5e37c9d..4885114 100644 --- a/plugins.py +++ b/plugins.py @@ -626,10 +626,7 @@ def event_trigger(): now = time.time() - i = 0 - for (t, callback, args) in joblist: + for (i, (t, callback, args)) in enumerate(joblist): if t < now: callback(*args) del(joblist[i]) - - i += 1 diff --git a/urlbot.py b/urlbot.py index 8b575e8..ca9c493 100755 --- a/urlbot.py +++ b/urlbot.py @@ -245,6 +245,7 @@ class bot(ClientXMPP): self.add_event_handler('session_start', self.session_start) self.add_event_handler('groupchat_message', self.muc_message) + self.add_event_handler('message', self.message) def session_start(self, event): self.get_roster() @@ -264,6 +265,12 @@ class bot(ClientXMPP): return handle_msg(msg_obj) + def message(self, msg_obj): + if 'groupchat' == msg_obj['type']: + return + + print('msg from %s: %s' % (msg_obj['from'].bare, msg_obj['body'])) + if '__main__' == __name__: import plugins