aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar MarkKoz <[email protected]>2021-04-09 18:52:01 -0700
committerGravatar MarkKoz <[email protected]>2021-04-09 19:48:46 -0700
commitb38e645a66b76693ebc0cf0febc63187ab7a8b2f (patch)
treebcc759b4699934a9d048cfe1f8ee6a4f06be03f2
parentMerge pull request #1511 from onerandomusername/defcon-voice-shutdown (diff)
AntiSpam: prevent attempts to punish a user multiple times
A user may manage to send multiple message that violate filters before the mute is applied. Because of a race condition, subsequent punish attempts did not detect the mute role exists and therefore proceeded to apply another mute. To avoid the race condition, abort any subsequent punish attempts while one is already ongoing for a given user. It could be possible to wait instead of abort, but the first attempt failing very likely means subsequent attempts would fail too. Fixes #902
-rw-r--r--bot/exts/filters/antispam.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/bot/exts/filters/antispam.py b/bot/exts/filters/antispam.py
index af8528a68..c9052b138 100644
--- a/bot/exts/filters/antispam.py
+++ b/bot/exts/filters/antispam.py
@@ -3,7 +3,7 @@ import logging
from collections.abc import Mapping
from dataclasses import dataclass, field
from datetime import datetime, timedelta
-from operator import itemgetter
+from operator import attrgetter, itemgetter
from typing import Dict, Iterable, List, Set
from discord import Colour, Member, Message, NotFound, Object, TextChannel
@@ -18,6 +18,7 @@ from bot.constants import (
)
from bot.converters import Duration
from bot.exts.moderation.modlog import ModLog
+from bot.utils import lock
from bot.utils.messages import format_user, send_attachments
@@ -211,6 +212,7 @@ class AntiSpam(Cog):
await self.maybe_delete_messages(channel, relevant_messages)
break
+ @lock.lock_arg("antispam.punish", "member", attrgetter("id"))
async def punish(self, msg: Message, member: Member, reason: str) -> None:
"""Punishes the given member for triggering an antispam rule."""
if not any(role.id == self.muted_role.id for role in member.roles):