Skip to content

Commit

Permalink
Merge pull request #135 from aahnik/solve-issue-93
Browse files Browse the repository at this point in the history
case insensitive filtering by default
  • Loading branch information
aahnik authored May 8, 2021
2 parents 5faa24f + b8a2f0b commit 8c116a8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
18 changes: 17 additions & 1 deletion plugins/tgcf_filter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ class FilesFilterList(BaseModel):
blacklist: Optional[List[FileType]] = []
whitelist: Optional[List[FileType]] = []

class TextFilter(FilterList):
case_sensitive: Optional[bool] = False

class Filters(BaseModel):
users: Optional[FilterList] = FilterList()
files: Optional[FilesFilterList] = FilesFilterList()
text: Optional[FilterList] = FilterList()
text: Optional[TextFilter] = TextFilter()


class TgcfFilter:
Expand All @@ -39,8 +41,16 @@ class TgcfFilter:
def __init__(self, data):
print("tgcf filter data loaded")
self.filters = Filters(**data)
self.case_correct()
logging.info(self.filters)

def case_correct(self):
textf:TextFilter = self.filters.text

if textf.case_sensitive is False:
textf.blacklist = [item.lower() for item in textf.blacklist]
textf.whitelist = [item.lower() for item in textf.whitelist]

def modify(self, message):

if self.users_safe(message):
Expand All @@ -50,9 +60,15 @@ def modify(self, message):

def text_safe(self, message):
flist = self.filters.text


text = message.text
if not flist.case_sensitive:
text = text.lower()
if not text and flist.whitelist == []:
return True


for forbidden in flist.blacklist:
if forbidden in text:
return False
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "tgcf"
version = "0.1.28"
version = "0.1.29"
description = "The ultimate tool to automate telegram message forwarding."
authors = ["aahnik <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit 8c116a8

Please sign in to comment.