diff options
| -rw-r--r-- | bot/cogs/filtering.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/bot/cogs/filtering.py b/bot/cogs/filtering.py index 74538542a..38c28dd00 100644 --- a/bot/cogs/filtering.py +++ b/bot/cogs/filtering.py @@ -27,6 +27,7 @@ INVITE_RE = re.compile( flags=re.IGNORECASE ) +SPOILER_RE = re.compile(r"(\|\|.+?\|\|)", re.DOTALL) URL_RE = re.compile(r"(https?://[^\s]+)", flags=re.IGNORECASE) ZALGO_RE = re.compile(r"[\u0300-\u036F\u0489]") @@ -38,6 +39,14 @@ TOKEN_WATCHLIST_PATTERNS = [ ] +def expand_spoilers(text: str) -> str: + """Return a string containing all interpretations of a spoilered message.""" + split_text = SPOILER_RE.split(text) + return ''.join( + split_text[0::2] + split_text[1::2] + split_text + ) + + class Filtering(Cog): """Filtering out invites, blacklisting domains, and warning us of certain regular expressions.""" @@ -244,6 +253,8 @@ class Filtering(Cog): Only matches words with boundaries before and after the expression. """ + if SPOILER_RE.search(text): + text = expand_spoilers(text) for regex_pattern in WORD_WATCHLIST_PATTERNS: match = regex_pattern.search(text) if match: |