mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-11 04:32:36 +01:00
Aka: Allow optional arguments and $* together, and also multiple instances of $*.
This commit is contained in:
parent
30596ad79c
commit
774285ef03
@ -292,17 +292,10 @@ 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):
|
||||||
for (i, token) in enumerate(tokens):
|
for (i, token) in enumerate(tokens):
|
||||||
if isinstance(token, list):
|
if isinstance(token, list):
|
||||||
@ -310,10 +303,8 @@ class Aka(callbacks.Plugin):
|
|||||||
return
|
return
|
||||||
if token == '$*':
|
if token == '$*':
|
||||||
tokens[i:i+1] = args
|
tokens[i:i+1] = args
|
||||||
return True
|
|
||||||
elif '$*' in token:
|
elif '$*' in token:
|
||||||
tokens[i] = token.replace('$*', ' '.join(args))
|
tokens[i] = token.replace('$*', ' '.join(args))
|
||||||
return True
|
|
||||||
return False
|
return False
|
||||||
everythingReplace(tokens)
|
everythingReplace(tokens)
|
||||||
self.Proxy(irc, msg, tokens)
|
self.Proxy(irc, msg, tokens)
|
||||||
@ -344,10 +335,6 @@ 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):
|
||||||
|
@ -86,7 +86,11 @@ 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.assertError('aka add foo "echo $1 @1 $*"')
|
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.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')
|
||||||
|
Loading…
Reference in New Issue
Block a user