Skip to content

Commit 93b0270

Browse files
committed
Confirm thread creation when user opens a thread using react to contact.
1 parent baa7e5f commit 93b0270

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

cogs/modmail.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,12 @@ async def contact(
10271027
await ctx.channel.send(embed=embed, delete_after=3)
10281028

10291029
else:
1030-
thread = await self.bot.threads.create(user, creator=ctx.author, category=category)
1030+
thread = await self.bot.threads.create(
1031+
recipient=user,
1032+
creator=ctx.author,
1033+
category=category,
1034+
manual_trigger=manual_trigger,
1035+
)
10311036
if self.bot.config["dm_disabled"] in (DMDisabled.NEW_THREADS, DMDisabled.ALL_THREADS):
10321037
logger.info("Contacting user %s when Modmail DM is disabled.", user)
10331038

core/thread.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -1175,6 +1175,7 @@ async def create(
11751175
message: discord.Message = None,
11761176
creator: typing.Union[discord.Member, discord.User] = None,
11771177
category: discord.CategoryChannel = None,
1178+
manual_trigger: bool = True,
11781179
) -> Thread:
11791180
"""Creates a Modmail thread"""
11801181

@@ -1215,8 +1216,12 @@ async def create(
12151216
self.bot.config.set("fallback_category_id", category.id)
12161217
await self.bot.config.update()
12171218

1218-
if message and self.bot.config["confirm_thread_creation"]:
1219-
confirm = await message.channel.send(
1219+
if (message or not manual_trigger) and self.bot.config["confirm_thread_creation"]:
1220+
if not manual_trigger:
1221+
destination = recipient
1222+
else:
1223+
destination = message.channel
1224+
confirm = await destination.send(
12201225
embed=discord.Embed(
12211226
title=self.bot.config["confirm_thread_creation_title"],
12221227
description=self.bot.config["confirm_thread_response"],
@@ -1231,7 +1236,7 @@ async def create(
12311236
try:
12321237
r, _ = await self.bot.wait_for(
12331238
"reaction_add",
1234-
check=lambda r, u: u.id == message.author.id
1239+
check=lambda r, u: u.id == recipient.id
12351240
and r.message.id == confirm.id
12361241
and r.message.channel.id == confirm.channel.id
12371242
and str(r.emoji) in (accept_emoji, deny_emoji),
@@ -1243,7 +1248,7 @@ async def create(
12431248
await confirm.remove_reaction(accept_emoji, self.bot.user)
12441249
await asyncio.sleep(0.2)
12451250
await confirm.remove_reaction(deny_emoji, self.bot.user)
1246-
await message.channel.send(
1251+
await destination.send(
12471252
embed=discord.Embed(
12481253
title="Cancelled", description="Timed out", color=self.bot.error_color
12491254
)
@@ -1257,7 +1262,7 @@ async def create(
12571262
await confirm.remove_reaction(accept_emoji, self.bot.user)
12581263
await asyncio.sleep(0.2)
12591264
await confirm.remove_reaction(deny_emoji, self.bot.user)
1260-
await message.channel.send(
1265+
await destination.send(
12611266
embed=discord.Embed(title="Cancelled", color=self.bot.error_color)
12621267
)
12631268
del self.cache[recipient.id]

0 commit comments

Comments
 (0)