|
| 1 | +""" |
| 2 | +The MIT License (MIT) |
| 3 | +
|
| 4 | +Copyright (c) 2021-present Pycord Development |
| 5 | +
|
| 6 | +Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | +copy of this software and associated documentation files (the "Software"), |
| 8 | +to deal in the Software without restriction, including without limitation |
| 9 | +the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 10 | +and/or sell copies of the Software, and to permit persons to whom the |
| 11 | +Software is furnished to do so, subject to the following conditions: |
| 12 | +
|
| 13 | +The above copyright notice and this permission notice shall be included in |
| 14 | +all copies or substantial portions of the Software. |
| 15 | +
|
| 16 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 17 | +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 21 | +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 22 | +DEALINGS IN THE SOFTWARE. |
| 23 | +""" |
| 24 | + |
| 25 | +from typing import TYPE_CHECKING |
| 26 | + |
| 27 | +if TYPE_CHECKING: |
| 28 | + from .state import ConnectionState |
| 29 | + |
| 30 | +from .asset import Asset |
| 31 | +from .types.collectibles import Nameplate as NameplatePayload |
| 32 | + |
| 33 | + |
| 34 | +class Nameplate: |
| 35 | + """ |
| 36 | + Represents a Discord Nameplate. |
| 37 | +
|
| 38 | + .. versionadded:: 2.7 |
| 39 | +
|
| 40 | + Attributes |
| 41 | + ---------- |
| 42 | + sku_id: int |
| 43 | + The SKU ID of the nameplate. |
| 44 | + palette: str |
| 45 | + The color palette of the nameplate. |
| 46 | + """ |
| 47 | + |
| 48 | + def __init__(self, data: NameplatePayload, state: "ConnectionState") -> None: |
| 49 | + self.sku_id: int = data["sku_id"] |
| 50 | + self.palette: str = data["palette"] |
| 51 | + self._label: str = data["label"] |
| 52 | + self._asset: str = data["asset"] |
| 53 | + self._state: "ConnectionState" = state |
| 54 | + |
| 55 | + def __repr__(self) -> str: |
| 56 | + return f"<Nameplate sku_id={self.sku_id} palette={self.palette}>" |
| 57 | + |
| 58 | + def get_asset(self, animated: bool = False) -> Asset: |
| 59 | + """Returns the asset of the nameplate. |
| 60 | +
|
| 61 | + Parameters |
| 62 | + ---------- |
| 63 | + animated: :class:`bool` |
| 64 | + Whether to return the animated version of the asset, in webm version. Defaults to ``False``. |
| 65 | + """ |
| 66 | + fn = "static.png" if not animated else "asset.webm" |
| 67 | + return Asset( |
| 68 | + state=self._state, |
| 69 | + url=f"{Asset.BASE}/assets/collectibles/{self._asset}{fn}", |
| 70 | + key=self._asset.split("/")[-1], |
| 71 | + animated=animated, |
| 72 | + ) |
| 73 | + |
| 74 | + |
| 75 | +__all__ = ("Nameplate",) |
0 commit comments