diff --git a/techsupport_bot/commands/modmail.py b/techsupport_bot/commands/modmail.py index 1d7d28785..a162d2538 100644 --- a/techsupport_bot/commands/modmail.py +++ b/techsupport_bot/commands/modmail.py @@ -229,6 +229,7 @@ async def on_member_join(self: Self, member: discord.Member) -> None: MODMAIL_FORUM_ID = None MODMAIL_LOG_CHANNEL_ID = None AUTOMATIC_RESPONSES = None +AUTOMATIC_REJECTIONS = None ROLES_TO_PING = None THREAD_CREATION_MESSAGE = None @@ -344,6 +345,15 @@ async def handle_dm(message: discord.Message) -> None: # - No thread was found, create one - + for regex in AUTOMATIC_REJECTIONS: + if re.match(regex, message.content): + await auxiliary.send_deny_embed( + message="This message cannot be used to start a " + + f"thread: {AUTOMATIC_REJECTIONS[regex]}", + channel=message.channel, + ) + return + if message.author.id in awaiting_confirmation: await auxiliary.send_deny_embed( message="Please respond to the existing prompt before trying to open a new modmail" @@ -842,6 +852,14 @@ async def setup(bot: bot.TechSupportBot) -> None: default={}, ) + config.add( + key="automatic_rejections", + datatype="dict", + title="Modmail auto-rejections", + description="If someone sends a message matching regex, blocks thread creation", + default={}, + ) + config.add( key="modmail_roles", datatype="list", @@ -910,6 +928,10 @@ def __init__(self: Self, bot: bot.TechSupportBot) -> None: global AUTOMATIC_RESPONSES AUTOMATIC_RESPONSES = config.extensions.modmail.automatic_responses.value + # pylint: disable=W0603 + global AUTOMATIC_REJECTIONS + AUTOMATIC_REJECTIONS = config.extensions.modmail.automatic_rejections.value + # pylint: disable=W0603 global ROLES_TO_PING # dict.fromkeys() to deduplicate the list