Improve generic duck type programming with PartialMessageable

This adds jump_url, permissions_for, and created_at. Luckily, most
cases of this type being constructed already have the guild_id at
creation time.
This commit is contained in:
Rapptz
2022-05-03 10:49:52 -04:00
parent e9c7c09ebf
commit 8699d2139a
8 changed files with 59 additions and 11 deletions

View File

@ -213,9 +213,11 @@ class Namespace:
for (message_id, message_data) in resolved.get('messages', {}).items():
channel_id = int(message_data['channel_id'])
if guild is None:
channel = PartialMessageable(state=state, id=channel_id)
channel = PartialMessageable(state=state, guild_id=guild_id, id=channel_id)
else:
channel = guild.get_channel_or_thread(channel_id) or PartialMessageable(state=state, id=channel_id)
channel = guild.get_channel_or_thread(channel_id) or PartialMessageable(
state=state, guild_id=guild_id, id=channel_id
)
# Type checker doesn't understand this due to failure to narrow
message = Message(state=state, channel=channel, data=message_data) # type: ignore