From 0a1a3551a208b31a4972b7ba02a94569ee78dc0c Mon Sep 17 00:00:00 2001 From: jesopo Date: Mon, 30 Sep 2019 10:15:12 +0100 Subject: [PATCH] support "$-" for alias arg, meaning "0 or more args" --- modules/commands/__init__.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/modules/commands/__init__.py b/modules/commands/__init__.py index 1a3587b0..7c1d8ff5 100644 --- a/modules/commands/__init__.py +++ b/modules/commands/__init__.py @@ -8,7 +8,7 @@ from . import outs COMMAND_METHOD = "command-method" COMMAND_METHODS = ["PRIVMSG", "NOTICE"] -REGEX_ARG_NUMBER = re.compile(r"\$(\d+)(-?)") +REGEX_ARG_NUMBER = re.compile(r"\$(?:(\d+)(-?)|(-))") MESSAGE_TAGS_CAP = utils.irc.Capability("message-tags", "draft/message-tags-0.2") @@ -66,14 +66,18 @@ class Module(ModuleManager.BaseModule): def _alias_arg_replace(self, s, args_split): for match in REGEX_ARG_NUMBER.finditer(s): - index = int(match.group(1)) - continuous = match.group(2) == "-" + if match.group(1): + index = int(match.group(1)) + continuous = match.group(2) == "-" + else: + index = -1 + continuous = True if index >= len(args_split): raise IndexError("Unknown alias arg index") if continuous: - replace = " ".join(args_split[index:]) + replace = " ".join(args_split[min(index, 0):]) else: replace = args_split[index] s = s.replace(match.group(0), replace)