del cmds[cmd]
del helps[func]
+class HelpLine(object):
+ def __init__(self, cmd, syntax, shorthelp, admin, level, module):
+ self.cmd = cmd
+ self.syntax = syntax
+ self.shorthelp = shorthelp
+ self.admin = admin
+ self.level = level
+ self.module = module
+
+ 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.admin:
+ return "%-35s(%3s) - %-10s - %-50s" % (self.cmd+' '+self.syntax, self.level, self.module, self.shorthelp)
+ else:
+ return "%-40s - %-50s" % (self.cmd+' '+self.syntax, self.shorthelp)
+
@lib.hook(needchan=False)
@lib.help('[<command>]', 'lists commands or describes a command')
def help(bot, user, chan, realtarget, *args):
- if len(args) == 0:
+ 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))
- 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, (user.glevel > 0), func.reqglevel, func.__module__))
if len(func.cmd) > 1:
for c in func.cmd[1:]:
- bot.slowmsg(user, "%-40s - Alias of %s" % (c, func.cmd[0]))
- else:
+ lines.append(HelpLine(c, "", "Alias of %s" % (func.cmd[0]), (user.glevel > 0), func.reqglevel, func.__module__))
+ for line in sorted(lines):
+ bot.slowmsg(user, str(line))
+ bot.slowmsg(user, "End of command listing.")
+ else: # help for a specific command/topic
cmd = str(' '.join(args))
if cmd in cmds and user.glevel >= cmds[cmd].reqglevel:
func = cmds[cmd]
- if func.reqglevel <= 0:
- 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))
+ bot.slowmsg(user, str(HelpLine(func.cmd[0], func.syntax, func.shorthelp, (user.glevel > 0), func.reqglevel, func.__module__)))
for line in func.longhelps:
bot.slowmsg(user, " %s" % (line))
+ bot.slowmsg(user, "End of help for %s." % (func.cmd[0]))
if len(func.cmd) > 1:
bot.slowmsg(user, " Aliases: %s" % (' '.join(func.cmd[1:])))