Skip to content

Commit 58c0dfc

Browse files
authored
feat: ✨ add Nameplate class and integration (#2817)
* ✨ add Nameplate class and integration in user model * 🏷️ feat: add nameplate attribute to User class * ✨ add NameplatePalette enum and enhance Nameplate class with asset retrieval * 📝 add nameplate attribute to User class documentation * 📝 CHANGELOG.md * 📝 add versionadded directive for Nameplate class and NameplatePalette enum * 📝 update Nameplate class documentation to include undocumented members * ✏️ Fix typo in NameplatePalette * 📝 standardize nameplate color attributes to lowercase and document each color in enums * 📝 refine Nameplate class docstring for clarity * Update discord/collectibles.py Signed-off-by: Paillat <[email protected]> * ♻️ remove NameplatePalette enum and change palette type to str --------- Signed-off-by: Paillat <[email protected]> Signed-off-by: Paillat <[email protected]>
1 parent 975a0d9 commit 58c0dfc

File tree

6 files changed

+136
-0
lines changed

6 files changed

+136
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ These changes are available on the `master` branch, but have not yet been releas
6363
([#2775](https://github.com/Pycord-Development/pycord/pull/2775))
6464
- Added `discord.Interaction.created_at`.
6565
([#2801](https://github.com/Pycord-Development/pycord/pull/2801))
66+
- Added `User.nameplate` property.
67+
([#2817](https://github.com/Pycord-Development/pycord/pull/2817))
6668
- Added role gradients support with `Role.colours` and the `RoleColours` class.
6769
([#2818](https://github.com/Pycord-Development/pycord/pull/2818))
6870

discord/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
from .channel import *
3636
from .client import *
3737
from .cog import *
38+
from .collectibles import *
3839
from .colour import *
3940
from .commands import *
4041
from .components import *

discord/collectibles.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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",)

discord/types/collectibles.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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 __future__ import annotations
26+
27+
from typing import TypedDict
28+
29+
from .snowflake import Snowflake
30+
31+
32+
class Nameplate(TypedDict):
33+
sku_id: Snowflake
34+
asset: str
35+
label: str
36+
palette: str

discord/user.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import discord.abc
3131

3232
from .asset import Asset
33+
from .collectibles import Nameplate
3334
from .colour import Colour
3435
from .flags import PublicUserFlags
3536
from .iterators import EntitlementIterator
@@ -76,6 +77,7 @@ class BaseUser(_UserTag):
7677
"_public_flags",
7778
"_avatar_decoration",
7879
"_state",
80+
"nameplate",
7981
)
8082

8183
if TYPE_CHECKING:
@@ -91,6 +93,7 @@ class BaseUser(_UserTag):
9193
_accent_colour: int | None
9294
_avatar_decoration: dict | None
9395
_public_flags: int
96+
nameplate: Nameplate | None
9497

9598
def __init__(
9699
self, *, state: ConnectionState, data: UserPayload | PartialUserPayload
@@ -143,6 +146,11 @@ def _update(self, data: UserPayload) -> None:
143146
self._banner = data.get("banner", None)
144147
self._accent_colour = data.get("accent_color", None)
145148
self._avatar_decoration = data.get("avatar_decoration_data", None)
149+
nameplate = (data.get("collectibles") or {}).get("nameplate", None)
150+
if nameplate:
151+
self.nameplate = Nameplate(data=nameplate, state=self._state)
152+
else:
153+
self.nameplate = None
146154
self._public_flags = data.get("public_flags", 0)
147155
self.bot = data.get("bot", False)
148156
self.system = data.get("system", False)
@@ -534,6 +542,10 @@ class User(BaseUser, discord.abc.Messageable):
534542
Specifies if the user is a bot account.
535543
system: :class:`bool`
536544
Specifies if the user is a system user (i.e. represents Discord officially).
545+
nameplate: Optional[:class:`Nameplate`]
546+
The user's nameplate, if the user has one.
547+
548+
.. versionadded:: 2.7
537549
"""
538550

539551
__slots__ = ("_stored",)

docs/api/models.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,3 +652,13 @@ Webhooks
652652

653653
.. autoclass:: PartialWebhookChannel()
654654
:members:
655+
656+
657+
658+
Collectibles
659+
------------
660+
661+
.. attributetable:: Nameplate
662+
663+
.. autoclass:: Nameplate()
664+
:undoc-members:

0 commit comments

Comments
 (0)