mirror of
http://aero2k.de/t/repos/urlbot-native.git
synced 2017-09-06 15:25:38 +02:00
a "teatimer" implemented
This commit is contained in:
@@ -27,6 +27,8 @@ config['persistent_storage'] = 'urlbot.persistent'
|
|||||||
# the "dice" feature will use more efficient random data (0) for given users
|
# the "dice" feature will use more efficient random data (0) for given users
|
||||||
config['enhanced-random-user'] = ( 'FIXME', 'FIXME' )
|
config['enhanced-random-user'] = ( 'FIXME', 'FIXME' )
|
||||||
|
|
||||||
|
config['tea_steep_time'] = (3*60 + 40)
|
||||||
|
|
||||||
def conf(val):
|
def conf(val):
|
||||||
if val in list(config.keys()):
|
if val in list(config.keys()):
|
||||||
return config[val]
|
return config[val]
|
||||||
|
|||||||
43
plugins.py
43
plugins.py
@@ -9,6 +9,8 @@ import time, random
|
|||||||
from local_config import conf
|
from local_config import conf
|
||||||
from common import *
|
from common import *
|
||||||
|
|
||||||
|
joblist = []
|
||||||
|
|
||||||
plugins = {}
|
plugins = {}
|
||||||
plugins['parse'] = []
|
plugins['parse'] = []
|
||||||
plugins['command'] = []
|
plugins['command'] = []
|
||||||
@@ -18,6 +20,9 @@ def get_reply_user(data):
|
|||||||
# or a user 'foo' just wrote '> > bar'
|
# or a user 'foo' just wrote '> > bar'
|
||||||
return data.split(' ')[0].strip('<>')
|
return data.split(' ')[0].strip('<>')
|
||||||
|
|
||||||
|
def register_event(t, callback, args):
|
||||||
|
joblist.append((t, callback, args))
|
||||||
|
|
||||||
def parse_mental_ill(args):
|
def parse_mental_ill(args):
|
||||||
if 'register' == args:
|
if 'register' == args:
|
||||||
return {
|
return {
|
||||||
@@ -280,6 +285,27 @@ def command_info(args):
|
|||||||
'msg': args['reply_user'] + (''': I'm a bot, my job is to extract <title> 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')))
|
'msg': args['reply_user'] + (''': I'm a bot, my job is to extract <title> 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):
|
def command_else(args):
|
||||||
logger('plugin', 'sent short info')
|
logger('plugin', 'sent short info')
|
||||||
return {
|
return {
|
||||||
@@ -356,7 +382,8 @@ funcs = {}
|
|||||||
funcs['parse'] = (parse_mental_ill, parse_skynet)
|
funcs['parse'] = (parse_mental_ill, parse_skynet)
|
||||||
funcs['command'] = (
|
funcs['command'] = (
|
||||||
command_command, command_help, command_version, command_unicode,
|
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()
|
_dir = dir()
|
||||||
@@ -405,3 +432,17 @@ def register(func_type, auto=False):
|
|||||||
def register_all():
|
def register_all():
|
||||||
register('parse')
|
register('parse')
|
||||||
register('command')
|
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
|
||||||
|
|||||||
@@ -182,7 +182,7 @@ def parse_delete(filepath):
|
|||||||
return
|
return
|
||||||
|
|
||||||
if 'nospoiler' in content:
|
if 'nospoiler' in content:
|
||||||
logger('info', "no spoiler for: " + content)
|
# logger('info', "no spoiler for: " + content)
|
||||||
return
|
return
|
||||||
|
|
||||||
if True != extract_url(content):
|
if True != extract_url(content):
|
||||||
@@ -215,6 +215,8 @@ if '__main__' == __name__:
|
|||||||
if 'mcabber-' == f[:8]:
|
if 'mcabber-' == f[:8]:
|
||||||
parse_delete(os.path.join(event_files_dir, f))
|
parse_delete(os.path.join(event_files_dir, f))
|
||||||
|
|
||||||
|
plugins.event_trigger()
|
||||||
|
|
||||||
time.sleep(delay)
|
time.sleep(delay)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print('')
|
print('')
|
||||||
|
|||||||
Reference in New Issue
Block a user