Skip to content

feat: ✨ add Nameplate class and integration #2817

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions discord/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand Down
76 changes: 76 additions & 0 deletions discord/collectibles.py
Original file line number Diff line number Diff line change
@@ -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"<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,
)


__all__ = ("Nameplate", "NameplatePalette")
19 changes: 19 additions & 0 deletions discord/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")


Expand Down
37 changes: 37 additions & 0 deletions discord/types/collectibles.py
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions discord/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -76,6 +77,7 @@ class BaseUser(_UserTag):
"_public_flags",
"_avatar_decoration",
"_state",
"nameplate",
)

if TYPE_CHECKING:
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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",)
Expand Down
50 changes: 50 additions & 0 deletions docs/api/enums.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
10 changes: 10 additions & 0 deletions docs/api/models.rst
Original file line number Diff line number Diff line change
Expand Up @@ -602,3 +602,13 @@ Webhooks

.. autoclass:: PartialWebhookChannel()
:members:



Collectibles
------------

.. attributetable:: Nameplate

.. autoclass:: Nameplate()
:undoc-members: