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

48 lines
1.6 KiB
Python
Raw Normal View History

2011-11-20 10:23:31 +01:00
import re
from util import hook
@hook.command(autohelp=False)
2012-02-21 00:18:06 +01:00
def help(inp, input=None, bot=None, say=None, notice=None):
2012-02-28 03:03:43 +01:00
".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:
2012-03-22 05:04:48 +01:00
if not args.get('adminonly', False) or input.mask in input.bot.config["admins"]:
if command not in disabled_comm:
if func.__doc__ is not None:
if func in funcs:
if len(funcs[func]) < len(command):
funcs[func] = command
else:
2011-11-20 10:23:31 +01:00
funcs[func] = command
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:
length = 0
2012-02-29 09:29:53 +01: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()
for x in well:
if len(out[0]) + len(str(x)) > 405:
2011-11-20 10:23:31 +01:00
out[1] += " " + str(x)
else:
out[0] += " " + str(x)
2012-02-19 12:00:51 +01:00
notice("Commands I recognise: " + out[0][1:])
2011-11-20 10:23:31 +01:00
if out[1]:
notice(out[1][1:])
2012-02-28 03:03:43 +01:00
notice("For detailed help, do '.help <example>' where <example> is the " +
2012-02-19 12:00:51 +01:00
"name of the command you want help for.")
2012-02-20 23:48:21 +01:00
2011-11-20 10:23:31 +01:00
else:
if inp in commands:
2012-02-20 23:48:21 +01:00
notice(commands[inp].__doc__)