Skip to content

Commit b0776da

Browse files
committed
fix: contact while snooze returned as invalid channel
1 parent 5e7802e commit b0776da

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

bot.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,6 +1599,19 @@ async def handle_react_to_contact(self, payload):
15991599
)
16001600
return await member.send(embed=embed)
16011601

1602+
# Check if user has a snoozed thread
1603+
existing_thread = await self.threads.find(recipient=member)
1604+
if existing_thread and existing_thread.snoozed:
1605+
# Unsnooze the thread
1606+
await existing_thread.restore_from_snooze()
1607+
self.threads.cache[existing_thread.id] = existing_thread
1608+
# Send notification to the thread channel
1609+
if existing_thread.channel:
1610+
await existing_thread.channel.send(
1611+
f"ℹ️ {member.mention} reacted to contact and their snoozed thread has been unsnoozed."
1612+
)
1613+
return
1614+
16021615
ctx = await self.get_context(message)
16031616
await ctx.invoke(self.get_command("contact"), users=[member], manual_trigger=False)
16041617

cogs/modmail.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1584,6 +1584,25 @@ async def edit(self, ctx, message_id: Optional[int] = None, *, message: str):
15841584
@checks.has_permissions(PermissionLevel.REGULAR)
15851585
async def selfcontact(self, ctx):
15861586
"""Creates a thread with yourself"""
1587+
# Check if user already has a thread
1588+
existing_thread = await self.bot.threads.find(recipient=ctx.author)
1589+
if existing_thread:
1590+
if existing_thread.snoozed:
1591+
# Unsnooze the thread
1592+
await ctx.send(f"ℹ️ You had a snoozed thread. Unsnoozing now...")
1593+
await existing_thread.restore_from_snooze()
1594+
self.bot.threads.cache[existing_thread.id] = existing_thread
1595+
return
1596+
else:
1597+
# Thread already exists and is active
1598+
embed = discord.Embed(
1599+
title="Thread not created",
1600+
description=f"A thread for you already exists in {existing_thread.channel.mention}.",
1601+
color=self.bot.error_color,
1602+
)
1603+
await ctx.send(embed=embed, delete_after=10)
1604+
return
1605+
15871606
await ctx.invoke(self.contact, users=[ctx.author])
15881607

15891608
@commands.command(usage="<user> [category] [options]")
@@ -1642,9 +1661,14 @@ async def contact(
16421661
users += u.members
16431662
users.remove(u)
16441663

1664+
snoozed_users = []
16451665
for u in list(users):
16461666
exists = await self.bot.threads.find(recipient=u)
16471667
if exists:
1668+
# Check if thread is snoozed
1669+
if exists.snoozed:
1670+
snoozed_users.append(u)
1671+
continue
16481672
errors.append(f"A thread for {u} already exists.")
16491673
if exists.channel:
16501674
errors[-1] += f" in {exists.channel.mention}"
@@ -1658,6 +1682,17 @@ async def contact(
16581682
errors.append(f"{ref} currently blocked from contacting {self.bot.user.name}.")
16591683
users.remove(u)
16601684

1685+
# Handle snoozed users - unsnooze them and return early
1686+
if snoozed_users:
1687+
for u in snoozed_users:
1688+
thread = await self.bot.threads.find(recipient=u)
1689+
if thread and thread.snoozed:
1690+
await ctx.send(f"ℹ️ {u.mention} had a snoozed thread. Unsnoozing now...")
1691+
await thread.restore_from_snooze()
1692+
self.bot.threads.cache[thread.id] = thread
1693+
# Don't try to create a new thread - we just unsnoozed existing ones
1694+
return
1695+
16611696
if len(users) > 5:
16621697
errors.append("Group conversations only support 5 users.")
16631698
users = []
@@ -1674,7 +1709,6 @@ async def contact(
16741709
await ctx.send(embed=embed, delete_after=10)
16751710

16761711
if not users:
1677-
# end
16781712
return
16791713

16801714
creator = ctx.author if manual_trigger else users[0]

0 commit comments

Comments
 (0)