Skip to content

Commit 636ff77

Browse files
committed
Fix duplicated commands in Message.command
Also add more test cases Related to #676
1 parent 4fc4501 commit 636ff77

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

pyrogram/filters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ async def func(flt, client: pyrogram.Client, message: Message):
789789
flags=re.IGNORECASE if not flt.case_sensitive else 0):
790790
continue
791791

792-
without_command = re.sub(rf"{cmd}(?:@?{username})?\s", "", without_prefix, count=1)
792+
without_command = re.sub(rf"{cmd}(?:@?{username})?\s?", "", without_prefix, count=1)
793793

794794
# match.groups are 1-indexed, group(1) is the quote, group(2) is the text
795795
# between the quotes, group(3) is unquoted, whitespace-split text

tests/filters/test_command.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,14 @@ async def test_with_mention():
103103
async def test_with_args():
104104
f = filters.command("start")
105105

106+
m = Message("/start")
107+
await f(c, m)
108+
assert m.command == ["start"]
109+
110+
m = Message("/start@username")
111+
await f(c, m)
112+
assert m.command == ["start"]
113+
106114
m = Message("/start a b c")
107115
await f(c, m)
108116
assert m.command == ["start"] + list("abc")

0 commit comments

Comments
 (0)