From 774285ef0338bafac33565216225f3a0c20ee167 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Wed, 24 Jul 2013 13:14:25 +0200 Subject: [PATCH] Aka: Allow optional arguments and $* together, and also multiple instances of $*. --- plugins/Aka/plugin.py | 15 +-------------- plugins/Aka/test.py | 6 +++++- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/plugins/Aka/plugin.py b/plugins/Aka/plugin.py index a09d2036a..bdcfb17ac 100644 --- a/plugins/Aka/plugin.py +++ b/plugins/Aka/plugin.py @@ -292,17 +292,10 @@ class Aka(callbacks.Plugin): else: tokens[i] = replacer(token) replace(tokens, lambda s: dollarRe.sub(regexpReplace, s)) + args = args[biggestDollar:] if biggestAt: - assert not wildcard - args = args[biggestDollar:] replace(tokens, lambda s: atRe.sub(regexpReplace, s)) if wildcard: - assert not biggestAt - # Gotta remove the things that have already been subbed in. - i = biggestDollar - while i: - args.pop(0) - i -= 1 def everythingReplace(tokens): for (i, token) in enumerate(tokens): if isinstance(token, list): @@ -310,10 +303,8 @@ class Aka(callbacks.Plugin): return if token == '$*': tokens[i:i+1] = args - return True elif '$*' in token: tokens[i] = token.replace('$*', ' '.join(args)) - return True return False everythingReplace(tokens) self.Proxy(irc, msg, tokens) @@ -344,10 +335,6 @@ class Aka(callbacks.Plugin): biggestDollar = findBiggestDollar(alias) biggestAt = findBiggestAt(alias) wildcard = '$*' in alias - if biggestAt and wildcard: - raise AkaError(_('Can\'t mix $* and optional args (@1, etc.)')) - if alias.count('$*') > 1: - raise AkaError(_('There can be only one $* in an alias.')) self._db.add_aka(channel, name, alias) def _remove_aka(self, channel, name, evenIfLocked=False): diff --git a/plugins/Aka/test.py b/plugins/Aka/test.py index 831b2dc5f..1b4dbec0d 100644 --- a/plugins/Aka/test.py +++ b/plugins/Aka/test.py @@ -86,7 +86,11 @@ class AkaChannelTestCase(ChannelPluginTestCase): def testAllArgs(self): self.assertNotError('aka add swap "echo $2 $1 $*"') self.assertResponse('swap 1 2 3 4 5', '2 1 3 4 5') - self.assertError('aka add foo "echo $1 @1 $*"') + self.assertNotError('aka add foo "echo $1 @1 $*"') + self.assertResponse('foo bar baz qux', 'bar baz baz qux') + self.assertNotError('aka remove foo') + self.assertNotError('aka add foo "echo $* $2 $*"') + self.assertResponse('foo bar baz qux quux', 'qux quux baz qux quux') self.assertNotError('aka add moo echo $1 $*') self.assertError('moo') self.assertResponse('moo foo', 'foo')