diff options
| author | Rapptz <[email protected]> | 2019-06-04 19:04:44 -0400 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2019-06-04 19:04:44 -0400 |
| commit | 9674055c2ac2c5385564775f82010fac76c790f1 (patch) | |
| tree | 94084a0d66fbeaeae82c55cdc4a4a474d8ee089f /discord/asset.py | |
| parent | Add support for new message types related to premium guilds. (diff) | |
| download | discord.py-9674055c2ac2c5385564775f82010fac76c790f1.tar.xz discord.py-9674055c2ac2c5385564775f82010fac76c790f1.zip | |
Add support for animated guild icons.
Diffstat (limited to 'discord/asset.py')
| -rw-r--r-- | discord/asset.py | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/discord/asset.py b/discord/asset.py index affe7d59..42e2db4d 100644 --- a/discord/asset.py +++ b/discord/asset.py @@ -70,7 +70,7 @@ class Asset: @classmethod def _from_avatar(cls, state, user, *, format=None, static_format='webp', size=1024): if not utils.valid_icon_size(size): - raise InvalidArgument("size must be a power of 2 between 16 and 1024") + raise InvalidArgument("size must be a power of 2 between 16 and 4096") if format is not None and format not in VALID_AVATAR_FORMATS: raise InvalidArgument("format must be None or one of {}".format(VALID_AVATAR_FORMATS)) if format == "gif" and not user.is_avatar_animated(): @@ -107,6 +107,26 @@ class Asset: url = 'https://cdn.discordapp.com/{key}/{0}/{1}.{2}?size={3}' return cls(state, url.format(id, hash, format, size, key=key)) + @classmethod + def _from_guild_icon(cls, state, guild, *, format=None, static_format='webp', size=1024): + if not utils.valid_icon_size(size): + raise InvalidArgument("size must be a power of 2 between 16 and 4096") + if format is not None and format not in VALID_AVATAR_FORMATS: + raise InvalidArgument("format must be one of {}".format(VALID_AVATAR_FORMATS)) + if format == "gif" and not guild.is_icon_animated(): + raise InvalidArgument("non animated guild icons do not support gif format") + if static_format not in VALID_STATIC_FORMATS: + raise InvalidArgument("static_format must be one of {}".format(VALID_STATIC_FORMATS)) + + if guild.icon is None: + return cls(state) + + if format is None: + format = 'gif' if guild.is_icon_animated() else static_format + + return cls(state, 'https://cdn.discordapp.com/icons/{0.id}/{0.icon}.{1}?size={2}'.format(guild, format, size)) + + def __str__(self): return self._url if self._url is not None else '' |