added help text to the Help module

This commit is contained in:
Mike Bloy 2011-01-08 22:47:51 -06:00
parent fdd059ddbc
commit 07d3775842

View File

@ -36,7 +36,8 @@ class Help(Module):
self.helpre = re.compile('^!help(\s+(\S+)(\s+(.+))?)?\s*$') self.helpre = re.compile('^!help(\s+(\S+)(\s+(.+))?)?\s*$')
def do(self, connection, event, nick, userhost, what, admin_unlocked): def do(self, connection, event, nick, userhost, what, admin_unlocked):
"""look for karma strings at the start of messages""" """look for !help and subcommands,
and dispatch for further processing"""
match = self.helpre.search(what) match = self.helpre.search(what)
if match: if match:
@ -49,6 +50,7 @@ class Help(Module):
return self.handle_help_detail(module, key) return self.handle_help_detail(module, key)
def handle_help_descriptions(self): def handle_help_descriptions(self):
"""print the general help"""
message = "General Help:\n" message = "General Help:\n"
for module in self.irc.modlist: for module in self.irc.modlist:
description = module.help_description() description = module.help_description()
@ -58,6 +60,7 @@ class Help(Module):
return message return message
def handle_help_module(self, modname): def handle_help_module(self, modname):
"""handle the module level help processing"""
module = self.find_module(modname) module = self.find_module(modname)
if module: if module:
helptext = module.help_summary() helptext = module.help_summary()
@ -69,6 +72,7 @@ class Help(Module):
return "no module named '%s' is loaded" % (modname) return "no module named '%s' is loaded" % (modname)
def handle_help_detail(self, modname, key): def handle_help_detail(self, modname, key):
"""handle the help detail message"""
module = self.find_module(modname) module = self.find_module(modname)
if module: if module:
helptext = module.help_detail(key) helptext = module.help_detail(key)
@ -82,11 +86,36 @@ class Help(Module):
return "asked for help on module %s detail %s" % (modname, key) return "asked for help on module %s detail %s" % (modname, key)
def find_module(self, modname): def find_module(self, modname):
"""find a module in the server's list of loaded modules"""
for module in self.irc.modlist: for module in self.irc.modlist:
if modname == module.__class__.__name__: if modname == module.__class__.__name__:
return module return module
return None return None
def help_description(self):
"""Return a quick list of commands or other summary, should be
less than two lines. If you want the module hidden from "!help",
return None here"""
return "Display module and command help"
def help_summary(self):
"""Return a command summary or longer description of this module.
If this returns None, the summary will be
"no help available for module foo"
"""
return """!help [module [detail]]
type '!help Help module' or '!help Help detail' for more information"""
def help_detail(self, command):
"""Return detailed help for the given command. Return None if there
is no suitable help available"""
if command == 'module':
return """get a summary of a module's commands or function"""
elif command == 'detail':
return """get information on a specific module-defined detail"""
else:
return None
if __name__ == "__main__": if __name__ == "__main__":
print "Hello World" print "Hello World"