diff --git a/plugins/comment_joins.py b/plugins/comment_joins.py index 9efda82..dfecd63 100644 --- a/plugins/comment_joins.py +++ b/plugins/comment_joins.py @@ -1,11 +1,10 @@ # -*- coding: utf-8 -*- import logging - import time import random - import config from plugin_system import pluginfunction, ptypes + log = logging.getLogger(__name__) comment_joins_strings = [ @@ -17,8 +16,8 @@ comment_joins_strings = [ @config.config_locked def comment_joins(**args): # max elapsed time between the latest and the N latest join - timespan = 120 - max_joins = 6 + timespan = 120 + max_joins = config.runtime_config_store current_timestamp = int(time.time()) @@ -26,12 +25,12 @@ def comment_joins(**args): arg_user_key = arg_user.lower() if arg_user_key not in config.runtime_config_store['user_joins']: - config.runtime_config_store['user_joins'][arg_user_key] = [ current_timestamp ] + config.runtime_config_store['user_joins'][arg_user_key] = [current_timestamp] config.runtimeconf_persist() return None - user_joins = [] - + user_joins = [] + for ts in config.runtime_config_store['user_joins'][arg_user_key]: if current_timestamp - int(ts) <= timespan: user_joins.append(ts) @@ -42,7 +41,7 @@ def comment_joins(**args): 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 } + 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