diff options
author | 2023-04-06 20:12:03 +0300 | |
---|---|---|
committer | 2023-04-06 20:12:03 +0300 | |
commit | 5cb296f2a0cb78afc597c70d7b321dbd0daf558f (patch) | |
tree | d91ca28750459ca03a74e027f0ffbc9c61c3653c | |
parent | Merge pull request #2390 from python-discord/new-filters (diff) | |
parent | Use the right variables in antispam (diff) |
Merge pull request #2514 from python-discord/fix_filters
Use the right variables in antispam
-rw-r--r-- | bot/exts/filtering/_filters/antispam/chars.py | 2 | ||||
-rw-r--r-- | bot/exts/filtering/_filters/antispam/emoji.py | 2 | ||||
-rw-r--r-- | bot/exts/filtering/_filters/antispam/links.py | 2 | ||||
-rw-r--r-- | bot/exts/filtering/_filters/antispam/mentions.py | 2 | ||||
-rw-r--r-- | bot/exts/filtering/_filters/antispam/newlines.py | 2 | ||||
-rw-r--r-- | bot/exts/filtering/_filters/antispam/role_mentions.py | 2 |
6 files changed, 6 insertions, 6 deletions
diff --git a/bot/exts/filtering/_filters/antispam/chars.py b/bot/exts/filtering/_filters/antispam/chars.py index 5c4fa201c..1b28b781c 100644 --- a/bot/exts/filtering/_filters/antispam/chars.py +++ b/bot/exts/filtering/_filters/antispam/chars.py @@ -34,7 +34,7 @@ class CharsFilter(UniqueFilter): relevant_messages = list(takewhile(lambda msg: msg.created_at > earliest_relevant_at, ctx.content)) detected_messages = {msg for msg in relevant_messages if msg.author == ctx.author} - total_recent_chars = sum(len(msg.content) for msg in relevant_messages) + total_recent_chars = sum(len(msg.content) for msg in detected_messages) if total_recent_chars > self.extra_fields.threshold: ctx.related_messages |= detected_messages diff --git a/bot/exts/filtering/_filters/antispam/emoji.py b/bot/exts/filtering/_filters/antispam/emoji.py index 0511e4a7b..b3bc63c1d 100644 --- a/bot/exts/filtering/_filters/antispam/emoji.py +++ b/bot/exts/filtering/_filters/antispam/emoji.py @@ -43,7 +43,7 @@ class EmojiFilter(UniqueFilter): # Convert Unicode emojis to :emoji: format to get their count. total_emojis = sum( len(DISCORD_EMOJI_RE.findall(demojize(CODE_BLOCK_RE.sub("", msg.content)))) - for msg in relevant_messages + for msg in detected_messages ) if total_emojis > self.extra_fields.threshold: diff --git a/bot/exts/filtering/_filters/antispam/links.py b/bot/exts/filtering/_filters/antispam/links.py index 76fe53e70..ca6e9d031 100644 --- a/bot/exts/filtering/_filters/antispam/links.py +++ b/bot/exts/filtering/_filters/antispam/links.py @@ -39,7 +39,7 @@ class DuplicatesFilter(UniqueFilter): total_links = 0 messages_with_links = 0 - for msg in relevant_messages: + for msg in detected_messages: total_matches = len(LINK_RE.findall(msg.content)) if total_matches: messages_with_links += 1 diff --git a/bot/exts/filtering/_filters/antispam/mentions.py b/bot/exts/filtering/_filters/antispam/mentions.py index f3c945e16..eb5a5e41b 100644 --- a/bot/exts/filtering/_filters/antispam/mentions.py +++ b/bot/exts/filtering/_filters/antispam/mentions.py @@ -55,7 +55,7 @@ class DuplicatesFilter(UniqueFilter): # We would need to deal with codeblocks, escaping markdown, and any discrepancies between # our implementation and discord's Markdown parser which would cause false positives or false negatives. total_recent_mentions = 0 - for msg in relevant_messages: + for msg in detected_messages: # We check if the message is a reply, and if it is try to get the author # since we ignore mentions of a user that we're replying to reply_author = None diff --git a/bot/exts/filtering/_filters/antispam/newlines.py b/bot/exts/filtering/_filters/antispam/newlines.py index b15a35219..f3830fdd7 100644 --- a/bot/exts/filtering/_filters/antispam/newlines.py +++ b/bot/exts/filtering/_filters/antispam/newlines.py @@ -43,7 +43,7 @@ class NewlinesFilter(UniqueFilter): # Identify groups of newline characters and get group & total counts newline_counts = [] - for msg in relevant_messages: + for msg in detected_messages: newline_counts += [len(group) for group in NEWLINES.findall(msg.content)] total_recent_newlines = sum(newline_counts) # Get maximum newline group size diff --git a/bot/exts/filtering/_filters/antispam/role_mentions.py b/bot/exts/filtering/_filters/antispam/role_mentions.py index 49de642fa..151dc49be 100644 --- a/bot/exts/filtering/_filters/antispam/role_mentions.py +++ b/bot/exts/filtering/_filters/antispam/role_mentions.py @@ -33,7 +33,7 @@ class DuplicatesFilter(UniqueFilter): earliest_relevant_at = arrow.utcnow() - timedelta(seconds=self.extra_fields.interval) relevant_messages = list(takewhile(lambda msg: msg.created_at > earliest_relevant_at, ctx.content)) detected_messages = {msg for msg in relevant_messages if msg.author == ctx.author} - total_recent_mentions = sum(len(msg.role_mentions) for msg in relevant_messages) + total_recent_mentions = sum(len(msg.role_mentions) for msg in detected_messages) if total_recent_mentions > self.extra_fields.threshold: ctx.related_messages |= detected_messages |