From bd002c6429613e22a8a85278f06749272fab7a6c Mon Sep 17 00:00:00 2001 From: Badiboy Date: Sun, 24 Apr 2022 11:28:20 +0300 Subject: [PATCH] i18n middleware - file revert --- telebot/custom_filters.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/telebot/custom_filters.py b/telebot/custom_filters.py index 21a079a..1bd80b3 100644 --- a/telebot/custom_filters.py +++ b/telebot/custom_filters.py @@ -69,7 +69,7 @@ class TextFilter: self.ends_with = self._check_iterable(ends_with, filter_name='ends_with') self.ignore_case = ignore_case - def _check_iterable(self, iterable, filter_name): + def _check_iterable(self, iterable, filter_name: str): if not iterable: pass elif not isinstance(iterable, str) and not isinstance(iterable, list) and not isinstance(iterable, tuple): @@ -95,33 +95,39 @@ class TextFilter: if self.ignore_case: text = text.lower() - prepare_func = lambda string: str(string).lower() - else: - prepare_func = str + + if self.equals: + self.equals = self.equals.lower() + elif self.contains: + self.contains = tuple(map(str.lower, self.contains)) + elif self.starts_with: + self.starts_with = tuple(map(str.lower, self.starts_with)) + elif self.ends_with: + self.ends_with = tuple(map(str.lower, self.ends_with)) if self.equals: - result = prepare_func(self.equals) == text + result = self.equals == text if result: return True elif not result and not any((self.contains, self.starts_with, self.ends_with)): return False if self.contains: - result = any([prepare_func(i) in text for i in self.contains]) + result = any([i in text for i in self.contains]) if result: return True elif not result and not any((self.starts_with, self.ends_with)): return False if self.starts_with: - result = any([text.startswith(prepare_func(i)) for i in self.starts_with]) + result = any([text.startswith(i) for i in self.starts_with]) if result: return True elif not result and not self.ends_with: return False if self.ends_with: - return any([text.endswith(prepare_func(i)) for i in self.ends_with]) + return any([text.endswith(i) for i in self.ends_with]) return False