diff --git a/payphone/core/censorship.py b/payphone/core/censorship.py index 39be68d..6db4307 100644 --- a/payphone/core/censorship.py +++ b/payphone/core/censorship.py @@ -29,7 +29,7 @@ def create_pattern(text: str) -> str: for r in replacements: text = text.replace(r[0], f"({r[1]})") - return f"({text})" + return f"(?:{text})" 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) 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. """ - match = next(PATTERN.finditer(message), None) - - if match is not None: - return message[match.start() : match.end()] + for word in WORDS.finditer(message): + word = message[word.start() : word.end()] + if PATTERN.match(word): + return word match = next(URL_PATTERN.finditer(message), None)