Added a listCommands method to PrivmsgRegexp, to allow plugins to list their own commands.

This commit is contained in:
Jeremy Fincher 2005-02-04 20:08:38 +00:00
parent 4125f97381
commit fdddefe129
2 changed files with 22 additions and 21 deletions

View File

@ -125,28 +125,13 @@ class Misc(callbacks.Privmsg):
else:
irc.reply('There are no public plugins.')
else:
if isinstance(cb, callbacks.PrivmsgRegexp) or \
not isinstance(cb, callbacks.Privmsg):
irc.error('That plugin exists, but it has no commands. '
'You may wish to check if it has any useful '
'configuration variables with the command '
'"config list supybot.plugins.%s".' % cb.name())
commands = cb.listCommands()
if commands:
commands.sort()
irc.reply(format('%L', commands))
else:
name = callbacks.canonicalName(cb.name())
commands = []
for s in dir(cb):
if cb.isCommand(s) and \
(s != name or cb._original) and \
s == callbacks.canonicalName(s):
method = getattr(cb, s)
if hasattr(method, '__doc__') and method.__doc__:
commands.append(s)
if commands:
commands.sort()
irc.reply(format('%L', commands))
else:
irc.error('That plugin exists, but it has no '
'commands with help.')
irc.error('That plugin exists, but it has no '
'commands with help.')
list = wrap(list, [getopts({'private':''}), additional('plugin')])
def apropos(self, irc, msg, args, s):

View File

@ -1115,6 +1115,19 @@ class Privmsg(irclib.IrcCallback):
assert self.isCommand(name), format('%s is not a command.', name)
return getattr(self, name)
def listCommands(self):
commands = []
name = canonicalName(self.name())
for s in dir(self):
if self.isCommand(s) and \
(s != name or self._original) and \
s == canonicalName(s):
method = getattr(self, s)
if hasattr(method, '__doc__') and method.__doc__:
commands.append(s)
commands.sort()
return commands
def callCommand(self, name, irc, msg, *L, **kwargs):
checkCapabilities = kwargs.pop('checkCapabilities', True)
if checkCapabilities:
@ -1283,6 +1296,9 @@ class PrivmsgRegexp(Privmsg):
value.__doc__, e)
utils.gen.sortBy(operator.itemgetter(1), self.res)
def isCommand(self):
return []
def callCommand(self, name, irc, msg, *L, **kwargs):
try:
self.__parent.callCommand(name, irc, msg, *L, **kwargs)