mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-24 19:52:54 +01:00
Added a listCommands method to PrivmsgRegexp, to allow plugins to list their own commands.
This commit is contained in:
parent
4125f97381
commit
fdddefe129
@ -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):
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user