Revert "Aka: Allow optional arguments and $* together, and also multiple instances of $*."

This reverts commit 774285ef03.

Conflicts:
	plugins/Aka/plugin.py
This commit is contained in:
Valentin Lorentz 2013-12-23 17:41:33 +01:00
parent 4a20270655
commit 764c788aa6
2 changed files with 20 additions and 14 deletions

View File

@ -312,10 +312,17 @@ class Aka(callbacks.Plugin):
else: else:
tokens[i] = replacer(token) tokens[i] = replacer(token)
replace(tokens, lambda s: dollarRe.sub(regexpReplace, s)) replace(tokens, lambda s: dollarRe.sub(regexpReplace, s))
args = args[biggestDollar:]
if biggestAt: if biggestAt:
assert not wildcard
args = args[biggestDollar:]
replace(tokens, lambda s: atRe.sub(regexpReplace, s)) replace(tokens, lambda s: atRe.sub(regexpReplace, s))
if wildcard: 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): def everythingReplace(tokens):
ret = False ret = False
new_tokens = [] new_tokens = []
@ -326,14 +333,13 @@ class Aka(callbacks.Plugin):
if sub_ret: if sub_ret:
continue continue
if token == '$*': if token == '$*':
new_tokens.extend(args) tokens[i:i+1] = args
ret = True return True
else: elif '$*' in token:
new_tokens.append( tokens[i] = token.replace('$*', ' '.join(args))
token.replace('$*', ' '.join(args))) return True
ret = True return False
return (ret, new_tokens) everythingReplace(tokens)
(ret, 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:
irc.error(_('You\'ve attempted more nesting than is ' irc.error(_('You\'ve attempted more nesting than is '
@ -366,6 +372,10 @@ class Aka(callbacks.Plugin):
biggestDollar = findBiggestDollar(alias) biggestDollar = findBiggestDollar(alias)
biggestAt = findBiggestAt(alias) biggestAt = findBiggestAt(alias)
wildcard = '$*' in 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) self._db.add_aka(channel, name, alias)
def _remove_aka(self, channel, name, evenIfLocked=False): def _remove_aka(self, channel, name, evenIfLocked=False):

View File

@ -87,11 +87,7 @@ class AkaChannelTestCase(ChannelPluginTestCase):
def testAllArgs(self): def testAllArgs(self):
self.assertNotError('aka add swap "echo $2 $1 $*"') self.assertNotError('aka add swap "echo $2 $1 $*"')
self.assertResponse('swap 1 2 3 4 5', '2 1 3 4 5') self.assertResponse('swap 1 2 3 4 5', '2 1 3 4 5')
self.assertNotError('aka add foo "echo $1 @1 $*"') self.assertError('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.assertNotError('aka add moo echo $1 $*')
self.assertError('moo') self.assertError('moo')
self.assertResponse('moo foo', 'foo') self.assertResponse('moo foo', 'foo')