diff --git a/CHANGELOG.md b/CHANGELOG.md index fdfdc6d896..47c79c66ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,6 +57,8 @@ These changes are available on the `master` branch, but have not yet been releas ([#2747](https://github.com/Pycord-Development/pycord/pull/2747)) - Added `discord.Interaction.created_at`. ([#2801](https://github.com/Pycord-Development/pycord/pull/2801)) +- Added `User.nameplate` property. + ([#2817](https://github.com/Pycord-Development/pycord/pull/2817)) ### Fixed diff --git a/discord/__init__.py b/discord/__init__.py index d6031ce3ac..afe3002e00 100644 --- a/discord/__init__.py +++ b/discord/__init__.py @@ -35,6 +35,7 @@ from .channel import * from .client import * from .cog import * +from .collectibles import * from .colour import * from .commands import * from .components import * diff --git a/discord/collectibles.py b/discord/collectibles.py new file mode 100644 index 0000000000..925b604688 --- /dev/null +++ b/discord/collectibles.py @@ -0,0 +1,76 @@ +""" +The MIT License (MIT) + +Copyright (c) 2021-present Pycord Development + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. +""" + +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + from .state import ConnectionState + +from .asset import Asset +from .enums import NameplatePalette +from .types.collectibles import Nameplate as NameplatePayload + + +class Nameplate: + """ + Represents a Discord Nameplate. + + .. versionadded:: 2.7 + + Attributes + ---------- + sku_id: int + The SKU ID of the nameplate. + palette: NameplatePalette + The color palette of the nameplate. + """ + + def __init__(self, data: NameplatePayload, state: "ConnectionState") -> None: + self.sku_id: int = data["sku_id"] + self.palette: NameplatePalette = data["palette"] + self._label: str = data["label"] + self._asset: str = data["asset"] + self._state: "ConnectionState" = state + + def __repr__(self) -> str: + return f"" + + 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, + ) + + +__all__ = ("Nameplate", "NameplatePalette") diff --git a/discord/enums.py b/discord/enums.py index 01d10275c8..0ceefcc441 100644 --- a/discord/enums.py +++ b/discord/enums.py @@ -1078,6 +1078,25 @@ class SubscriptionStatus(Enum): inactive = 2 +class NameplatePalette(Enum): + """A nameplate color palette. + + .. versionadded:: 2.7 + """ + + crimson = "crimson" + berry = "berry" + sky = "sky" + teal = "teal" + forest = "forest" + bubble_gum = "bubble_gum" + violet = "violet" + cobalt = "cobalt" + clover = "clover" + lemon = "lemon" + white = "white" + + T = TypeVar("T") diff --git a/discord/types/collectibles.py b/discord/types/collectibles.py new file mode 100644 index 0000000000..d284776917 --- /dev/null +++ b/discord/types/collectibles.py @@ -0,0 +1,37 @@ +""" +The MIT License (MIT) + +Copyright (c) 2021-present Pycord Development + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. +""" + +from __future__ import annotations + +from typing import TypedDict + +from ..enums import NameplatePalette +from .snowflake import Snowflake + + +class Nameplate(TypedDict): + sku_id: Snowflake + asset: str + label: str + palette: NameplatePalette diff --git a/discord/user.py b/discord/user.py index 9fa995cf66..368381191c 100644 --- a/discord/user.py +++ b/discord/user.py @@ -30,6 +30,7 @@ import discord.abc from .asset import Asset +from .collectibles import Nameplate from .colour import Colour from .flags import PublicUserFlags from .iterators import EntitlementIterator @@ -76,6 +77,7 @@ class BaseUser(_UserTag): "_public_flags", "_avatar_decoration", "_state", + "nameplate", ) if TYPE_CHECKING: @@ -91,6 +93,7 @@ class BaseUser(_UserTag): _accent_colour: int | None _avatar_decoration: dict | None _public_flags: int + nameplate: Nameplate | None def __init__( self, *, state: ConnectionState, data: UserPayload | PartialUserPayload @@ -143,6 +146,11 @@ def _update(self, data: UserPayload) -> None: self._banner = data.get("banner", None) self._accent_colour = data.get("accent_color", None) self._avatar_decoration = data.get("avatar_decoration_data", None) + nameplate = (data.get("collectibles") or {}).get("nameplate", None) + if nameplate: + self.nameplate = Nameplate(data=nameplate, state=self._state) + else: + self.nameplate = None self._public_flags = data.get("public_flags", 0) self.bot = data.get("bot", False) self.system = data.get("system", False) @@ -534,6 +542,10 @@ class User(BaseUser, discord.abc.Messageable): Specifies if the user is a bot account. system: :class:`bool` Specifies if the user is a system user (i.e. represents Discord officially). + nameplate: Optional[:class:`Nameplate`] + The user's nameplate, if the user has one. + + .. versionadded:: 2.7 """ __slots__ = ("_stored",) diff --git a/docs/api/enums.rst b/docs/api/enums.rst index 4d278e3758..8527f47c8b 100644 --- a/docs/api/enums.rst +++ b/docs/api/enums.rst @@ -2519,3 +2519,53 @@ of :class:`enum.Enum`. .. attribute:: inactive The subscription is inactive and the subscription owner is not being charged. + +.. class:: NameplatePalette + + A nameplate color palette. + + .. versionadded:: 2.7 + + .. attribute:: crimson + + Crimson nameplate color palette. + + .. attribute:: berry + + Berry nameplate color palette. + + .. attribute:: sky + + Sky nameplate color palette. + + .. attribute:: teal + + Teal nameplate color palette. + + .. attribute:: forest + + Forest nameplate color palette. + + .. attribute:: bubble_gum + + Bubble_gum nameplate color palette. + + .. attribute:: violet + + Violet nameplate color palette. + + .. attribute:: cobalt + + Cobalt nameplate color palette. + + .. attribute:: clover + + Clover nameplate color palette. + + .. attribute:: lemon + + Lemon nameplate color palette. + + .. attribute:: white + + White nameplate color palette. diff --git a/docs/api/models.rst b/docs/api/models.rst index cb702b2c38..cb3e4f9e71 100644 --- a/docs/api/models.rst +++ b/docs/api/models.rst @@ -602,3 +602,13 @@ Webhooks .. autoclass:: PartialWebhookChannel() :members: + + + +Collectibles +------------ + +.. attributetable:: Nameplate + +.. autoclass:: Nameplate() + :undoc-members: