mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
update fix #206
This commit is contained in:
parent
8741515cb5
commit
2f8ed13980
2 changed files with 6 additions and 15 deletions
|
|
@ -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()
|
||||
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue