aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Leon Sandøy <[email protected]>2020-07-29 15:03:15 +0200
committerGravatar Leon Sandøy <[email protected]>2020-07-29 15:03:15 +0200
commit4e1609695762524bc707b6a8d39e88c2710cff6b (patch)
treedc2acfa36cf8ef7af1ce9de13483fb8ee503b013
parentMake a helper for validating guild invites. (diff)
Refactor filtering: use non-compiled expressions.
-rw-r--r--bot/cogs/filtering.py16
1 files changed, 6 insertions, 10 deletions
diff --git a/bot/cogs/filtering.py b/bot/cogs/filtering.py
index 9f9bcc464..7787d396d 100644
--- a/bot/cogs/filtering.py
+++ b/bot/cogs/filtering.py
@@ -99,14 +99,10 @@ class Filtering(Cog):
self.bot.loop.create_task(self.reschedule_offensive_msg_deletion())
- def _get_filterlist_items(self, list_type: str, *, allowed: bool, compiled: Optional[bool] = False) -> list:
+ def _get_filterlist_items(self, list_type: str, *, allowed: bool) -> list:
"""Fetch items from the filter_list_cache."""
items = self.bot.filter_list_cache[f"{list_type.upper()}.{allowed}"]
-
- if compiled:
- return [re.compile(fr'{item["content"]}', flags=re.IGNORECASE) for item in items]
- else:
- return [item["content"] for item in items]
+ return [item["content"] for item in items]
@staticmethod
def _expand_spoilers(text: str) -> str:
@@ -143,9 +139,9 @@ class Filtering(Cog):
def get_name_matches(self, name: str) -> List[re.Match]:
"""Check bad words from passed string (name). Return list of matches."""
matches = []
- watchlist_patterns = self._get_filterlist_items('word_watchlist', allowed=False, compiled=True)
+ watchlist_patterns = self._get_filterlist_items('word_watchlist', allowed=False)
for pattern in watchlist_patterns:
- if match := pattern.search(name):
+ if match := re.search(pattern, name, flags=re.IGNORECASE):
matches.append(match)
return matches
@@ -408,9 +404,9 @@ class Filtering(Cog):
if URL_RE.search(text):
return False
- watchlist_patterns = self._get_filterlist_items('word_watchlist', allowed=False, compiled=True)
+ watchlist_patterns = self._get_filterlist_items('word_watchlist', allowed=False)
for pattern in watchlist_patterns:
- match = pattern.search(text)
+ match = re.search(pattern, text, flags=re.IGNORECASE)
if match:
return match