aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar MarkKoz <[email protected]>2020-08-27 12:26:27 -0700
committerGravatar MarkKoz <[email protected]>2020-08-27 12:26:27 -0700
commit30cbde7a7c48e59a19b5a7f1934d0e7674473d62 (patch)
tree3ff1dd2eb936cdbd35daa105f43366e1ab762a38
parentMerge pull request #1124 from python-discord/feat/backend/707/alias-decorator (diff)
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
-rw-r--r--bot/rules/discord_emojis.py4
1 files changed, 3 insertions, 1 deletions
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
)