Fix bug that caused commands like '@google google google google translate' to be valid. Closes GH-19.

This commit is contained in:
Valentin Lorentz 2013-08-10 15:22:47 +02:00
parent c23f25545f
commit 1ee8bc3480
2 changed files with 6 additions and 3 deletions

View File

@ -1190,14 +1190,15 @@ class Commands(BasePlugin):
assert isinstance(command, list) assert isinstance(command, list)
return self.getCommand(command) == command return self.getCommand(command) == command
def getCommand(self, args): def getCommand(self, args, stripOwnName=True):
assert args == map(canonicalName, args) assert args == map(canonicalName, args)
first = args[0] first = args[0]
for cb in self.cbs: for cb in self.cbs:
if first == cb.canonicalName(): if first == cb.canonicalName():
return cb.getCommand(args) return cb.getCommand(args)
if first == self.canonicalName() and len(args) > 1: if first == self.canonicalName() and len(args) > 1 and \
ret = self.getCommand(args[1:]) stripOwnName:
ret = self.getCommand(args[1:], stripOwnName=False)
if ret: if ret:
return [first] + ret return [first] + ret
if self.isCommandMethod(first): if self.isCommandMethod(first):

View File

@ -433,6 +433,8 @@ class PrivmsgTestCase(ChannelPluginTestCase):
self.assertResponse('secondcmd', 'bar') self.assertResponse('secondcmd', 'bar')
self.assertResponse('first firstcmd', 'foo') self.assertResponse('first firstcmd', 'foo')
self.assertResponse('second secondcmd', 'bar') self.assertResponse('second secondcmd', 'bar')
self.assertRegexp('first first firstcmd',
'there is no command named "first" in it')
def testAmbiguousError(self): def testAmbiguousError(self):
self.irc.addCallback(self.First(self.irc)) self.irc.addCallback(self.First(self.irc))