From 2f8ed139803f6f251b5de42564ad60e4ccbcb30c Mon Sep 17 00:00:00 2001 From: Shubham Patel Date: Thu, 12 Oct 2023 21:40:55 +0530 Subject: [PATCH] update fix #206 --- aiogram/filters/command.py | 19 +++++-------------- tests/test_filters/test_command.py | 2 +- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/aiogram/filters/command.py b/aiogram/filters/command.py index d5fcef27..acaf2a04 100644 --- a/aiogram/filters/command.py +++ b/aiogram/filters/command.py @@ -78,17 +78,6 @@ class Command(Filter): " or their Iterable" ) - prefixes = [] - for char in prefix: - if char not in prefixes: - prefixes.append(char) - - operations = { - BotCommand: lambda cmd, prefix: cmd.command.lstrip(prefix), - re.Pattern: lambda cmd, prefix: re.compile(cmd.pattern.lstrip(prefix)), - str: lambda cmd, prefix: cmd.lstrip(prefix), - } - items = [] for command in (*values, *commands): if isinstance(command, BotCommand): @@ -100,9 +89,8 @@ class Command(Filter): ) if ignore_case and isinstance(command, str): command = command.casefold() - for individual_prefix in prefixes: - if isinstance(command, (str, BotCommand, re.Pattern)): - command = operations[type(command)](command, individual_prefix) + for individual_prefix in prefix: + command = command.lstrip(individual_prefix) items.append(command) if not items: @@ -182,6 +170,9 @@ class Command(Filter): return replace(command, regexp_match=result) command_name = command.command + for individual_prefix in self.prefix: + command_name = command.command.replace(individual_prefix, '', 1) + if self.ignore_case: command_name = command_name.casefold() diff --git a/tests/test_filters/test_command.py b/tests/test_filters/test_command.py index 85acf8f4..54e75e36 100644 --- a/tests/test_filters/test_command.py +++ b/tests/test_filters/test_command.py @@ -42,7 +42,7 @@ class TestCommandFilter: [("12TeSt", "3t4Est", "5TE6sT"), ("12test", "3t4est", "5te6st")], [[BotCommand(command="/Test", description="Test1")], ("test",)], [[BotCommand(command="tEsT", description="Test2")], ("test",)], - [(re.compile(r"/test(\d+)"), "TeSt"), (re.compile(r"test(\d+)"), "test")], + [(re.compile(r"test(\d+)"), "TeSt"), (re.compile(r"test(\d+)"), "test")], ], ) def test_init_casefold(self, commands, checklist):