3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-12-25 20:22:45 +01:00

ServiceBot: fill in 'help' and 'list' commands (#216)

This commit is contained in:
James Lu 2016-05-14 12:22:00 -07:00
parent 9236f7e095
commit 5b3059c85d

View File

@ -226,7 +226,36 @@ class ServiceBot():
return func return func
def help(self, irc, source, args): def help(self, irc, source, args):
self.reply(irc, "Help command stub called.") """<command>
Gives help for <command>, if it is available."""
try:
command = args[0].lower()
except IndexError: # No argument given, just return 'list' output
self.listcommands(irc, source, args)
return
if command not in self.commands:
self.reply(irc, 'Error: Unknown command %r.' % command)
return
else:
funcs = self.commands[command]
if len(funcs) > 1:
self.reply(irc, 'The following \x02%s\x02 plugins bind to the \x02%s\x02 command: %s'
% (len(funcs), command, ', '.join([func.__module__ for func in funcs])))
for func in funcs:
doc = func.__doc__
mod = func.__module__
if doc:
lines = doc.split('\n')
# Bold the first line, which usually just tells you what
# arguments the command takes.
lines[0] = '\x02%s %s\x02' % (command, lines[0])
for line in lines:
# Then, just output the rest of the docstring to IRC.
self.reply(irc, line.strip())
else:
self.reply(irc, "Error: Command %r doesn't offer any help." % command)
return
def request(self, irc, source, args): def request(self, irc, source, args):
self.reply(irc, "Request command stub called.") self.reply(irc, "Request command stub called.")
@ -235,7 +264,14 @@ class ServiceBot():
self.reply(irc, "Remove command stub called.") self.reply(irc, "Remove command stub called.")
def listcommands(self, irc, source, args): def listcommands(self, irc, source, args):
self.reply(irc, "List command stub called.") """takes no arguments.
Returns a list of available commands this service has to offer."""
cmds = list(self.commands.keys())
cmds.sort()
self.reply(irc, 'Available commands include: %s' % ', '.join(cmds))
self.reply(irc, 'To see help on a specific command, type \x02help <command>\x02.')
def registerService(name, *args, **kwargs): def registerService(name, *args, **kwargs):
name = name.lower() name = name.lower()