Fix duplicated commands in Message.command

Also add more test cases
Related to #676
This commit is contained in:
Dan 2021-05-06 19:20:12 +02:00
parent 4fc4501445
commit 636ff776d6
2 changed files with 9 additions and 1 deletions

View File

@ -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

View File

@ -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")