Fixed improper whitelisting
This commit is contained in:
@@ -105,6 +105,8 @@ async def _violent_worker(data: dict) -> None:
|
|||||||
if is_text_forbidden(res[i].message.lower(), blacklist, whitelist):
|
if is_text_forbidden(res[i].message.lower(), blacklist, whitelist):
|
||||||
messages_to_delete.append(res[i].id)
|
messages_to_delete.append(res[i].id)
|
||||||
continue
|
continue
|
||||||
|
if is_text_whitelisted(res[i].message.lower(), whitelist):
|
||||||
|
continue
|
||||||
# names are not to be checked
|
# names are not to be checked
|
||||||
if not data['check_names']:
|
if not data['check_names']:
|
||||||
continue
|
continue
|
||||||
@@ -115,6 +117,8 @@ async def _violent_worker(data: dict) -> None:
|
|||||||
if name:
|
if name:
|
||||||
if sender.last_name is not None:
|
if sender.last_name is not None:
|
||||||
name += ' ' + sender.last_name
|
name += ' ' + sender.last_name
|
||||||
|
if is_text_whitelisted(name.lower(), whitelist):
|
||||||
|
continue
|
||||||
if is_text_forbidden(name.lower(), blacklist, whitelist):
|
if is_text_forbidden(name.lower(), blacklist, whitelist):
|
||||||
messages_to_delete.append(res[i].id)
|
messages_to_delete.append(res[i].id)
|
||||||
continue
|
continue
|
||||||
@@ -137,6 +141,8 @@ async def _violent_worker(data: dict) -> None:
|
|||||||
if name_to_check:
|
if name_to_check:
|
||||||
if sender.last_name is not None:
|
if sender.last_name is not None:
|
||||||
name_to_check += ' ' + sender.last_name
|
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):
|
if name_to_check is not None and is_text_forbidden(name_to_check.lower(), blacklist, whitelist):
|
||||||
messages_to_delete.append(res[i].id)
|
messages_to_delete.append(res[i].id)
|
||||||
continue
|
continue
|
||||||
@@ -213,18 +219,29 @@ def mod_get_config_for_session(session_name) -> dict:
|
|||||||
_mod_config[session_name] = c
|
_mod_config[session_name] = c
|
||||||
return 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:
|
def is_text_forbidden(text, blacklist, whitelist) -> bool:
|
||||||
''' Returns True or False '''
|
''' Returns True or False '''
|
||||||
# check if has blacklisted content
|
# check if has blacklisted content
|
||||||
for word in blacklist:
|
for word in blacklist:
|
||||||
if word in text:
|
if word in text.lower():
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
# check if has whitelisted content
|
# check if has whitelisted content
|
||||||
for word in whitelist:
|
for word in whitelist:
|
||||||
# whitelisted content exists
|
# whitelisted content exists
|
||||||
if word in text:
|
if word in text.lower():
|
||||||
return False
|
return False
|
||||||
# forbidden
|
# forbidden
|
||||||
return True
|
return True
|
||||||
|
|||||||
Reference in New Issue
Block a user