mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-02 07:34:08 +01:00
Fixed bug with nested plugins having the same name as themselves.
This commit is contained in:
parent
52fabfdaf7
commit
0e68a44513
@ -1020,33 +1020,31 @@ class Commands(BasePlugin):
|
||||
return self.getCommand(command) == command
|
||||
|
||||
def getCommand(self, args):
|
||||
assert args == map(canonicalName, args)
|
||||
first = args[0]
|
||||
if len(args) >= 2 and first == self.canonicalName():
|
||||
command = self.getCommand(args[1:])
|
||||
if command:
|
||||
command.insert(0, first)
|
||||
return command
|
||||
for cb in self.cbs:
|
||||
if first == cb.canonicalName():
|
||||
command = cb.getCommand(args[1:])
|
||||
if command:
|
||||
command.insert(0, first)
|
||||
return command
|
||||
return cb.getCommand(args)
|
||||
if self.isCommandMethod(first):
|
||||
return [first]
|
||||
elif first == self.canonicalName():
|
||||
ret = self.getCommand(args[1:])
|
||||
if ret:
|
||||
return [first] + ret
|
||||
return []
|
||||
|
||||
def getCommandMethod(self, command):
|
||||
"""Gets the given command from this plugin."""
|
||||
#print '*** %s.getCommandMethod(%r)' % (self.name(), command)
|
||||
assert not isinstance(command, basestring)
|
||||
assert command == map(canonicalName, command)
|
||||
assert self.getCommand(command) == command
|
||||
if len(command) > 1:
|
||||
if command[0] == self.canonicalName():
|
||||
return self.getCommandMethod(command[1:])
|
||||
for cb in self.cbs:
|
||||
if command[0] == cb.canonicalName():
|
||||
return cb.getCommandMethod(command)
|
||||
if len(command) > 1:
|
||||
assert command[0] == self.canonicalName()
|
||||
return self.getCommandMethod(command[1:])
|
||||
else:
|
||||
return getattr(self, command[0])
|
||||
|
||||
@ -1058,6 +1056,9 @@ class Commands(BasePlugin):
|
||||
for cb in self.cbs:
|
||||
name = cb.canonicalName()
|
||||
for command in cb.listCommands():
|
||||
if command == name:
|
||||
commands.append(command)
|
||||
else:
|
||||
commands.append(' '.join([name, command]))
|
||||
commands.sort()
|
||||
return commands
|
||||
|
@ -544,11 +544,13 @@ class SourceNestedPluginTestCase(PluginTestCase):
|
||||
self.assertHelp('help f')
|
||||
self.assertHelp('help e g h')
|
||||
self.assertHelp('help e g i j')
|
||||
self.assertRegexp('list e', 'f, g h, and g i j')
|
||||
self.assertRegexp('list e', 'f, g h, g i j, and same')
|
||||
|
||||
def testCommandSameNameAsNestedPlugin(self):
|
||||
cb = self.E(self.irc)
|
||||
self.irc.addCallback(cb)
|
||||
self.assertResponse('e f', 'f') # Just to make sure it was loaded.
|
||||
self.assertEqual(cb.getCommand(['e', 'same']), ['e', 'same'])
|
||||
self.assertResponse('e same', 'same')
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user