From 51f7ec9d05b1e93a6a6138cecec6aabd504d5eb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=90=91=E5=A4=9C?= Date: Tue, 5 Mar 2024 15:19:42 +0800 Subject: [PATCH] fix(dicer): fix dicer check when empty matches --- src/diceutils/dicer.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/diceutils/dicer.py b/src/diceutils/dicer.py index 883f7f9..03ea7bb 100644 --- a/src/diceutils/dicer.py +++ b/src/diceutils/dicer.py @@ -259,13 +259,16 @@ def check(roll_string: str): matches: List[str] = re.findall(r"\d*[a-zA-Z]\w*|\d+|[-+*/()]", roll_string) patterns = [r"\d*[dD]\d*", r"\d*[bB]\d+", r"\d*[pP]\d+", r"\d+"] + if not matches: + return False + for match in matches: if match not in "-+*/()" and not any( [re.match(pattern, match) for pattern in patterns] ): return False - - return True + else: + return True def roll(self): self.parse(roll_string=self.roll_string, explode=self.explode)