From b19a2ea4872093bebefdc69f56363f0655813020 Mon Sep 17 00:00:00 2001 From: ikkemaniac Date: Sun, 5 Jan 2025 18:42:29 +0100 Subject: [PATCH 1/2] fix: raise ValueError if arg is required but empty string. fixes #154 and #216 --- maubot/handlers/command.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maubot/handlers/command.py b/maubot/handlers/command.py index 27e6547..3f37bb9 100644 --- a/maubot/handlers/command.py +++ b/maubot/handlers/command.py @@ -173,7 +173,7 @@ class CommandHandler: remaining_val, call_args[arg.name] = arg.match( remaining_val.strip(), evt=evt, instance=self.__bound_instance__ ) - if arg.required and call_args[arg.name] is None: + if arg.required and (call_args[arg.name] is None or call_args[arg.name] == ""): raise ValueError("Argument required") except ArgumentSyntaxError as e: await evt.reply(e.message + (f"\n{self.__mb_usage__}" if e.show_usage else "")) From ae77f3763957993cf8445fdd3eacfa6223c4fb3d Mon Sep 17 00:00:00 2001 From: ikkemaniac Date: Sun, 5 Jan 2025 18:48:01 +0100 Subject: [PATCH 2/2] fix: return correct no. of vars. (remaining_val missing). Fixes arg issues with custom arguments. --- maubot/handlers/command.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maubot/handlers/command.py b/maubot/handlers/command.py index 3f37bb9..8068bbc 100644 --- a/maubot/handlers/command.py +++ b/maubot/handlers/command.py @@ -392,7 +392,7 @@ class CustomArgument(Argument): def match(self, val: str, **kwargs) -> Tuple[str, Any]: if self.pass_raw: - return self.matcher(val) + return "", self.matcher(val) orig_val = val val = re.split(r"\s", val, 1)[0] res = self.matcher(val)