mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-24 02:54:05 +01:00
Aka: Allow more than one in an aka. Closes GH-1283.
This commit is contained in:
parent
5452d4194a
commit
3075a41a3b
@ -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):
|
||||
|
@ -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')
|
||||
|
Loading…
Reference in New Issue
Block a user