h/plugins/help.py

31 lines
995 B
Python
Raw Permalink Normal View History

import re
from util import hook
2010-03-01 02:32:41 +00:00
@hook.command(autohelp=False)
2010-02-02 04:42:34 +00:00
def help(inp, bot=None, pm=None):
".help [command] -- gives a list of commands/help for a command"
2010-03-01 02:32:41 +00:00
funcs = {}
2010-11-22 05:28:45 +00:00
disabled = bot.config.get('disabled_plugins', [])
2010-11-22 08:03:32 +00:00
disabled_comm = bot.config.get('disabled_commands', [])
2015-11-15 16:36:35 +00:00
for command, (func, args) in bot.commands.items():
fn = re.match(r'^plugins.(.+).py$', func._filename)
if fn.group(1).lower() not in disabled:
2010-11-22 08:03:32 +00:00
if command not in disabled_comm:
2010-11-22 05:28:45 +00:00
if func.__doc__ is not None:
if func in funcs:
if len(funcs[func]) < len(command):
funcs[func] = command
else:
funcs[func] = command
2010-03-13 14:09:16 +00:00
2015-11-15 16:36:35 +00:00
commands = dict((value, key) for key, value in funcs.items())
2010-02-02 04:42:34 +00:00
if not inp:
2010-03-13 14:09:16 +00:00
pm('available commands: ' + ' '.join(sorted(commands)))
else:
2010-03-13 14:09:16 +00:00
if inp in commands:
pm(commands[inp].__doc__)