From c6baf3cf601ee4eac1d19e33f5d6d8e84493c9f1 Mon Sep 17 00:00:00 2001 From: braph Date: Tue, 5 Apr 2016 18:13:47 +0200 Subject: [PATCH] changes in plugin comment_joins --- plugins/comment_joins.py | 23 ++++++++++++++--------- plugins/moin.py | 1 + 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/plugins/comment_joins.py b/plugins/comment_joins.py index 8c0ac02..65d666a 100644 --- a/plugins/comment_joins.py +++ b/plugins/comment_joins.py @@ -8,6 +8,10 @@ import random import config from plugin_system import pluginfunction, ptypes +comment_joins_strings = [ + "%s: please consider to fix your internet connection" +] + @pluginfunction('comment_joins', 'comments frequent joins', ptypes.MUC_ONLINE) @config.config_locked def comment_joins(**args): @@ -15,10 +19,6 @@ def comment_joins(**args): timespan = 120 max_joins = 6 - comment_joins_strings = [ - "%s: please consider to fix your internet connection" - ] - current_timestamp = int(time.time()) arg_user = args['reply_user'] @@ -29,16 +29,21 @@ def comment_joins(**args): config.runtimeconf_persist() return None - user_joins = config.runtime_config_store['user_joins'][arg_user_key] + user_joins = [] + + for ts in config.runtime_config_store['user_joins'][arg_user_key]: + if current_timestamp - int(ts) <= timespan: + user_joins.append(ts) - user_joins = [ - ts if current_timestamp - int(ts) <= timespan else [] for ts in user_joins - ] - user_joins.append(current_timestamp) + print(user_joins) if len(user_joins) >= max_joins: config.runtime_config_store['user_joins'].pop(arg_user_key) config.runtimeconf_persist() + log.info("send comment on join") return { 'msg': random.choice(comment_joins_strings) % arg_user } else: + user_joins.append(current_timestamp) + config.runtime_config_store['user_joins'][arg_user_key] = user_joins config.runtimeconf_persist() + diff --git a/plugins/moin.py b/plugins/moin.py index c3f9702..2373b35 100644 --- a/plugins/moin.py +++ b/plugins/moin.py @@ -2,6 +2,7 @@ import logging log = logging.getLogger(__name__) +import config from plugin_system import pluginfunction, ptypes moin_strings_hi = [