diff options
| author | SebbyLaw <[email protected]> | 2020-10-04 05:41:29 -0700 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2020-11-21 21:11:47 -0500 |
| commit | 2e2560126fb924d558c9df3f92162eda4de46323 (patch) | |
| tree | fffc3eee715cf2296b35f903aa3ba3e9e8ecb1c5 /discord/asset.py | |
| parent | Translation sync with crowdin (diff) | |
| download | discord.py-2e2560126fb924d558c9df3f92162eda4de46323.tar.xz discord.py-2e2560126fb924d558c9df3f92162eda4de46323.zip | |
Implement icon_rl_as and cover_image_url_as for AppInfo
Diffstat (limited to 'discord/asset.py')
| -rw-r--r-- | discord/asset.py | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/discord/asset.py b/discord/asset.py index 349c42a4..f5c5eddc 100644 --- a/discord/asset.py +++ b/discord/asset.py @@ -89,19 +89,29 @@ class Asset: return cls(state, '/avatars/{0.id}/{0.avatar}.{1}?size={2}'.format(user, format, size)) @classmethod - def _from_icon(cls, state, object, path): + def _from_icon(cls, state, object, path, *, format='webp', size=1024): if object.icon is None: return cls(state) - url = '/{0}-icons/{1.id}/{1.icon}.jpg'.format(path, object) + if not utils.valid_icon_size(size): + raise InvalidArgument("size must be a power of 2 between 16 and 4096") + if format not in VALID_STATIC_FORMATS: + raise InvalidArgument("format must be None or one of {}".format(VALID_STATIC_FORMATS)) + + url = '/{0}-icons/{1.id}/{1.icon}.{2}?size={3}'.format(path, object, format, size) return cls(state, url) @classmethod - def _from_cover_image(cls, state, obj): + def _from_cover_image(cls, state, obj, *, format='webp', size=1024): if obj.cover_image is None: return cls(state) - url = '/app-assets/{0.id}/store/{0.cover_image}.jpg'.format(obj) + if not utils.valid_icon_size(size): + raise InvalidArgument("size must be a power of 2 between 16 and 4096") + if format not in VALID_STATIC_FORMATS: + raise InvalidArgument("format must be None or one of {}".format(VALID_STATIC_FORMATS)) + + url = '/app-assets/{0.id}/store/{0.cover_image}.{1}?size={2}'.format(obj, format, size) return cls(state, url) @classmethod |