:D new simplier command API kinda working
This commit is contained in:
parent
5c6367a0f7
commit
3378fb081f
2 changed files with 1 additions and 25 deletions
|
@ -14,7 +14,7 @@ with open("./data/8ball_responses.txt") as f:
|
||||||
f.readlines() if not line.startswith("//")]
|
f.readlines() if not line.startswith("//")]
|
||||||
|
|
||||||
|
|
||||||
@hook.command('8ball')
|
@hook.command()
|
||||||
def eightball(input, conn):
|
def eightball(input, conn):
|
||||||
"""8ball <question> -- The all knowing magic eight ball,
|
"""8ball <question> -- The all knowing magic eight ball,
|
||||||
in electronic form. Ask and it shall be answered!"""
|
in electronic form. Ask and it shall be answered!"""
|
||||||
|
|
24
util/hook.py
24
util/hook.py
|
@ -10,30 +10,6 @@ def _hook_add(func, add, name=''):
|
||||||
if not hasattr(func, '_filename'):
|
if not hasattr(func, '_filename'):
|
||||||
func._filename = func.__code__.co_filename
|
func._filename = func.__code__.co_filename
|
||||||
|
|
||||||
if not hasattr(func, '_args'):
|
|
||||||
argspec = inspect.getargspec(func)
|
|
||||||
if name:
|
|
||||||
n_args = len(argspec.args)
|
|
||||||
if argspec.defaults:
|
|
||||||
n_args -= len(argspec.defaults)
|
|
||||||
if argspec.keywords:
|
|
||||||
n_args -= 1
|
|
||||||
if argspec.varargs:
|
|
||||||
n_args -= 1
|
|
||||||
if n_args != 1:
|
|
||||||
err = '%ss must take 1 non-keyword argument (%s)' % (name,
|
|
||||||
func.__name__)
|
|
||||||
raise ValueError(err)
|
|
||||||
|
|
||||||
args = []
|
|
||||||
if argspec.defaults:
|
|
||||||
end = bool(argspec.keywords) + bool(argspec.varargs)
|
|
||||||
args.extend(argspec.args[-len(argspec.defaults):
|
|
||||||
end if end else None])
|
|
||||||
if argspec.keywords:
|
|
||||||
args.append(0) # means kwargs present
|
|
||||||
func._args = args
|
|
||||||
|
|
||||||
if not hasattr(func, '_thread'): # does function run in its own thread?
|
if not hasattr(func, '_thread'): # does function run in its own thread?
|
||||||
func._thread = False
|
func._thread = False
|
||||||
|
|
||||||
|
|
Reference in a new issue