parent
ee6f4e85d6
commit
6ed0ae7d96
@ -229,8 +229,8 @@ class Invite(Hashable):
|
|||||||
How long the before the invite expires in seconds. A value of 0 indicates that it doesn't expire.
|
How long the before the invite expires in seconds. A value of 0 indicates that it doesn't expire.
|
||||||
code: :class:`str`
|
code: :class:`str`
|
||||||
The URL fragment used for the invite.
|
The URL fragment used for the invite.
|
||||||
guild: Union[:class:`Guild`, :class:`Object`, :class:`PartialInviteGuild`]
|
guild: Optional[Union[:class:`Guild`, :class:`Object`, :class:`PartialInviteGuild`]]
|
||||||
The guild the invite is for.
|
The guild the invite is for. Can be ``None`` if it's from a group direct message.
|
||||||
revoked: :class:`bool`
|
revoked: :class:`bool`
|
||||||
Indicates if the invite has been revoked.
|
Indicates if the invite has been revoked.
|
||||||
created_at: :class:`datetime.datetime`
|
created_at: :class:`datetime.datetime`
|
||||||
@ -278,17 +278,28 @@ class Invite(Hashable):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_incomplete(cls, *, state, data):
|
def from_incomplete(cls, *, state, data):
|
||||||
guild_id = int(data['guild']['id'])
|
try:
|
||||||
channel_id = int(data['channel']['id'])
|
guild_id = int(data['guild']['id'])
|
||||||
guild = state._get_guild(guild_id)
|
except KeyError:
|
||||||
if guild is not None:
|
# If we're here, then this is a group DM
|
||||||
channel = guild.get_channel(channel_id)
|
guild = None
|
||||||
else:
|
else:
|
||||||
channel_data = data['channel']
|
guild = state._get_guild(guild_id)
|
||||||
guild_data = data['guild']
|
if guild is None:
|
||||||
channel_type = try_enum(ChannelType, channel_data['type'])
|
# If it's not cached, then it has to be a partial guild
|
||||||
channel = PartialInviteChannel(id=channel_id, name=channel_data['name'], type=channel_type)
|
guild_data = data['guild']
|
||||||
guild = PartialInviteGuild(state, guild_data, guild_id)
|
guild = PartialInviteGuild(state, guild_data, guild_id)
|
||||||
|
|
||||||
|
# As far as I know, invites always need a channel
|
||||||
|
# So this should never raise.
|
||||||
|
channel_data = data['channel']
|
||||||
|
channel_id = int(channel_data['id'])
|
||||||
|
channel_type = try_enum(ChannelType, channel_data['type'])
|
||||||
|
channel = PartialInviteChannel(id=channel_id, name=channel_data['name'], type=channel_type)
|
||||||
|
if guild is not None:
|
||||||
|
# Upgrade the partial data if applicable
|
||||||
|
channel = guild.get_channel(channel_id) or channel
|
||||||
|
|
||||||
data['guild'] = guild
|
data['guild'] = guild
|
||||||
data['channel'] = channel
|
data['channel'] = channel
|
||||||
return cls(state=state, data=data)
|
return cls(state=state, data=data)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user