From 3075a41a3b906ed89a8dfb12cdfe2a481439fac5 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Mon, 17 Apr 2017 10:53:26 +0200 Subject: [PATCH] Aka: Allow more than one in an aka. Closes GH-1283. --- plugins/Aka/plugin.py | 17 ++++++++++------- plugins/Aka/test.py | 10 ++++++++-- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/plugins/Aka/plugin.py b/plugins/Aka/plugin.py index 0d02dded1..f1273d717 100644 --- a/plugins/Aka/plugin.py +++ b/plugins/Aka/plugin.py @@ -470,17 +470,19 @@ class Aka(callbacks.Plugin): i = biggestDollar args[:] = args[i:] def everythingReplace(tokens): + skip = 0 for (i, token) in enumerate(tokens): + if skip: + skip -= 1 + continue if isinstance(token, list): - if everythingReplace(token): - return + everythingReplace(token) if token == '$*': tokens[i:i+1] = args - return True + skip = len(args)-1 # do not make replacements in + # tokens we just added elif '$*' in token: tokens[i] = token.replace('$*', ' '.join(args)) - return True - return False everythingReplace(tokens) maxNesting = conf.supybot.commands.nested.maximum() if maxNesting and irc.nested+1 > maxNesting: @@ -518,8 +520,9 @@ class Aka(callbacks.Plugin): 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.')) + if alias.count('$*') > 3: + # mitigate huge expansions + raise AkaError(_('There can be only three $* 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 2dac1d8e8..50b3580bc 100644 --- a/plugins/Aka/test.py +++ b/plugins/Aka/test.py @@ -104,6 +104,10 @@ class AkaChannelTestCase(ChannelPluginTestCase): self.assertResponse('spam egg', 'egg') self.assertResponse('spam egg bacon', 'egg bacon') + self.assertNotError('aka add doublespam "echo [echo $* $*]"') + self.assertResponse('doublespam egg', 'egg egg') + self.assertResponse('doublespam egg bacon', 'egg bacon egg bacon') + def testChannel(self): self.assertNotError('aka add channel echo $channel') self.assertResponse('aka channel', self.channel) @@ -179,8 +183,10 @@ class AkaChannelTestCase(ChannelPluginTestCase): self.assertRegexp('fact 50', 'more nesting') def testDollarStarNesting(self): - self.assertNotError('aka add alias aka $*') - self.assertNotError('alias add a+ aka add $*') + self.assertResponse('aka add alias aka $*', 'The operation succeeded.') + self.assertResponse('alias add a+ aka add $*', 'The operation succeeded.') + self.assertResponse('a+ spam echo egg', 'The operation succeeded.') + self.assertResponse('spam', 'egg') class AkaTestCase(PluginTestCase): plugins = ('Aka', 'Alias', 'User', 'Utilities')