diff --git a/CHANGES/1263.feature b/CHANGES/1263.feature new file mode 100644 index 00000000..3365bc82 --- /dev/null +++ b/CHANGES/1263.feature @@ -0,0 +1 @@ +Added support for commands starting with command prefix by automatically removing user added prefix diff --git a/aiogram/filters/command.py b/aiogram/filters/command.py index 6e654531..acaf2a04 100644 --- a/aiogram/filters/command.py +++ b/aiogram/filters/command.py @@ -89,6 +89,8 @@ class Command(Filter): ) if ignore_case and isinstance(command, str): command = command.casefold() + for individual_prefix in prefix: + command = command.lstrip(individual_prefix) items.append(command) if not items: @@ -168,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 ec79098a..54e75e36 100644 --- a/tests/test_filters/test_command.py +++ b/tests/test_filters/test_command.py @@ -38,9 +38,9 @@ class TestCommandFilter: @pytest.mark.parametrize( "commands,checklist", [ - [("Test1", "tEst2", "teSt3"), ("test1", "test2", "test3")], + [("/Test1", "tEst2", "teSt3"), ("test1", "test2", "test3")], [("12TeSt", "3t4Est", "5TE6sT"), ("12test", "3t4est", "5te6st")], - [[BotCommand(command="Test", description="Test1")], ("test",)], + [[BotCommand(command="/Test", description="Test1")], ("test",)], [[BotCommand(command="tEsT", description="Test2")], ("test",)], [(re.compile(r"test(\d+)"), "TeSt"), (re.compile(r"test(\d+)"), "test")], ],