From 02a3969101729f8a34b26e4fcc315eac7ed63095 Mon Sep 17 00:00:00 2001 From: Alisson Lauffer Date: Tue, 14 Sep 2021 13:33:54 -0300 Subject: [PATCH] Fix Message.command when case is different (#757) * Fix Message.command when case is different * Update test_command.py Co-authored-by: Dan <14043624+delivrance@users.noreply.github.com> --- pyrogram/filters.py | 3 ++- tests/filters/test_command.py | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/pyrogram/filters.py b/pyrogram/filters.py index d969026b..b6d27087 100644 --- a/pyrogram/filters.py +++ b/pyrogram/filters.py @@ -794,7 +794,8 @@ 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, + flags=re.IGNORECASE if not flt.case_sensitive else 0) # 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 d9a7490e..19e21d9d 100644 --- a/tests/filters/test_command.py +++ b/tests/filters/test_command.py @@ -107,6 +107,10 @@ async def test_with_args(): await f(c, m) assert m.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"]