X-Git-Url: https://jfr.im/git/erebus.git/blobdiff_plain/aaf381b89dbe853f0106d6e90a4a40d3265d3027..7d0de55e2fd60d6309075a68b29e68e5e64c4aa9:/modules/help.py diff --git a/modules/help.py b/modules/help.py index bc4c17d..b336240 100644 --- a/modules/help.py +++ b/modules/help.py @@ -56,19 +56,45 @@ def dereghelp(func, *args, **kwargs): del cmds[cmd] del helps[func] +class HelpLine(object): + def __init__(self, cmd, syntax, shorthelp, level=0): + self.cmd = cmd + self.syntax = syntax + self.shorthelp = shorthelp + self.level = level + + def __cmp__(self, other): + if self.level == other.level: + return cmp(self.cmd, other.cmd) + else: + return cmp(self.level, other.level) + + + def __str__(self): + if self.level <= 0: + return "%-40s - %-50s" % (self.cmd+' '+self.syntax, self.shorthelp) + else: + return "%-35s(%3s) - %-50s" % (self.cmd+' '+self.syntax, self.level, self.shorthelp) + @lib.hook(needchan=False) @lib.help('[]', 'lists commands or describes a command') def help(bot, user, chan, realtarget, *args): #TODO add ordering - by access level, then alphabetic? if len(args) == 0: # list commands + lines = [] for func in helps.itervalues(): if user.glevel >= func.reqglevel: if func.reqglevel <= 0: - bot.slowmsg(user, "%-40s - %-50s" % (func.cmd[0]+' '+func.syntax, func.shorthelp)) + lines.append(HelpLine(func.cmd[0], func.syntax, func.shorthelp)) +# bot.slowmsg(user, "%-40s - %-50s" % (func.cmd[0]+' '+func.syntax, func.shorthelp)) else: - bot.slowmsg(user, "%-40s - %-50s (%5s)" % (func.cmd[0]+' '+func.syntax, func.shorthelp, func.reqglevel)) + lines.append(HelpLine(func.cmd[0], func.syntax, func.shorthelp, func.reqglevel)) +# bot.slowmsg(user, "%-40s - %-50s (%5s)" % (func.cmd[0]+' '+func.syntax, func.shorthelp, func.reqglevel)) if len(func.cmd) > 1: for c in func.cmd[1:]: - bot.slowmsg(user, "%-40s - Alias of %s" % (c, func.cmd[0])) + lines.append(HelpLine(c, "", "Alias of %s" % (func.cmd[0]), func.reqglevel)) +# bot.slowmsg(user, "%-40s - Alias of %s" % (c, func.cmd[0])) + for line in sorted(lines): + bot.slowmsg(user, str(line)) else: # help for a specific command/topic cmd = str(' '.join(args)) if cmd in cmds and user.glevel >= cmds[cmd].reqglevel: