1
0
Fork 0

Hooks can now contain help on optional keywords

This commit is contained in:
nemunaire 2015-10-31 14:49:44 +01:00
parent c6aa38147b
commit 9790954dfc
2 changed files with 7 additions and 2 deletions

View File

@ -100,7 +100,9 @@ class Bot(threading.Thread):
for (s, h) in self.modules[module].__nemubot_context__.hooks:
if s == "in_Command" and (h.name is not None or h.regexp is not None) and h.is_matching(msg.args[0][1:]):
if h.help_usage:
return res.append_message(["\x03\x02%s%s\x03\x02: %s" % (msg.args[0], (" " + k if k is not None else ""), h.help_usage[k]) for k in h.help_usage], title="Usage for command %s from module %s" % (msg.args[0], module))
lp = ["\x03\x02%s%s\x03\x02: %s" % (msg.args[0], (" " + k if k is not None else ""), h.help_usage[k]) for k in h.help_usage]
jp = ["\x03\x02@%s\x03\x02: %s" % (k, h.keywords[k]) for k in h.keywords]
return res.append_message(lp + ([". Moreover, you can provides some optional parameters: "] + jp if len(jp) else []), title="Usage for command %s from module %s" % (msg.args[0], module))
elif h.help:
return res.append_message("Command %s from module %s: %s" % (msg.args[0], module, h.help))
else:

View File

@ -25,7 +25,8 @@ class Message(Abstract):
"""Class storing hook information, specialized for a generic Message"""
def __init__(self, call, name=None, regexp=None, channels=list(),
server=None, help=None, help_usage=dict(), **kargs):
server=None, help=None, help_usage=dict(), keywords=dict(),
**kargs):
Abstract.__init__(self, call=call, **kargs)
@ -33,6 +34,7 @@ class Message(Abstract):
assert channels is None or type(channels) is list, channels
assert server is None or type(server) is str, server
assert type(help_usage) is dict, help_usage
assert type(keywords) is dict, keywords
self.name = str(name) if name is not None else None
self.regexp = regexp
@ -40,6 +42,7 @@ class Message(Abstract):
self.channels = channels
self.help = help
self.help_usage = help_usage
self.keywords = keywords
def __str__(self):