diff --git a/local_config.py.skel b/local_config.py.skel
index dbb806a..a08409d 100644
--- a/local_config.py.skel
+++ b/local_config.py.skel
@@ -27,6 +27,8 @@ config['persistent_storage'] = 'urlbot.persistent'
# the "dice" feature will use more efficient random data (0) for given users
config['enhanced-random-user'] = ( 'FIXME', 'FIXME' )
+config['tea_steep_time'] = (3*60 + 40)
+
def conf(val):
if val in list(config.keys()):
return config[val]
diff --git a/plugins.py b/plugins.py
index e46efcd..91c238f 100644
--- a/plugins.py
+++ b/plugins.py
@@ -9,6 +9,8 @@ import time, random
from local_config import conf
from common import *
+joblist = []
+
plugins = {}
plugins['parse'] = []
plugins['command'] = []
@@ -18,6 +20,9 @@ def get_reply_user(data):
# or a user 'foo' just wrote '> > bar'
return data.split(' ')[0].strip('<>')
+def register_event(t, callback, args):
+ joblist.append((t, callback, args))
+
def parse_mental_ill(args):
if 'register' == args:
return {
@@ -280,6 +285,27 @@ def command_info(args):
'msg': args['reply_user'] + (''': I'm a bot, my job is to extract
tags from posted URLs. In case I'm annoying or for further questions, please talk to my master %s. I'm rate limited and shouldn't post more than %d messages per %d seconds. To make me exit immediately, highlight me with 'hangup' in the message (emergency only, please). For other commands, highlight me with 'command'.''' %(conf('bot_owner'), conf('hist_max_count'), conf('hist_max_time')))
}
+def command_teatimer(args):
+ if 'register' == args:
+ return {
+ 'name': 'teatimer',
+ 'desc': 'sets a tea timer',
+ 'args': ('data', 'reply_user'),
+ 'ratelimit_class': RATE_GLOBAL
+ }
+
+ if 'teatimer' in args['data']:
+ ready = time.time() + conf('tea_steep_time')
+
+ logger('plugin', 'tea timer set to %s' % time.strftime('%F.%T', time.localtime(ready)))
+ register_event(ready, chat_write, args['reply_user'] + ': Your tea is ready!')
+
+ return {
+ 'msg': args['reply_user'] + ': Tea timer set to %s' % time.strftime(
+ '%F.%T', time.localtime(ready)
+ )
+ }
+
def command_else(args):
logger('plugin', 'sent short info')
return {
@@ -356,7 +382,8 @@ funcs = {}
funcs['parse'] = (parse_mental_ill, parse_skynet)
funcs['command'] = (
command_command, command_help, command_version, command_unicode,
- command_source, command_dice, command_uptime, command_ping, command_info
+ command_source, command_dice, command_uptime, command_ping, command_info,
+ command_teatimer
)
_dir = dir()
@@ -405,3 +432,17 @@ def register(func_type, auto=False):
def register_all():
register('parse')
register('command')
+
+def event_trigger():
+ if 0 == len(joblist):
+ return
+
+ now = time.time()
+
+ i = 0
+ for (t, callback, args) in joblist:
+ if t < now:
+ callback(args)
+ del(joblist[i])
+
+ i += 1
diff --git a/urlbot.py b/urlbot.py
index 62db411..fca7f0a 100755
--- a/urlbot.py
+++ b/urlbot.py
@@ -182,7 +182,7 @@ def parse_delete(filepath):
return
if 'nospoiler' in content:
- logger('info', "no spoiler for: " + content)
+# logger('info', "no spoiler for: " + content)
return
if True != extract_url(content):
@@ -215,6 +215,8 @@ if '__main__' == __name__:
if 'mcabber-' == f[:8]:
parse_delete(os.path.join(event_files_dir, f))
+ plugins.event_trigger()
+
time.sleep(delay)
except KeyboardInterrupt:
print('')