mirror of
http://aero2k.de/t/repos/urlbot-native.git
synced 2017-09-06 15:25:38 +02:00
add modul. "help"; prep "save"; add {desc}
This commit is contained in:
12
common.py
12
common.py
@@ -5,7 +5,8 @@ if '__main__' == __name__:
|
|||||||
print '''this is a library file, which is not meant to be executed'''
|
print '''this is a library file, which is not meant to be executed'''
|
||||||
exit(-1)
|
exit(-1)
|
||||||
|
|
||||||
import sys, os, time
|
import sys, os, time, pickle
|
||||||
|
from local_config import conf
|
||||||
|
|
||||||
RATE_GLOBAL = 0x01
|
RATE_GLOBAL = 0x01
|
||||||
RATE_NO_SILENCE = 0x02
|
RATE_NO_SILENCE = 0x02
|
||||||
@@ -43,6 +44,15 @@ def logger(severity, message):
|
|||||||
args = (sys.argv[0], time.strftime('%Y-%m-%d.%H:%M:%S'), severity, message)
|
args = (sys.argv[0], time.strftime('%Y-%m-%d.%H:%M:%S'), severity, message)
|
||||||
sys.stderr.write(e('%s %s %s: %s' % args) + '\n')
|
sys.stderr.write(e('%s %s %s: %s' % args) + '\n')
|
||||||
|
|
||||||
|
def conf_save(obj):
|
||||||
|
with open(conf('persistent_storage'), 'wb') as fd:
|
||||||
|
return pickle.dump(obj, fd)
|
||||||
|
|
||||||
|
def conf_load():
|
||||||
|
with open(conf('persistent_storage'), 'rb') as fd:
|
||||||
|
fd.seek(0)
|
||||||
|
return pickle.load(fd)
|
||||||
|
|
||||||
def get_version_git():
|
def get_version_git():
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
|
||||||
import time
|
import time, sys
|
||||||
|
|
||||||
|
def _logger(a, b): sys.stderr.write('logger: %s::%s\n' %(a, b))
|
||||||
|
try: logger
|
||||||
|
except NameError: logger = _logger
|
||||||
|
|
||||||
if '__main__' == __name__:
|
if '__main__' == __name__:
|
||||||
print '''this is a config file, which is not meant to be executed'''
|
print '''this is a config file, which is not meant to be executed'''
|
||||||
@@ -18,12 +22,15 @@ config['hist_max_time'] = 10 * 60
|
|||||||
config['uptime'] = -time.time()
|
config['uptime'] = -time.time()
|
||||||
config['request_counter'] = 0
|
config['request_counter'] = 0
|
||||||
|
|
||||||
|
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' )
|
||||||
|
|
||||||
def conf(val):
|
def conf(val):
|
||||||
if val in config.keys():
|
if val in config.keys():
|
||||||
return config[val]
|
return config[val]
|
||||||
|
logger('warn', 'conf(): unknown key ' + str(val))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def set_conf(key, val):
|
def set_conf(key, val):
|
||||||
|
|||||||
87
plugins.py
87
plugins.py
@@ -85,23 +85,63 @@ def data_parse_other(data):
|
|||||||
ratelimit_touch(RATE_CHAT)
|
ratelimit_touch(RATE_CHAT)
|
||||||
chat_write(ret['msg'])
|
chat_write(ret['msg'])
|
||||||
|
|
||||||
def command_help(args):
|
def command_command(args):
|
||||||
if 'register' == args:
|
if 'register' == args:
|
||||||
return {
|
return {
|
||||||
'name': 'prints help',
|
'name': 'command',
|
||||||
'args': ('data', 'reply_user'),
|
'desc': 'lists commands',
|
||||||
|
'args': ('data', 'reply_user', 'cmd_list'),
|
||||||
'ratelimit_class': RATE_GLOBAL
|
'ratelimit_class': RATE_GLOBAL
|
||||||
}
|
}
|
||||||
|
|
||||||
if 'command' in args['data']:
|
if 'command' in args['data']:
|
||||||
return {
|
return {
|
||||||
'msg': args['reply_user'] + (""": known commands: 'command', 'dice', 'info', 'hangup', 'nospoiler', 'ping', 'uptime', 'source', 'version'""")
|
'msg': args['reply_user'] + ': known commands: ' + str(args['cmd_list']).strip('[]')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def command_help(args):
|
||||||
|
if 'register' == args:
|
||||||
|
return {
|
||||||
|
'name': 'help',
|
||||||
|
'desc': 'print help for a command',
|
||||||
|
'args': ('data', 'reply_user', 'cmd_list'),
|
||||||
|
'ratelimit_class': RATE_GLOBAL
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
cmd = None
|
||||||
|
flag = False
|
||||||
|
|
||||||
|
for word in args['data'].split():
|
||||||
|
if True == flag:
|
||||||
|
cmd = word
|
||||||
|
break
|
||||||
|
|
||||||
|
if 'help' == word:
|
||||||
|
flag = True
|
||||||
|
|
||||||
|
if None == cmd:
|
||||||
|
return {
|
||||||
|
'msg': args['reply_user'] + ': no command given'
|
||||||
|
}
|
||||||
|
|
||||||
|
if not cmd in [p['name'] for p in plugins['command']]:
|
||||||
|
return {
|
||||||
|
'msg': args['reply_user'] + ': no such command: %s' % cmd
|
||||||
|
}
|
||||||
|
|
||||||
|
for p in plugins['command']:
|
||||||
|
if cmd == p['name']:
|
||||||
|
return {
|
||||||
|
'msg': args['reply_user'] + ': help for %s: %s' %(cmd, p['desc'])
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def command_version(args):
|
def command_version(args):
|
||||||
if 'register' == args:
|
if 'register' == args:
|
||||||
return {
|
return {
|
||||||
'name': 'prints version',
|
'name': 'version',
|
||||||
|
'desc': 'prints version',
|
||||||
'args': ('data', 'reply_user'),
|
'args': ('data', 'reply_user'),
|
||||||
'ratelimit_class': RATE_GLOBAL
|
'ratelimit_class': RATE_GLOBAL
|
||||||
}
|
}
|
||||||
@@ -114,7 +154,8 @@ def command_version(args):
|
|||||||
def command_unicode(args):
|
def command_unicode(args):
|
||||||
if 'register' == args:
|
if 'register' == args:
|
||||||
return {
|
return {
|
||||||
'name': 'prints an unicode string',
|
'name': 'unikot',
|
||||||
|
'desc': 'prints an unicode string',
|
||||||
'args': ('data', 'reply_user'),
|
'args': ('data', 'reply_user'),
|
||||||
'ratelimit_class': RATE_GLOBAL
|
'ratelimit_class': RATE_GLOBAL
|
||||||
}
|
}
|
||||||
@@ -130,7 +171,8 @@ def command_unicode(args):
|
|||||||
def command_source(args):
|
def command_source(args):
|
||||||
if 'register' == args:
|
if 'register' == args:
|
||||||
return {
|
return {
|
||||||
'name': 'prints git URL',
|
'name': 'source',
|
||||||
|
'desc': 'prints git URL',
|
||||||
'args': ('data', 'reply_user'),
|
'args': ('data', 'reply_user'),
|
||||||
'ratelimit_class': RATE_GLOBAL
|
'ratelimit_class': RATE_GLOBAL
|
||||||
}
|
}
|
||||||
@@ -143,7 +185,8 @@ def command_source(args):
|
|||||||
def command_dice(args):
|
def command_dice(args):
|
||||||
if 'register' == args:
|
if 'register' == args:
|
||||||
return {
|
return {
|
||||||
'name': 'rolls a dice',
|
'name': 'dice',
|
||||||
|
'desc': 'rolls a dice',
|
||||||
'args': ('data', 'reply_user'),
|
'args': ('data', 'reply_user'),
|
||||||
'ratelimit_class': RATE_INTERACTIVE
|
'ratelimit_class': RATE_INTERACTIVE
|
||||||
}
|
}
|
||||||
@@ -162,7 +205,8 @@ def command_dice(args):
|
|||||||
def command_uptime(args):
|
def command_uptime(args):
|
||||||
if 'register' == args:
|
if 'register' == args:
|
||||||
return {
|
return {
|
||||||
'name': 'prints uptime',
|
'name': 'uptime',
|
||||||
|
'desc': 'prints uptime',
|
||||||
'args': ('data', 'reply_user'),
|
'args': ('data', 'reply_user'),
|
||||||
'ratelimit_class': RATE_GLOBAL
|
'ratelimit_class': RATE_GLOBAL
|
||||||
}
|
}
|
||||||
@@ -183,7 +227,8 @@ def command_uptime(args):
|
|||||||
def command_ping(args):
|
def command_ping(args):
|
||||||
if 'register' == args:
|
if 'register' == args:
|
||||||
return {
|
return {
|
||||||
'name': 'pong',
|
'name': 'ping',
|
||||||
|
'desc': 'sends pong',
|
||||||
'args': ('data', 'reply_user'),
|
'args': ('data', 'reply_user'),
|
||||||
'ratelimit_class': RATE_INTERACTIVE
|
'ratelimit_class': RATE_INTERACTIVE
|
||||||
}
|
}
|
||||||
@@ -207,7 +252,8 @@ def command_ping(args):
|
|||||||
def command_info(args):
|
def command_info(args):
|
||||||
if 'register' == args:
|
if 'register' == args:
|
||||||
return {
|
return {
|
||||||
'name': 'prints info message',
|
'name': 'info',
|
||||||
|
'desc': 'prints info message',
|
||||||
'args': ('data', 'reply_user'),
|
'args': ('data', 'reply_user'),
|
||||||
'ratelimit_class': RATE_GLOBAL
|
'ratelimit_class': RATE_GLOBAL
|
||||||
}
|
}
|
||||||
@@ -241,8 +287,6 @@ def data_parse_commands(data):
|
|||||||
|
|
||||||
reply_user = get_reply_user(data)
|
reply_user = get_reply_user(data)
|
||||||
|
|
||||||
flag = False
|
|
||||||
|
|
||||||
for p in plugins['command']:
|
for p in plugins['command']:
|
||||||
if ratelimit_exceeded(p['ratelimit_class']):
|
if ratelimit_exceeded(p['ratelimit_class']):
|
||||||
continue
|
continue
|
||||||
@@ -255,6 +299,10 @@ def data_parse_commands(data):
|
|||||||
|
|
||||||
if 'data' == a:
|
if 'data' == a:
|
||||||
args['data'] = data
|
args['data'] = data
|
||||||
|
elif 'cmd_list' == a:
|
||||||
|
cmds = [c['name'] for c in plugins['command']]
|
||||||
|
cmds.sort()
|
||||||
|
args['cmd_list'] = cmds
|
||||||
elif 'reply_user' == a:
|
elif 'reply_user' == a:
|
||||||
args['reply_user'] = reply_user
|
args['reply_user'] = reply_user
|
||||||
else:
|
else:
|
||||||
@@ -263,13 +311,10 @@ def data_parse_commands(data):
|
|||||||
ret = p['func'](args)
|
ret = p['func'](args)
|
||||||
|
|
||||||
if None != ret:
|
if None != ret:
|
||||||
flag = True
|
|
||||||
if 'msg' in ret.keys():
|
if 'msg' in ret.keys():
|
||||||
ratelimit_touch(RATE_CHAT)
|
ratelimit_touch(RATE_CHAT)
|
||||||
chat_write(ret['msg'])
|
chat_write(ret['msg'])
|
||||||
|
return None
|
||||||
if False != flag:
|
|
||||||
return None
|
|
||||||
|
|
||||||
ret = command_else({'reply_user': reply_user})
|
ret = command_else({'reply_user': reply_user})
|
||||||
if None != ret:
|
if None != ret:
|
||||||
@@ -282,14 +327,14 @@ def data_parse_commands(data):
|
|||||||
funcs = {}
|
funcs = {}
|
||||||
funcs['parse'] = (parse_mental_ill, parse_skynet)
|
funcs['parse'] = (parse_mental_ill, parse_skynet)
|
||||||
funcs['command'] = (
|
funcs['command'] = (
|
||||||
command_help, command_version, command_unicode, command_source,
|
command_command, command_help, command_version, command_unicode,
|
||||||
command_dice, command_uptime, command_ping, command_info
|
command_source, command_dice, command_uptime, command_ping, command_info
|
||||||
)
|
)
|
||||||
|
|
||||||
_dir = dir()
|
_dir = dir()
|
||||||
|
|
||||||
if debug_enabled():
|
if debug_enabled():
|
||||||
def _chat_write(a): _logger('chat_write', a)
|
def _chat_write(a): logger('chat_write', a)
|
||||||
def _conf(a): return 'bot'
|
def _conf(a): return 'bot'
|
||||||
def _ratelimit_exceeded(ignored=None): return False
|
def _ratelimit_exceeded(ignored=None): return False
|
||||||
def _ratelimit_touch(ignored=None): return True
|
def _ratelimit_touch(ignored=None): return True
|
||||||
@@ -303,6 +348,8 @@ if debug_enabled():
|
|||||||
try: ratelimit_touch
|
try: ratelimit_touch
|
||||||
except NameError: ratelimit_touch = _ratelimit_touch
|
except NameError: ratelimit_touch = _ratelimit_touch
|
||||||
|
|
||||||
|
logger('info', 'debugging enabled')
|
||||||
|
|
||||||
def register(func_type, auto=False):
|
def register(func_type, auto=False):
|
||||||
plugins[func_type] = []
|
plugins[func_type] = []
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user