2010-11-22 03:12:59 +00:00
|
|
|
import re
|
|
|
|
|
2010-01-17 04:24:36 +00:00
|
|
|
from util import hook
|
|
|
|
|
2010-03-01 02:32:41 +00:00
|
|
|
|
2010-05-07 23:16:44 +00:00
|
|
|
@hook.command(autohelp=False)
|
2010-02-02 04:42:34 +00:00
|
|
|
def help(inp, bot=None, pm=None):
|
2010-01-17 04:24:36 +00:00
|
|
|
".help [command] -- gives a list of commands/help for a command"
|
2010-03-01 02:32:41 +00:00
|
|
|
|
2010-01-17 04:24:36 +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', [])
|
2010-03-13 14:09:16 +00:00
|
|
|
for command, (func, args) in bot.commands.iteritems():
|
2010-11-22 03:12:59 +00:00
|
|
|
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:
|
2010-11-22 03:12:59 +00:00
|
|
|
funcs[func] = command
|
2010-03-13 14:09:16 +00:00
|
|
|
|
|
|
|
commands = dict((value, key) for key, value in funcs.iteritems())
|
2010-01-17 04:24:36 +00:00
|
|
|
|
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)))
|
2010-01-17 04:24:36 +00:00
|
|
|
else:
|
2010-03-13 14:09:16 +00:00
|
|
|
if inp in commands:
|
|
|
|
pm(commands[inp].__doc__)
|