mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-24 11:04: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
|
i = biggestDollar
|
||||||
args[:] = args[i:]
|
args[:] = args[i:]
|
||||||
def everythingReplace(tokens):
|
def everythingReplace(tokens):
|
||||||
|
skip = 0
|
||||||
for (i, token) in enumerate(tokens):
|
for (i, token) in enumerate(tokens):
|
||||||
|
if skip:
|
||||||
|
skip -= 1
|
||||||
|
continue
|
||||||
if isinstance(token, list):
|
if isinstance(token, list):
|
||||||
if everythingReplace(token):
|
everythingReplace(token)
|
||||||
return
|
|
||||||
if token == '$*':
|
if token == '$*':
|
||||||
tokens[i:i+1] = args
|
tokens[i:i+1] = args
|
||||||
return True
|
skip = len(args)-1 # do not make replacements in
|
||||||
|
# tokens we just added
|
||||||
elif '$*' in token:
|
elif '$*' in token:
|
||||||
tokens[i] = token.replace('$*', ' '.join(args))
|
tokens[i] = token.replace('$*', ' '.join(args))
|
||||||
return True
|
|
||||||
return False
|
|
||||||
everythingReplace(tokens)
|
everythingReplace(tokens)
|
||||||
maxNesting = conf.supybot.commands.nested.maximum()
|
maxNesting = conf.supybot.commands.nested.maximum()
|
||||||
if maxNesting and irc.nested+1 > maxNesting:
|
if maxNesting and irc.nested+1 > maxNesting:
|
||||||
@ -518,8 +520,9 @@ class Aka(callbacks.Plugin):
|
|||||||
wildcard = '$*' in alias
|
wildcard = '$*' in alias
|
||||||
if biggestAt and wildcard:
|
if biggestAt and wildcard:
|
||||||
raise AkaError(_('Can\'t mix $* and optional args (@1, etc.)'))
|
raise AkaError(_('Can\'t mix $* and optional args (@1, etc.)'))
|
||||||
if alias.count('$*') > 1:
|
if alias.count('$*') > 3:
|
||||||
raise AkaError(_('There can be only one $* in an alias.'))
|
# mitigate huge expansions
|
||||||
|
raise AkaError(_('There can be only three $* in an alias.'))
|
||||||
self._db.add_aka(channel, name, alias)
|
self._db.add_aka(channel, name, alias)
|
||||||
|
|
||||||
def _remove_aka(self, channel, name, evenIfLocked=False):
|
def _remove_aka(self, channel, name, evenIfLocked=False):
|
||||||
|
@ -104,6 +104,10 @@ class AkaChannelTestCase(ChannelPluginTestCase):
|
|||||||
self.assertResponse('spam egg', 'egg')
|
self.assertResponse('spam egg', 'egg')
|
||||||
self.assertResponse('spam egg bacon', 'egg bacon')
|
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):
|
def testChannel(self):
|
||||||
self.assertNotError('aka add channel echo $channel')
|
self.assertNotError('aka add channel echo $channel')
|
||||||
self.assertResponse('aka channel', self.channel)
|
self.assertResponse('aka channel', self.channel)
|
||||||
@ -179,8 +183,10 @@ class AkaChannelTestCase(ChannelPluginTestCase):
|
|||||||
self.assertRegexp('fact 50', 'more nesting')
|
self.assertRegexp('fact 50', 'more nesting')
|
||||||
|
|
||||||
def testDollarStarNesting(self):
|
def testDollarStarNesting(self):
|
||||||
self.assertNotError('aka add alias aka $*')
|
self.assertResponse('aka add alias aka $*', 'The operation succeeded.')
|
||||||
self.assertNotError('alias add a+ aka add $*')
|
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):
|
class AkaTestCase(PluginTestCase):
|
||||||
plugins = ('Aka', 'Alias', 'User', 'Utilities')
|
plugins = ('Aka', 'Alias', 'User', 'Utilities')
|
||||||
|
Loading…
Reference in New Issue
Block a user