Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions discord/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,18 @@ def _from_cover_image(cls, state, object_id: int, cover_image_hash: str) -> Asse
animated=False,
)

@classmethod
def _from_collectible(
cls, state: ConnectionState, asset: str, animated: bool = False
) -> Asset:
name = "static.png" if not animated else "asset.webm"
return cls(
state,
url=f"{cls.BASE}/assets/collectibles/{asset}{name}",
key=asset,
animated=animated,
)

@classmethod
def _from_guild_image(cls, state, guild_id: int, image: str, path: str) -> Asset:
animated = False
Expand Down
25 changes: 10 additions & 15 deletions discord/collectibles.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
DEALINGS IN THE SOFTWARE.
"""

from functools import cached_property
from typing import TYPE_CHECKING

if TYPE_CHECKING:
Expand Down Expand Up @@ -55,21 +56,15 @@ def __init__(self, data: NameplatePayload, state: "ConnectionState") -> None:
def __repr__(self) -> str:
return f"<Nameplate sku_id={self.sku_id} palette={self.palette}>"

def get_asset(self, animated: bool = False) -> Asset:
"""Returns the asset of the nameplate.

Parameters
----------
animated: :class:`bool`
Whether to return the animated version of the asset, in webm version. Defaults to ``False``.
"""
fn = "static.png" if not animated else "asset.webm"
return Asset(
state=self._state,
url=f"{Asset.BASE}/assets/collectibles/{self._asset}{fn}",
key=self._asset.split("/")[-1],
animated=animated,
)
@cached_property
def static_asset(self) -> Asset:
"""The static :class:`Asset` of this nameplate."""
return Asset._from_collectible(self._state, self._asset)

@cached_property
def animated_asset(self) -> Asset:
"""The animated :class:`Asset` of this nameplate."""
return Asset._from_collectible(self._state, self._asset, animated=True)


__all__ = ("Nameplate",)
Loading