From fd14a38546445fcf97c6bd486d846a5c56a79659 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sun, 21 Oct 2018 21:57:34 +0300 Subject: [PATCH] Make command arguments map optional and fix optional command arguments --- maubot/command_spec.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/maubot/command_spec.py b/maubot/command_spec.py index a2102da..f5136ce 100644 --- a/maubot/command_spec.py +++ b/maubot/command_spec.py @@ -31,7 +31,7 @@ class Argument(SerializableAttrs['Argument']): @dataclass class Command(SerializableAttrs['Command']): syntax: str - arguments: Dict[str, Argument] + arguments: Dict[str, Argument] = {} description: str = None @@ -80,7 +80,9 @@ class ParsedCommand: arg = command.arguments.get(word, None) if arg is not None and len(word) > 0: argument_encountered = True - regex = f"({arg.matches})" if arg.required else f"(?:{arg.matches})?" + regex = f"({arg.matches})" + if not arg.required: + regex += "?" self.arguments.append(word) regex_builder.append(regex) else: