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

45 lines
1.3 KiB
Python
Raw Normal View History

2016-04-05 14:18:22 +02:00
# -*- coding: utf-8 -*-
import logging
2016-04-05 14:18:22 +02:00
log = logging.getLogger(__name__)
2016-04-04 00:47:14 +02:00
import time
import random
import config
2016-04-05 14:18:22 +02:00
from plugin_system import pluginfunction, ptypes
2016-04-04 00:47:14 +02:00
2016-04-05 14:18:22 +02:00
@pluginfunction('comment_joins', 'comments frequent joins', ptypes.MUC_ONLINE)
@config.config_locked
2016-04-04 00:47:14 +02:00
def comment_joins(**args):
# max elapsed time between the latest and the N latest join
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']
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.runtimeconf_persist()
return None
user_joins = config.runtime_config_store['user_joins'][arg_user_key]
user_joins = [
ts if current_timestamp - int(ts) <= timespan else [] for ts in user_joins
]
user_joins.append(current_timestamp)
if len(user_joins) >= max_joins:
config.runtime_config_store['user_joins'].pop(arg_user_key)
config.runtimeconf_persist()
return { 'msg': random.choice(comment_joins_strings) % arg_user }
else:
config.runtimeconf_persist()