Skip to content

Commit 35d75bd

Browse files
committed
Allow recipient for threads to be only the id
1 parent c366f43 commit 35d75bd

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

core/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ def channel(self) -> typing.Union[TextChannel, DMChannel]:
283283

284284
@property
285285
@abc.abstractmethod
286-
def recipient(self) -> typing.Union[User, Member]:
286+
def recipient(self) -> typing.Optional[typing.Union[User, Member]]:
287287
raise NotImplementedError
288288

289289
@property

core/thread.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,27 @@ class Thread(ThreadABC):
1616
"""Represents a discord Modmail thread"""
1717

1818
def __init__(self, manager: 'ThreadManager',
19-
recipient: typing.Union[discord.Member, discord.User],
19+
recipient: typing.Union[discord.Member, discord.User,
20+
int],
2021
channel: typing.Union[discord.DMChannel,
2122
discord.TextChannel]):
2223
if recipient.bot:
2324
raise CommandError('Recipient cannot be a bot.')
2425

2526
self.manager = manager
2627
self.bot = manager.bot
27-
self._id = recipient.id
28-
self._recipient = recipient
28+
if isinstance(recipient, int):
29+
self._id = recipient
30+
self._recipient = None
31+
else:
32+
self._id = recipient.id
33+
self._recipient = recipient
2934
self._channel = channel
3035
self._ready_event = asyncio.Event()
3136
self._close_task = None
3237

3338
def __repr__(self):
34-
return (f'Thread(recipient="{self.recipient}", '
39+
return (f'Thread(recipient="{self.recipient or self.id}", '
3540
f'channel={self.channel.id})')
3641

3742
async def wait_until_ready(self):
@@ -134,7 +139,10 @@ async def _close(self, closer, silent=False, delete_channel=True,
134139
else:
135140
log_url = f"https://logs.modmail.tk/{log_data['key']}"
136141

137-
user = self.recipient.mention if self.recipient else f'`{self.id}`'
142+
if self.recipient is not None:
143+
user = self.recipient.mention
144+
else:
145+
user = f'`{self.id}`'
138146

139147
if log_data['messages']:
140148
msg = str(log_data['messages'][0]['content'])
@@ -497,9 +505,9 @@ async def _find_from_channel(self, channel):
497505

498506
recipient = self.bot.get_user(user_id) # this could be None
499507
if recipient is None:
500-
raise ValueError('Recipient not found.')
501-
502-
self.cache[user_id] = thread = Thread(self, recipient, channel)
508+
self.cache[user_id] = thread = Thread(self, user_id, channel)
509+
else:
510+
self.cache[user_id] = thread = Thread(self, recipient, channel)
503511
thread.ready = True
504512

505513
return thread

0 commit comments

Comments
 (0)