From 636ff776d61a5823be88d75621f4e9c3b6fe9c55 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 6 May 2021 19:20:12 +0200 Subject: [PATCH] Fix duplicated commands in Message.command Also add more test cases Related to #676 --- pyrogram/filters.py | 2 +- tests/filters/test_command.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/pyrogram/filters.py b/pyrogram/filters.py index 4a07413d..9a1b2bdd 100644 --- a/pyrogram/filters.py +++ b/pyrogram/filters.py @@ -789,7 +789,7 @@ def command(commands: Union[str, List[str]], prefixes: Union[str, List[str]] = " flags=re.IGNORECASE if not flt.case_sensitive else 0): continue - without_command = re.sub(rf"{cmd}(?:@?{username})?\s", "", without_prefix, count=1) + without_command = re.sub(rf"{cmd}(?:@?{username})?\s?", "", without_prefix, count=1) # match.groups are 1-indexed, group(1) is the quote, group(2) is the text # between the quotes, group(3) is unquoted, whitespace-split text diff --git a/tests/filters/test_command.py b/tests/filters/test_command.py index 0cd00e95..d9a7490e 100644 --- a/tests/filters/test_command.py +++ b/tests/filters/test_command.py @@ -103,6 +103,14 @@ async def test_with_mention(): async def test_with_args(): f = filters.command("start") + m = Message("/start") + await f(c, m) + assert m.command == ["start"] + + m = Message("/start@username") + await f(c, m) + assert m.command == ["start"] + m = Message("/start a b c") await f(c, m) assert m.command == ["start"] + list("abc")