Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix breaking modmail internal thread cache #3028

Merged
merged 1 commit into from
May 24, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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