mirror of
https://github.com/eternnoir/pyTelegramBotAPI.git
synced 2023-08-10 21:12:57 +03:00
slight TextFilter class improvement
This commit is contained in:
parent
0d85a34551
commit
ae5d183db0
@ -92,39 +92,33 @@ class TextFilter:
|
|||||||
|
|
||||||
if self.ignore_case:
|
if self.ignore_case:
|
||||||
text = text.lower()
|
text = text.lower()
|
||||||
|
prepare_func = lambda string: str(string).lower()
|
||||||
if self.equals:
|
else:
|
||||||
self.equals = self.equals.lower()
|
prepare_func = str
|
||||||
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:
|
if self.equals:
|
||||||
result = self.equals == text
|
result = prepare_func(self.equals) == text
|
||||||
if result:
|
if result:
|
||||||
return True
|
return True
|
||||||
elif not result and not any((self.contains, self.starts_with, self.ends_with)):
|
elif not result and not any((self.contains, self.starts_with, self.ends_with)):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if self.contains:
|
if self.contains:
|
||||||
result = any([i in text for i in self.contains])
|
result = any([prepare_func(i) in text for i in self.contains])
|
||||||
if result:
|
if result:
|
||||||
return True
|
return True
|
||||||
elif not result and not any((self.starts_with, self.ends_with)):
|
elif not result and not any((self.starts_with, self.ends_with)):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if self.starts_with:
|
if self.starts_with:
|
||||||
result = any([text.startswith(i) for i in self.starts_with])
|
result = any([text.startswith(prepare_func(i)) for i in self.starts_with])
|
||||||
if result:
|
if result:
|
||||||
return True
|
return True
|
||||||
elif not result and not self.ends_with:
|
elif not result and not self.ends_with:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if self.ends_with:
|
if self.ends_with:
|
||||||
return any([text.endswith(i) for i in self.ends_with])
|
return any([text.endswith(prepare_func(i)) for i in self.ends_with])
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user