fix(bot): 🐛 Censorship tagging normal words with different safe meaning but bad words in them.
This commit is contained in:
@@ -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)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user