This commit is contained in:
Shubham Patel 2023-10-12 21:40:55 +05:30
parent 8741515cb5
commit 2f8ed13980
2 changed files with 6 additions and 15 deletions

View file

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

View file

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