aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Jeremiah Boby <[email protected]>2019-11-28 10:28:52 +0000
committerGravatar Jeremiah Boby <[email protected]>2019-11-28 10:28:52 +0000
commitdef24f55c81865e1a7a8d93e0de7562a7abb556a (patch)
tree2db35307c465594e1e3afc7e72fe33c7c0e274bd
parentUpdate spoiler regex to support multi-line spoilers (diff)
Expand spoilers to match multiple interpretations
-rw-r--r--bot/cogs/filtering.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/bot/cogs/filtering.py b/bot/cogs/filtering.py
index fd90ff836..f1651b4d0 100644
--- a/bot/cogs/filtering.py
+++ b/bot/cogs/filtering.py
@@ -38,6 +38,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."""
@@ -237,8 +245,10 @@ 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:
- if regex_pattern.search(text + SPOILER_RE.sub('', text)):
+ if regex_pattern.search(text):
return True
return False