mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-13 04:01:05 +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
|
return self.getCommand(command) == command
|
||||||
|
|
||||||
def getCommand(self, args):
|
def getCommand(self, args):
|
||||||
|
assert args == map(canonicalName, args)
|
||||||
first = args[0]
|
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:
|
for cb in self.cbs:
|
||||||
if first == cb.canonicalName():
|
if first == cb.canonicalName():
|
||||||
command = cb.getCommand(args[1:])
|
return cb.getCommand(args)
|
||||||
if command:
|
|
||||||
command.insert(0, first)
|
|
||||||
return command
|
|
||||||
if self.isCommandMethod(first):
|
if self.isCommandMethod(first):
|
||||||
return [first]
|
return [first]
|
||||||
|
elif first == self.canonicalName():
|
||||||
|
ret = self.getCommand(args[1:])
|
||||||
|
if ret:
|
||||||
|
return [first] + ret
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def getCommandMethod(self, command):
|
def getCommandMethod(self, command):
|
||||||
"""Gets the given command from this plugin."""
|
"""Gets the given command from this plugin."""
|
||||||
|
#print '*** %s.getCommandMethod(%r)' % (self.name(), command)
|
||||||
assert not isinstance(command, basestring)
|
assert not isinstance(command, basestring)
|
||||||
assert command == map(canonicalName, command)
|
assert command == map(canonicalName, command)
|
||||||
assert self.getCommand(command) == 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:
|
for cb in self.cbs:
|
||||||
if command[0] == cb.canonicalName():
|
if command[0] == cb.canonicalName():
|
||||||
return cb.getCommandMethod(command)
|
return cb.getCommandMethod(command)
|
||||||
|
if len(command) > 1:
|
||||||
|
assert command[0] == self.canonicalName()
|
||||||
|
return self.getCommandMethod(command[1:])
|
||||||
else:
|
else:
|
||||||
return getattr(self, command[0])
|
return getattr(self, command[0])
|
||||||
|
|
||||||
@ -1058,6 +1056,9 @@ class Commands(BasePlugin):
|
|||||||
for cb in self.cbs:
|
for cb in self.cbs:
|
||||||
name = cb.canonicalName()
|
name = cb.canonicalName()
|
||||||
for command in cb.listCommands():
|
for command in cb.listCommands():
|
||||||
|
if command == name:
|
||||||
|
commands.append(command)
|
||||||
|
else:
|
||||||
commands.append(' '.join([name, command]))
|
commands.append(' '.join([name, command]))
|
||||||
commands.sort()
|
commands.sort()
|
||||||
return commands
|
return commands
|
||||||
|
@ -544,11 +544,13 @@ class SourceNestedPluginTestCase(PluginTestCase):
|
|||||||
self.assertHelp('help f')
|
self.assertHelp('help f')
|
||||||
self.assertHelp('help e g h')
|
self.assertHelp('help e g h')
|
||||||
self.assertHelp('help e g i j')
|
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):
|
def testCommandSameNameAsNestedPlugin(self):
|
||||||
cb = self.E(self.irc)
|
cb = self.E(self.irc)
|
||||||
self.irc.addCallback(cb)
|
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')
|
self.assertResponse('e same', 'same')
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user