3
0
mirror of https://github.com/jlu5/PyLink.git synced 2025-02-02 15:44:06 +01:00

ServiceBot: implement short form help for featured command lists

Suggestion from @cooper.
This commit is contained in:
James Lu 2016-06-30 18:52:35 -07:00
parent 91a663d5c7
commit d2b5fd7b6e

View File

@ -255,7 +255,7 @@ class ServiceBot():
self.commands[name].append(func) self.commands[name].append(func)
return func return func
def _show_command_help(self, irc, command, private=False): def _show_command_help(self, irc, command, private=False, shortform=False):
""" """
Shows help for the given command. Shows help for the given command.
""" """
@ -281,9 +281,13 @@ class ServiceBot():
# Bold the first line, which usually just tells you what # Bold the first line, which usually just tells you what
# arguments the command takes. # arguments the command takes.
lines[0] = '\x02%s %s\x02' % (command, lines[0]) lines[0] = '\x02%s %s\x02' % (command, lines[0])
for line in lines:
# Then, just output the rest of the docstring to IRC. if shortform: # Short form is just the command name + args.
_reply(line.strip()) _reply(lines[0].strip())
else:
for line in lines:
# Otherwise, just output the rest of the docstring to IRC.
_reply(line.strip())
else: else:
_reply("Error: Command %r doesn't offer any help." % command) _reply("Error: Command %r doesn't offer any help." % command)
return return
@ -336,8 +340,7 @@ class ServiceBot():
# Only show featured commands that are both defined and loaded. # Only show featured commands that are both defined and loaded.
# TODO: perhaps plugin unload should remove unused featured command # TODO: perhaps plugin unload should remove unused featured command
# definitions automatically? # definitions automatically?
self.reply(irc, " ", private=True) self._show_command_help(irc, cmd, private=True, shortform=True)
self._show_command_help(irc, cmd, private=True)
def registerService(name, *args, **kwargs): def registerService(name, *args, **kwargs):
"""Registers a service bot.""" """Registers a service bot."""