Fixed improper whitelisting

This commit is contained in:
Nikita Tyukalov, ASUS, Linux
2025-11-25 05:03:43 +03:00
parent 27bfc18c1f
commit 99a5786112

View File

@@ -105,6 +105,8 @@ async def _violent_worker(data: dict) -> None:
if is_text_forbidden(res[i].message.lower(), blacklist, whitelist):
messages_to_delete.append(res[i].id)
continue
if is_text_whitelisted(res[i].message.lower(), whitelist):
continue
# names are not to be checked
if not data['check_names']:
continue
@@ -115,6 +117,8 @@ async def _violent_worker(data: dict) -> None:
if name:
if sender.last_name is not None:
name += ' ' + sender.last_name
if is_text_whitelisted(name.lower(), whitelist):
continue
if is_text_forbidden(name.lower(), blacklist, whitelist):
messages_to_delete.append(res[i].id)
continue
@@ -137,6 +141,8 @@ async def _violent_worker(data: dict) -> None:
if name_to_check:
if sender.last_name is not None:
name_to_check += ' ' + sender.last_name
if name_to_check is not None and is_text_whitelisted(name.lower(), whitelist):
continue
if name_to_check is not None and is_text_forbidden(name_to_check.lower(), blacklist, whitelist):
messages_to_delete.append(res[i].id)
continue
@@ -213,18 +219,29 @@ def mod_get_config_for_session(session_name) -> dict:
_mod_config[session_name] = c
return c
def is_text_whitelisted(text, whitelist) -> bool:
''' Returns True if text contains something from whitelist '''
# check if has whitelisted content
for word in whitelist:
# whitelisted content exists
if word in text.lower():
return True
# forbidden
return False
def is_text_forbidden(text, blacklist, whitelist) -> bool:
''' Returns True or False '''
# check if has blacklisted content
for word in blacklist:
if word in text:
if word in text.lower():
break
else:
return False
# check if has whitelisted content
for word in whitelist:
# whitelisted content exists
if word in text:
if word in text.lower():
return False
# forbidden
return True