From 49a7a29dc3883791080b9a7c56d189fb720179e8 Mon Sep 17 00:00:00 2001 From: ajax146 <31014239+ajax146@users.noreply.github.com> Date: Sun, 21 Jul 2024 18:12:07 -0400 Subject: [PATCH 1/3] Add automatic rejections to modmail to block threads from being created --- techsupport_bot/commands/modmail.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/techsupport_bot/commands/modmail.py b/techsupport_bot/commands/modmail.py index 1d7d28785..238e118bb 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,14 @@ 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=f"This message cannot be used to start a 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 +851,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 +927,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 From 23dd7f22352526888d0b34ba4e2b66a49902ea49 Mon Sep 17 00:00:00 2001 From: ajax146 <31014239+ajax146@users.noreply.github.com> Date: Sun, 21 Jul 2024 18:15:10 -0400 Subject: [PATCH 2/3] Formatting --- techsupport_bot/commands/modmail.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/techsupport_bot/commands/modmail.py b/techsupport_bot/commands/modmail.py index 238e118bb..2b4fc716a 100644 --- a/techsupport_bot/commands/modmail.py +++ b/techsupport_bot/commands/modmail.py @@ -348,7 +348,8 @@ async def handle_dm(message: discord.Message) -> None: for regex in AUTOMATIC_REJECTIONS: if re.match(regex, message.content): await auxiliary.send_deny_embed( - message=f"This message cannot be used to start a thread: {AUTOMATIC_REJECTIONS[regex]}", + message=f"This message cannot be used to start a " + + "thread: {AUTOMATIC_REJECTIONS[regex]}", channel=message.channel, ) return From 18557a2f7340c046da8afeeb4252eae2d3721287 Mon Sep 17 00:00:00 2001 From: ajax146 <31014239+ajax146@users.noreply.github.com> Date: Sun, 21 Jul 2024 18:21:17 -0400 Subject: [PATCH 3/3] Formatting 2 --- techsupport_bot/commands/modmail.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/techsupport_bot/commands/modmail.py b/techsupport_bot/commands/modmail.py index 2b4fc716a..a162d2538 100644 --- a/techsupport_bot/commands/modmail.py +++ b/techsupport_bot/commands/modmail.py @@ -348,8 +348,8 @@ async def handle_dm(message: discord.Message) -> None: for regex in AUTOMATIC_REJECTIONS: if re.match(regex, message.content): await auxiliary.send_deny_embed( - message=f"This message cannot be used to start a " - + "thread: {AUTOMATIC_REJECTIONS[regex]}", + message="This message cannot be used to start a " + + f"thread: {AUTOMATIC_REJECTIONS[regex]}", channel=message.channel, ) return