Skip to content

Commit 4d65cab

Browse files
committed
Merge branch 'dev-01' of git://github.com/Jerrie-Aries/modmail into Jerrie-Aries-dev-07
2 parents ac37091 + ccc8e6f commit 4d65cab

File tree

3 files changed

+44
-8
lines changed

3 files changed

+44
-8
lines changed

bot.py

+28-2
Original file line numberDiff line numberDiff line change
@@ -1188,6 +1188,14 @@ async def handle_reaction_events(self, payload):
11881188
# the reacted message is the corresponding thread creation embed
11891189
# closing thread
11901190
return await thread.close(closer=user)
1191+
if (
1192+
message.author == self.user
1193+
and message.embeds
1194+
and self.config.get("confirm_thread_creation")
1195+
and message.embeds[0].title == self.config["confirm_thread_creation_title"]
1196+
and message.embeds[0].description == self.config["confirm_thread_response"]
1197+
):
1198+
return
11911199
if not thread.recipient.dm_channel:
11921200
await thread.recipient.create_dm()
11931201
try:
@@ -1238,15 +1246,33 @@ async def on_raw_reaction_add(self, payload):
12381246
if not member.bot:
12391247
message = await channel.fetch_message(payload.message_id)
12401248
await message.remove_reaction(payload.emoji, member)
1249+
await message.add_reaction(emoji_fmt) # bot adds as well
1250+
1251+
if self.config["dm_disabled"] in (
1252+
DMDisabled.NEW_THREADS,
1253+
DMDisabled.ALL_THREADS,
1254+
):
1255+
embed = discord.Embed(
1256+
title=self.config["disabled_new_thread_title"],
1257+
color=self.error_color,
1258+
description=self.config["disabled_new_thread_response"],
1259+
)
1260+
embed.set_footer(
1261+
text=self.config["disabled_new_thread_footer"],
1262+
icon_url=self.guild.icon_url,
1263+
)
1264+
logger.info(
1265+
"A new thread using react to contact was blocked from %s due to disabled Modmail.",
1266+
member,
1267+
)
1268+
return await member.send(embed=embed)
12411269

12421270
ctx = await self.get_context(message)
12431271
ctx.author = member
12441272
await ctx.invoke(
12451273
self.get_command("contact"), user=member, manual_trigger=False
12461274
)
12471275

1248-
await message.add_reaction(emoji_fmt) # bot adds as well
1249-
12501276
async def on_raw_reaction_remove(self, payload):
12511277
if self.config["transfer_reactions"]:
12521278
await self.handle_reaction_events(payload)

cogs/modmail.py

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

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

core/thread.py

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

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

1219-
if message and self.bot.config["confirm_thread_creation"]:
1220-
confirm = await message.channel.send(
1220+
if (message or not manual_trigger) and self.bot.config["confirm_thread_creation"]:
1221+
if not manual_trigger:
1222+
destination = recipient
1223+
else:
1224+
destination = message.channel
1225+
confirm = await destination.send(
12211226
embed=discord.Embed(
12221227
title=self.bot.config["confirm_thread_creation_title"],
12231228
description=self.bot.config["confirm_thread_response"],
@@ -1232,7 +1237,7 @@ async def create(
12321237
try:
12331238
r, _ = await self.bot.wait_for(
12341239
"reaction_add",
1235-
check=lambda r, u: u.id == message.author.id
1240+
check=lambda r, u: u.id == recipient.id
12361241
and r.message.id == confirm.id
12371242
and r.message.channel.id == confirm.channel.id
12381243
and str(r.emoji) in (accept_emoji, deny_emoji),
@@ -1244,7 +1249,7 @@ async def create(
12441249
await confirm.remove_reaction(accept_emoji, self.bot.user)
12451250
await asyncio.sleep(0.2)
12461251
await confirm.remove_reaction(deny_emoji, self.bot.user)
1247-
await message.channel.send(
1252+
await destination.send(
12481253
embed=discord.Embed(
12491254
title="Cancelled", description="Timed out", color=self.bot.error_color
12501255
)
@@ -1258,7 +1263,7 @@ async def create(
12581263
await confirm.remove_reaction(accept_emoji, self.bot.user)
12591264
await asyncio.sleep(0.2)
12601265
await confirm.remove_reaction(deny_emoji, self.bot.user)
1261-
await message.channel.send(
1266+
await destination.send(
12621267
embed=discord.Embed(title="Cancelled", color=self.bot.error_color)
12631268
)
12641269
del self.cache[recipient.id]

0 commit comments

Comments
 (0)