add !apropos - to show commands with a given string in them

closes #133
This commit is contained in:
jesopo 2019-10-08 14:45:46 +01:00
parent 0226b48b0c
commit c547df81dd

View file

@ -84,3 +84,19 @@ class Module(ModuleManager.BaseModule):
event["stdout"].write("Commands for %s module: %s" % (
module.name, ", ".join(commands)))
@utils.hook("received.command.apropos")
@utils.kwarg("min_args", 1)
@utils.kwarg("help", "Show commands with a given string in them")
@utils.kwarg("usage", "<query>")
def apropos(self, event):
query = event["args_split"][0]
query_lower = query.lower()
commands = []
for command, hook in self._all_command_hooks().items():
if query_lower in command.lower():
commands.append("%s%s" % (event["command_prefix"], command))
if commands:
event["stdout"].write("Apropos of '%s': %s" %
(query, ", ".join(commands)))