Skip to content

Commit e002867

Browse files
committed
Merge branch 'dev-03' of git://github.com/Jerrie-Aries/modmail into Jerrie-Aries-dev-03
2 parents c71efc3 + ef4b5b2 commit e002867

File tree

1 file changed

+30
-28
lines changed

1 file changed

+30
-28
lines changed

core/thread.py

+30-28
Original file line numberDiff line numberDiff line change
@@ -1115,16 +1115,16 @@ async def find(
11151115
try:
11161116
await thread.wait_until_ready()
11171117
except asyncio.CancelledError:
1118-
logger.warning("Thread for %s cancelled, abort creating", recipient)
1118+
logger.warning("Thread for %s cancelled.", recipient)
11191119
return thread
11201120
else:
1121-
if not thread.channel or not self.bot.get_channel(thread.channel.id):
1121+
if not thread.cancelled and (
1122+
not thread.channel or not self.bot.get_channel(thread.channel.id)
1123+
):
11221124
logger.warning(
11231125
"Found existing thread for %s but the channel is invalid.", recipient_id
11241126
)
1125-
self.bot.loop.create_task(
1126-
thread.close(closer=self.bot.user, silent=True, delete_channel=False)
1127-
)
1127+
await thread.close(closer=self.bot.user, silent=True, delete_channel=False)
11281128
thread = None
11291129
else:
11301130
channel = discord.utils.get(
@@ -1186,7 +1186,7 @@ async def create(
11861186
try:
11871187
await thread.wait_until_ready()
11881188
except asyncio.CancelledError:
1189-
logger.warning("Thread for %s cancelled, abort creating", recipient)
1189+
logger.warning("Thread for %s cancelled, abort creating.", recipient)
11901190
return thread
11911191
else:
11921192
if thread.channel and self.bot.get_channel(thread.channel.id):
@@ -1195,9 +1195,7 @@ async def create(
11951195
logger.warning(
11961196
"Found an existing thread for %s, closing previous thread.", recipient
11971197
)
1198-
self.bot.loop.create_task(
1199-
thread.close(closer=self.bot.user, silent=True, delete_channel=False)
1200-
)
1198+
await thread.close(closer=self.bot.user, silent=True, delete_channel=False)
12011199

12021200
thread = Thread(self, recipient)
12031201

@@ -1231,9 +1229,11 @@ async def create(
12311229
)
12321230
accept_emoji = self.bot.config["confirm_thread_creation_accept"]
12331231
deny_emoji = self.bot.config["confirm_thread_creation_deny"]
1234-
await confirm.add_reaction(accept_emoji)
1235-
await asyncio.sleep(0.2)
1236-
await confirm.add_reaction(deny_emoji)
1232+
emojis = [accept_emoji, deny_emoji]
1233+
for emoji in emojis:
1234+
await confirm.add_reaction(emoji)
1235+
await asyncio.sleep(0.2)
1236+
12371237
try:
12381238
r, _ = await self.bot.wait_for(
12391239
"reaction_add",
@@ -1245,29 +1245,31 @@ async def create(
12451245
)
12461246
except asyncio.TimeoutError:
12471247
thread.cancelled = True
1248-
1249-
await confirm.remove_reaction(accept_emoji, self.bot.user)
1250-
await asyncio.sleep(0.2)
1251-
await confirm.remove_reaction(deny_emoji, self.bot.user)
1252-
await destination.send(
1253-
embed=discord.Embed(
1254-
title="Cancelled", description="Timed out", color=self.bot.error_color
1248+
self.bot.loop.create_task(
1249+
destination.send(
1250+
embed=discord.Embed(
1251+
title="Cancelled", description="Timed out", color=self.bot.error_color
1252+
)
12551253
)
12561254
)
1257-
del self.cache[recipient.id]
1258-
return thread
12591255
else:
12601256
if str(r.emoji) == deny_emoji:
12611257
thread.cancelled = True
1258+
self.bot.loop.create_task(
1259+
destination.send(
1260+
embed=discord.Embed(title="Cancelled", color=self.bot.error_color)
1261+
)
1262+
)
12621263

1263-
await confirm.remove_reaction(accept_emoji, self.bot.user)
1264+
async def remove_reactions():
1265+
for emoji in emojis:
1266+
await confirm.remove_reaction(emoji, self.bot.user)
12641267
await asyncio.sleep(0.2)
1265-
await confirm.remove_reaction(deny_emoji, self.bot.user)
1266-
await destination.send(
1267-
embed=discord.Embed(title="Cancelled", color=self.bot.error_color)
1268-
)
1269-
del self.cache[recipient.id]
1270-
return thread
1268+
1269+
self.bot.loop.create_task(remove_reactions())
1270+
if thread.cancelled:
1271+
del self.cache[recipient.id]
1272+
return thread
12711273

12721274
self.bot.loop.create_task(
12731275
thread.setup(creator=creator, category=category, initial_message=message)

0 commit comments

Comments
 (0)