Skip to content

Commit

Permalink
Hopefully resolves #3022.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerrie-Aries committed May 11, 2021
1 parent 7ed1fcb commit ef4b5b2
Showing 1 changed file with 30 additions and 28 deletions.
58 changes: 30 additions & 28 deletions core/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -1115,16 +1115,16 @@ async def find(
try:
await thread.wait_until_ready()
except asyncio.CancelledError:
logger.warning("Thread for %s cancelled, abort creating", recipient)
logger.warning("Thread for %s cancelled.", recipient)
return thread
else:
if not thread.channel or not self.bot.get_channel(thread.channel.id):
if not thread.cancelled and (
not thread.channel or not self.bot.get_channel(thread.channel.id)
):
logger.warning(
"Found existing thread for %s but the channel is invalid.", recipient_id
)
self.bot.loop.create_task(
thread.close(closer=self.bot.user, silent=True, delete_channel=False)
)
await thread.close(closer=self.bot.user, silent=True, delete_channel=False)
thread = None
else:
channel = discord.utils.get(
Expand Down Expand Up @@ -1186,7 +1186,7 @@ async def create(
try:
await thread.wait_until_ready()
except asyncio.CancelledError:
logger.warning("Thread for %s cancelled, abort creating", recipient)
logger.warning("Thread for %s cancelled, abort creating.", recipient)
return thread
else:
if thread.channel and self.bot.get_channel(thread.channel.id):
Expand All @@ -1195,9 +1195,7 @@ async def create(
logger.warning(
"Found an existing thread for %s, closing previous thread.", recipient
)
self.bot.loop.create_task(
thread.close(closer=self.bot.user, silent=True, delete_channel=False)
)
await thread.close(closer=self.bot.user, silent=True, delete_channel=False)

thread = Thread(self, recipient)

Expand Down Expand Up @@ -1231,9 +1229,11 @@ async def create(
)
accept_emoji = self.bot.config["confirm_thread_creation_accept"]
deny_emoji = self.bot.config["confirm_thread_creation_deny"]
await confirm.add_reaction(accept_emoji)
await asyncio.sleep(0.2)
await confirm.add_reaction(deny_emoji)
emojis = [accept_emoji, deny_emoji]
for emoji in emojis:
await confirm.add_reaction(emoji)
await asyncio.sleep(0.2)

try:
r, _ = await self.bot.wait_for(
"reaction_add",
Expand All @@ -1245,29 +1245,31 @@ async def create(
)
except asyncio.TimeoutError:
thread.cancelled = True

await confirm.remove_reaction(accept_emoji, self.bot.user)
await asyncio.sleep(0.2)
await confirm.remove_reaction(deny_emoji, self.bot.user)
await destination.send(
embed=discord.Embed(
title="Cancelled", description="Timed out", color=self.bot.error_color
self.bot.loop.create_task(
destination.send(
embed=discord.Embed(
title="Cancelled", description="Timed out", color=self.bot.error_color
)
)
)
del self.cache[recipient.id]
return thread
else:
if str(r.emoji) == deny_emoji:
thread.cancelled = True
self.bot.loop.create_task(
destination.send(
embed=discord.Embed(title="Cancelled", color=self.bot.error_color)
)
)

await confirm.remove_reaction(accept_emoji, self.bot.user)
async def remove_reactions():
for emoji in emojis:
await confirm.remove_reaction(emoji, self.bot.user)
await asyncio.sleep(0.2)
await confirm.remove_reaction(deny_emoji, self.bot.user)
await destination.send(
embed=discord.Embed(title="Cancelled", color=self.bot.error_color)
)
del self.cache[recipient.id]
return thread

self.bot.loop.create_task(remove_reactions())
if thread.cancelled:
del self.cache[recipient.id]
return thread

self.bot.loop.create_task(
thread.setup(creator=creator, category=category, initial_message=message)
Expand Down

0 comments on commit ef4b5b2

Please sign in to comment.