mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 13:19:24 +01:00
Added wildcard support, as per RFE #817309
This commit is contained in:
parent
52757421e0
commit
8b7b4d97ac
@ -127,23 +127,32 @@ def makeNewAlias(name, alias):
|
|||||||
doChannel = '$channel' in alias
|
doChannel = '$channel' in alias
|
||||||
biggestDollar = findBiggestDollar(alias)
|
biggestDollar = findBiggestDollar(alias)
|
||||||
biggestAt = findBiggestAt(alias)
|
biggestAt = findBiggestAt(alias)
|
||||||
|
wildcard = '$*' in alias
|
||||||
|
if biggestAt and wildcard:
|
||||||
|
raise AliasError, 'Can\'t use $* and optional args (@1, etc.)'
|
||||||
def f(self, irc, msg, args):
|
def f(self, irc, msg, args):
|
||||||
alias_ = alias
|
alias_ = alias
|
||||||
if doChannel:
|
if doChannel:
|
||||||
channel = privmsgs.getChannel(msg, args)
|
channel = privmsgs.getChannel(msg, args)
|
||||||
alias_ = alias.replace('$channel', channel)
|
alias_ = alias.replace('$channel', channel)
|
||||||
if biggestDollar or biggestAt:
|
if not wildcard and biggestDollar or biggestAt:
|
||||||
args = privmsgs.getArgs(args, needed=biggestDollar,
|
args = privmsgs.getArgs(args, needed=biggestDollar,
|
||||||
optional=biggestAt)
|
optional=biggestAt)
|
||||||
# Gotta have a tuple.
|
# Gotta have a tuple.
|
||||||
if biggestDollar + biggestAt == 1:
|
if biggestDollar + biggestAt == 1 and not wildcard:
|
||||||
args = (args,)
|
args = (args,)
|
||||||
def replace(m):
|
def replace(m):
|
||||||
idx = int(m.group(1))
|
idx = int(m.group(1))
|
||||||
return utils.dqrepr(args[idx-1])
|
return utils.dqrepr(args[idx-1])
|
||||||
|
#debug.printf((args, alias_))
|
||||||
alias_ = dollarRe.sub(replace, alias_)
|
alias_ = dollarRe.sub(replace, alias_)
|
||||||
|
#debug.printf((args, alias_))
|
||||||
args = args[biggestDollar:]
|
args = args[biggestDollar:]
|
||||||
|
#debug.printf((args, alias_))
|
||||||
alias_ = atRe.sub(replace, alias_)
|
alias_ = atRe.sub(replace, alias_)
|
||||||
|
#debug.printf((args, alias_))
|
||||||
|
alias_ = alias_.replace('$*', ' '.join(map(utils.dqrepr, args)))
|
||||||
|
#debug.printf((args, alias_))
|
||||||
self.Proxy(irc.irc, msg, callbacks.tokenize(alias_))
|
self.Proxy(irc.irc, msg, callbacks.tokenize(alias_))
|
||||||
#f = new.function(f.func_code, f.func_globals, alias)
|
#f = new.function(f.func_code, f.func_globals, alias)
|
||||||
f.__doc__ ='<an alias, %s>\n\nAlias for %r' % \
|
f.__doc__ ='<an alias, %s>\n\nAlias for %r' % \
|
||||||
|
@ -91,6 +91,11 @@ class AliasTestCase(PluginTestCase, PluginDocumentation):
|
|||||||
self.assertNotError('alias rev "echo $3 $2 $1"')
|
self.assertNotError('alias rev "echo $3 $2 $1"')
|
||||||
self.assertResponse('rev foo bar baz', 'baz bar foo')
|
self.assertResponse('rev foo bar baz', 'baz bar foo')
|
||||||
|
|
||||||
|
def testAllArgs(self):
|
||||||
|
self.assertNotError('alias swap "echo $2 $1 $*"')
|
||||||
|
self.assertResponse('swap 1 2 3 4 5', '2 1 3 4 5')
|
||||||
|
self.assertError('alias foo "echo $1 @1 $*"')
|
||||||
|
|
||||||
def testNoRecursion(self):
|
def testNoRecursion(self):
|
||||||
self.assertError('alias rotinfinity "rot13 [rotinfinity $1]"')
|
self.assertError('alias rotinfinity "rot13 [rotinfinity $1]"')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user