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/channel.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/channel.py')
| -rw-r--r-- | discord/channel.py | 57 |
1 files changed, 13 insertions, 44 deletions
diff --git a/discord/channel.py b/discord/channel.py index ee6869c0..57ec56ca 100644 --- a/discord/channel.py +++ b/discord/channel.py @@ -94,9 +94,9 @@ class TextChannel(discord.abc.Messageable, discord.abc.GuildChannel, Hashable): :attr:`~Permissions.manage_messages` bypass slowmode. nsfw: :class:`bool` If the channel is marked as "not safe for work". - + .. note:: - + To check if the channel or the guild of that channel are marked as NSFW, consider :meth:`is_nsfw` instead. """ @@ -894,9 +894,9 @@ class CategoryChannel(discord.abc.GuildChannel, Hashable): top category is position 0. nsfw: :class:`bool` If the channel is marked as "not safe for work". - + .. note:: - + To check if the channel or the guild of that channel are marked as NSFW, consider :meth:`is_nsfw` instead. """ @@ -1096,9 +1096,9 @@ class StoreChannel(discord.abc.GuildChannel, Hashable): top channel is position 0. nsfw: :class:`bool` If the channel is marked as "not safe for work". - + .. note:: - + To check if the channel or the guild of that channel are marked as NSFW, consider :meth:`is_nsfw` instead. """ __slots__ = ('name', 'id', 'guild', '_state', 'nsfw', @@ -1343,13 +1343,11 @@ class GroupChannel(discord.abc.Messageable, Hashable): The group channel ID. owner: :class:`User` The user that owns the group channel. - icon: Optional[:class:`str`] - The group channel's icon hash if provided. name: Optional[:class:`str`] The group channel's name if provided. """ - __slots__ = ('id', 'recipients', 'owner', 'icon', 'name', 'me', '_state') + __slots__ = ('id', 'recipients', 'owner', '_icon', 'name', 'me', '_state') def __init__(self, *, me, state, data): self._state = state @@ -1359,7 +1357,7 @@ class GroupChannel(discord.abc.Messageable, Hashable): def _update_group(self, data): owner_id = utils._get_as_snowflake(data, 'owner_id') - self.icon = data.get('icon') + self._icon = data.get('icon') self.name = data.get('name') try: @@ -1393,40 +1391,11 @@ class GroupChannel(discord.abc.Messageable, Hashable): return ChannelType.group @property - def icon_url(self): - """:class:`Asset`: Returns the channel's icon asset if available. - - This is equivalent to calling :meth:`icon_url_as` with - the default parameters ('webp' format and a size of 1024). - """ - return self.icon_url_as() - - def icon_url_as(self, *, format='webp', size=1024): - """Returns an :class:`Asset` for the icon the channel has. - - The format must be one of 'webp', 'jpeg', 'jpg' or 'png'. - The size must be a power of 2 between 16 and 4096. - - .. versionadded:: 2.0 - - Parameters - ----------- - format: :class:`str` - The format to attempt to convert the icon to. Defaults to 'webp'. - size: :class:`int` - The size of the image to display. - - Raises - ------ - InvalidArgument - Bad image format passed to ``format`` or invalid ``size``. - - Returns - -------- - :class:`Asset` - The resulting CDN asset. - """ - return Asset._from_icon(self._state, self, 'channel', format=format, size=size) + def icon(self): + """Optional[:class:`Asset`]: Returns the channel's icon asset if available.""" + if self._icon is None: + return None + return Asset._from_icon(self._state, self.id, self._icon, path='channel') @property def created_at(self): |