diff --git a/plugins/core/help.py b/plugins/core/help.py index b9496ac9e..a3229e860 100644 --- a/plugins/core/help.py +++ b/plugins/core/help.py @@ -1,7 +1,7 @@ -from operator import attrgetter import asyncio -import re import os +import re +from operator import attrgetter from cloudbot import hook from cloudbot.util import formatting @@ -72,6 +72,46 @@ def help_command(text, chan, conn, bot, notice, message, has_permission): message(line) notice("For detailed help, use {}help , without the brackets.".format(conn.config["command_prefix"])) + +@asyncio.coroutine +@hook.command +def cmdinfo(text, bot, notice, event): + """ - Gets various information about a command""" + cmd = text.split()[0].lower().strip() + + if cmd in bot.plugin_manager.commands: + cmd_hook = bot.plugin_manager.commands[cmd] + else: + potentials = [] + for potential_match, plugin in bot.plugin_manager.commands.items(): + if potential_match.startswith(cmd): + potentials.append((potential_match, plugin)) + + if potentials: + if len(potentials) == 1: + cmd_hook = potentials[0][1] + else: + notice("Possible matches: {}".format( + formatting.get_text_list([command for command, plugin in potentials]))) + return + else: + cmd_hook = None + + if cmd_hook is None: + notice("Unknown command: '{}'".format(cmd)) + return + + hook_name = cmd_hook.plugin.title + "." + cmd_hook.function_name + info = "Command: {}, Aliases: [{}], Hook name: {}".format( + cmd_hook.name, ', '.join(cmd_hook.aliases), hook_name + ) + + if cmd_hook.permissions: + info += ", Permissions: [{}]".format(', '.join(cmd_hook.permissions)) + + notice(info) + + @hook.command(permissions=["botcontrol"], autohelp=False) def generatehelp(conn, bot, notice, has_permission): """Dumps a list of commands with their help text to the docs directory formatted using markdown."""