fix(bot): 🐛 Censorship tagging normal words with different safe meaning but bad words in them.

This commit is contained in:
Nyeki.py
2024-10-18 01:28:10 -03:00
parent 5213515387
commit f265e12cb4
+7 -6
View File
@@ -29,7 +29,7 @@ def create_pattern(text: str) -> str:
for r in replacements: for r in replacements:
text = text.replace(r[0], f"({r[1]})") text = text.replace(r[0], f"({r[1]})")
return f"({text})" return f"(?:{text})"
BLOCKED_WORDS = [ BLOCKED_WORDS = [
@@ -228,7 +228,8 @@ BLOCKED_WORDS = [
] ]
] ]
PATTERN = re.compile("|".join(BLOCKED_WORDS), re.IGNORECASE) WORDS = re.compile(r"\w+")
PATTERN = re.compile(f"^({"|".join(BLOCKED_WORDS)})$", re.IGNORECASE)
URL_PATTERN = re.compile(r"https?://[^\s]+", re.IGNORECASE) URL_PATTERN = re.compile(r"https?://[^\s]+", re.IGNORECASE)
INVITES_PATTERN = re.compile(r"discord.gg/[^\s]+", re.IGNORECASE) INVITES_PATTERN = re.compile(r"discord.gg/[^\s]+", re.IGNORECASE)
@@ -243,10 +244,10 @@ def moderate(message: str) -> str:
str | None: The blocked pattern found as it was found. str | None: The blocked pattern found as it was found.
""" """
match = next(PATTERN.finditer(message), None) for word in WORDS.finditer(message):
word = message[word.start() : word.end()]
if match is not None: if PATTERN.match(word):
return message[match.start() : match.end()] return word
match = next(URL_PATTERN.finditer(message), None) match = next(URL_PATTERN.finditer(message), None)