This repository has been archived on 2023-04-13. You can view files and clone it, but cannot push or open issues or pull requests.
CloudBot/plugins/help.py

49 lines
1.6 KiB
Python
Raw Normal View History

2011-11-20 10:23:31 +01:00
import re
from util import hook
2012-04-02 18:17:55 +02:00
2011-11-20 10:23:31 +01:00
@hook.command(autohelp=False)
2013-09-04 12:30:04 +02:00
def help(inp, notice=None, input=None, conn=None, bot=None):
"""help -- Gives a list of commands/help for a command."""
2011-11-20 10:23:31 +01:00
funcs = {}
disabled = bot.config.get('disabled_plugins', [])
disabled_comm = bot.config.get('disabled_commands', [])
for command, (func, args) in bot.commands.iteritems():
fn = re.match(r'^plugins.(.+).py$', func._filename)
if fn.group(1).lower() not in disabled:
if command not in disabled_comm:
if func.__doc__ is not None:
if func in funcs:
if len(funcs[func]) < len(command):
2011-11-20 10:23:31 +01:00
funcs[func] = command
else:
funcs[func] = command
2011-11-20 10:23:31 +01:00
2012-02-20 23:31:18 +01:00
commands = dict((value, key) for key, value in funcs.iteritems())
2011-11-20 10:23:31 +01:00
if not inp:
2013-09-06 05:51:01 +02:00
out = [""]
2011-11-20 10:23:31 +01:00
well = []
for x in commands:
2012-02-20 23:31:18 +01:00
well.append(x)
2011-11-20 10:23:31 +01:00
well.sort()
2013-09-06 05:51:01 +02:00
count = 0
2011-11-20 10:23:31 +01:00
for x in well:
2013-09-06 05:51:01 +02:00
if len(out[count]) + len(str(x)) > 405:
count += 1
out.append(str(x))
2011-11-20 10:23:31 +01:00
else:
2013-09-06 05:51:01 +02:00
out[count] += " " + str(x)
2012-04-02 18:17:55 +02:00
2012-02-19 12:00:51 +01:00
notice("Commands I recognise: " + out[0][1:])
2013-09-06 05:51:01 +02:00
if len(out) > 1:
for x in out[1:]:
notice(x)
2013-09-04 12:30:04 +02:00
notice("For detailed help, do '%shelp <example>' where <example> "
2012-09-04 21:52:03 +02:00
"is the name of the command you want help for." % conn.conf["command_prefix"])
2012-04-02 18:17:55 +02:00
2011-11-20 10:23:31 +01:00
else:
if inp in commands:
notice(conn.conf["command_prefix"] + commands[inp].__doc__)