diff options
| author | Rapptz <[email protected]> | 2021-04-16 11:21:13 -0400 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2021-04-16 11:27:23 -0400 |
| commit | 9eaf1e85e4e987b5f874a7ba4c3ed13de10fd154 (patch) | |
| tree | 83a60b0aaff3c1b63868631418cb7583adda054d /discord/invite.py | |
| parent | Add `fetch_message` for webhooks (diff) | |
| download | discord.py-9eaf1e85e4e987b5f874a7ba4c3ed13de10fd154.tar.xz discord.py-9eaf1e85e4e987b5f874a7ba4c3ed13de10fd154.zip | |
Rewrite Asset design
This is a breaking change.
This does the following transformations, assuming `asset` represents
an asset type.
Object.is_asset_animated() => Object.asset.is_animated()
Object.asset => Object.asset.key
Object.asset_url => Object.asset_url
Object.asset_url_as => Object.asset.replace(...)
Since the asset type now requires a key (or hash, if you will),
Emoji had to be flattened similar to how Attachment was done since
these assets are keyed solely ID.
Emoji.url (Asset) => Emoji.url (str)
Emoji.url_as => removed
Emoji.url.read => Emoji.read
Emoji.url.save => Emoji.save
This transformation was also done to PartialEmoji.
Diffstat (limited to 'discord/invite.py')
| -rw-r--r-- | discord/invite.py | 75 |
1 files changed, 19 insertions, 56 deletions
diff --git a/discord/invite.py b/discord/invite.py index d8bd554f..ce601299 100644 --- a/discord/invite.py +++ b/discord/invite.py @@ -140,26 +140,20 @@ class PartialInviteGuild: The partial guild's verification level. features: List[:class:`str`] A list of features the guild has. See :attr:`Guild.features` for more information. - icon: Optional[:class:`str`] - The partial guild's icon. - banner: Optional[:class:`str`] - The partial guild's banner. - splash: Optional[:class:`str`] - The partial guild's invite splash. description: Optional[:class:`str`] The partial guild's description. """ - __slots__ = ('_state', 'features', 'icon', 'banner', 'id', 'name', 'splash', 'verification_level', 'description') + __slots__ = ('_state', 'features', '_icon', '_banner', 'id', 'name', '_splash', 'verification_level', 'description') def __init__(self, state, data: InviteGuildPayload, id: int): self._state = state self.id = id self.name = data['name'] self.features = data.get('features', []) - self.icon = data.get('icon') - self.banner = data.get('banner') - self.splash = data.get('splash') + self._icon = data.get('icon') + self._banner = data.get('banner') + self._splash = data.get('splash') self.verification_level = try_enum(VerificationLevel, data.get('verification_level')) self.description = data.get('description') @@ -178,56 +172,25 @@ class PartialInviteGuild: return snowflake_time(self.id) @property - def icon_url(self) -> Asset: - """:class:`Asset`: Returns the guild's icon asset.""" - return self.icon_url_as() - - def is_icon_animated(self) -> bool: - """:class:`bool`: Returns ``True`` if the guild has an animated icon. - - .. versionadded:: 1.4 - """ - return bool(self.icon and self.icon.startswith('a_')) - - def icon_url_as(self, *, format=None, static_format='webp', size=1024) -> Asset: - """The same operation as :meth:`Guild.icon_url_as`. - - Returns - -------- - :class:`Asset` - The resulting CDN asset. - """ - return Asset._from_guild_icon(self._state, self, format=format, static_format=static_format, size=size) + def icon_url(self) -> Optional[Asset]: + """Optional[:class:`Asset`]: Returns the guild's icon asset, if available.""" + if self._icon is None: + return None + return Asset._from_guild_icon(self._state, self.id, self._icon) @property - def banner_url(self) -> Asset: - """:class:`Asset`: Returns the guild's banner asset.""" - return self.banner_url_as() - - def banner_url_as(self, *, format='webp', size=2048) -> Asset: - """The same operation as :meth:`Guild.banner_url_as`. - - Returns - -------- - :class:`Asset` - The resulting CDN asset. - """ - return Asset._from_guild_image(self._state, self.id, self.banner, 'banners', format=format, size=size) + def banner(self) -> Optional[Asset]: + """Optional[:class:`Asset`]: Returns the guild's banner asset, if available.""" + if self._banner is None: + return None + return Asset._from_guild_image(self._state, self.id, self._banner, path='banners') @property - def splash_url(self) -> Asset: - """:class:`Asset`: Returns the guild's invite splash asset.""" - return self.splash_url_as() - - def splash_url_as(self, *, format='webp', size=2048) -> Asset: - """The same operation as :meth:`Guild.splash_url_as`. - - Returns - -------- - :class:`Asset` - The resulting CDN asset. - """ - return Asset._from_guild_image(self._state, self.id, self.splash, 'splashes', format=format, size=size) + def splash(self) -> Optional[Asset]: + """Optional[:class:`Asset`]: Returns the guild's invite splash asset, if available.""" + if self._splash is None: + return None + return Asset._from_guild_image(self._state, self.id, self._splash, path='splashes') class Invite(Hashable): |