From efe24c3927d038bf0338fddda5f7cb192985339c Mon Sep 17 00:00:00 2001 From: Lilly Rose Berner Date: Sat, 23 Apr 2022 02:28:45 +0200 Subject: [PATCH] Support dynamic rich presence asset URLs --- discord/activity.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/discord/activity.py b/discord/activity.py index 258a8fa48..19489c590 100644 --- a/discord/activity.py +++ b/discord/activity.py @@ -286,28 +286,28 @@ class Activity(BaseActivity): @property def large_image_url(self) -> Optional[str]: """Optional[:class:`str`]: Returns a URL pointing to the large image asset of this activity if applicable.""" - if self.application_id is None: - return None - try: large_image = self.assets['large_image'] except KeyError: return None else: - return Asset.BASE + f'/app-assets/{self.application_id}/{large_image}.png' + return self._image_url(large_image) @property def small_image_url(self) -> Optional[str]: """Optional[:class:`str`]: Returns a URL pointing to the small image asset of this activity if applicable.""" - if self.application_id is None: - return None - try: small_image = self.assets['small_image'] except KeyError: return None else: - return Asset.BASE + f'/app-assets/{self.application_id}/{small_image}.png' + return self._image_url(small_image) + + def _image_url(self, image: str) -> Optional[str]: + if image.startswith('mp:'): + return f'https://media.discordapp.net/{image[3:]}' + elif self.application_id is not None: + return Asset.BASE + f'/app-assets/{self.application_id}/{image}.png' @property def large_image_text(self) -> Optional[str]: