From 30cbde7a7c48e59a19b5a7f1934d0e7674473d62 Mon Sep 17 00:00:00 2001 From: MarkKoz Date: Thu, 27 Aug 2020 12:26:27 -0700 Subject: AntiSpam: ignore custom emojis in code blocks In code blocks, custom emojis render as text rather than as images. Therefore, they probably aren't being spammed and should be ignored. Fix #1130 --- bot/rules/discord_emojis.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bot/rules/discord_emojis.py b/bot/rules/discord_emojis.py index 5bab514f2..6e47f0197 100644 --- a/bot/rules/discord_emojis.py +++ b/bot/rules/discord_emojis.py @@ -5,6 +5,7 @@ from discord import Member, Message DISCORD_EMOJI_RE = re.compile(r"<:\w+:\d+>") +CODE_BLOCK_RE = re.compile(r"```.*?```", flags=re.DOTALL) async def apply( @@ -17,8 +18,9 @@ async def apply( if msg.author == last_message.author ) + # Get rid of code blocks in the message before searching for emojis. total_emojis = sum( - len(DISCORD_EMOJI_RE.findall(msg.content)) + len(DISCORD_EMOJI_RE.findall(CODE_BLOCK_RE.sub("", msg.content))) for msg in relevant_messages ) -- cgit v1.2.3