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:
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):
ret = False
new_tokens = []
@ -326,14 +333,13 @@ class Aka(callbacks.Plugin):
if sub_ret:
continue
if token == '$*':
new_tokens.extend(args)
ret = True
else:
new_tokens.append(
token.replace('$*', ' '.join(args)))
ret = True
return (ret, new_tokens)
(ret, tokens) = everythingReplace(tokens)
tokens[i:i+1] = args
return True
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:
irc.error(_('You\'ve attempted more nesting than is '
@ -366,6 +372,10 @@ 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):

View File

@ -87,11 +87,7 @@ 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.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.assertError('aka add foo "echo $1 @1 $*"')
self.assertNotError('aka add moo echo $1 $*')
self.assertError('moo')
self.assertResponse('moo foo', 'foo')