support "$$" as a literal "$" in alias arg replacements

This commit is contained in:
jesopo 2019-11-20 18:23:57 +00:00
parent 6e005f1569
commit 352df0fa75

View file

@ -7,22 +7,24 @@ SETTING_PREFIX = "command-alias-"
class Module(ModuleManager.BaseModule): class Module(ModuleManager.BaseModule):
def _arg_replace(self, s, args_split): def _arg_replace(self, s, args_split):
for match in REGEX_ARG_NUMBER.finditer(s): parts = s.split("$$")
if match.group(1): for i, part in enumerate(parts):
index = int(match.group(1)) for match in REGEX_ARG_NUMBER.finditer(s):
continuous = match.group(2) == "-" if match.group(1):
if index >= len(args_split): index = int(match.group(1))
raise IndexError("Unknown alias arg index") continuous = match.group(2) == "-"
else: if index >= len(args_split):
index = 0 raise IndexError("Unknown alias arg index")
continuous = True else:
index = 0
continuous = True
if continuous: if continuous:
replace = " ".join(args_split[index:]) replace = " ".join(args_split[index:])
else: else:
replace = args_split[index] replace = args_split[index]
s = s.replace(match.group(0), replace) parts[i] = part.replace(match.group(0), replace)
return s return "$".join(parts)
def _get_alias(self, server, target, command): def _get_alias(self, server, target, command):
setting = "%s%s" % (SETTING_PREFIX, command) setting = "%s%s" % (SETTING_PREFIX, command)