Skip to content

Commit bdf604d

Browse files
authored
feat: implement Avatar Decorations (Pycord-Development#2131)
1 parent 73ef733 commit bdf604d

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ These changes are available on the `master` branch, but have not yet been releas
8484
([#2178](https://github.com/Pycord-Development/pycord/pull/2178))
8585
- Added `applied_tags` parameter to `Webhook.send()` method.
8686
([#2322](https://github.com/Pycord-Development/pycord/pull/2322))
87+
- Added `User.avatar_decoration`.
88+
([#2131](https://github.com/Pycord-Development/pycord/pull/2131))
8789

8890
### Changed
8991

discord/asset.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,23 @@ def _from_avatar(cls, state, user_id: int, avatar: str) -> Asset:
182182
animated=animated,
183183
)
184184

185+
@classmethod
186+
def _from_avatar_decoration(
187+
cls, state, user_id: int, avatar_decoration: str
188+
) -> Asset:
189+
animated = avatar_decoration.startswith("a_")
190+
endpoint = (
191+
"avatar-decoration-presets"
192+
# if avatar_decoration.startswith(("v3", "v2"))
193+
# else f"avatar-decorations/{user_id}"
194+
)
195+
return cls(
196+
state,
197+
url=f"{cls.BASE}/{endpoint}/{avatar_decoration}.png?size=1024",
198+
key=avatar_decoration,
199+
animated=animated,
200+
)
201+
185202
@classmethod
186203
def _from_guild_avatar(
187204
cls, state, guild_id: int, member_id: int, avatar: str

discord/user.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class BaseUser(_UserTag):
7070
"bot",
7171
"system",
7272
"_public_flags",
73+
"_avatar_decoration",
7374
"_state",
7475
)
7576

@@ -84,6 +85,7 @@ class BaseUser(_UserTag):
8485
_avatar: str | None
8586
_banner: str | None
8687
_accent_colour: int | None
88+
_avatar_decoration: dict | None
8789
_public_flags: int
8890

8991
def __init__(self, *, state: ConnectionState, data: UserPayload) -> None:
@@ -134,6 +136,7 @@ def _update(self, data: UserPayload) -> None:
134136
self._avatar = data["avatar"]
135137
self._banner = data.get("banner", None)
136138
self._accent_colour = data.get("accent_color", None)
139+
self._avatar_decoration = data.get("avatar_decoration_data", None)
137140
self._public_flags = data.get("public_flags", 0)
138141
self.bot = data.get("bot", False)
139142
self.system = data.get("system", False)
@@ -149,6 +152,7 @@ def _copy(cls: type[BU], user: BU) -> BU:
149152
self._avatar = user._avatar
150153
self._banner = user._banner
151154
self._accent_colour = user._accent_colour
155+
self._avatar_decoration = user._avatar_decoration
152156
self.bot = user.bot
153157
self._state = user._state
154158
self._public_flags = user._public_flags
@@ -221,6 +225,18 @@ def banner(self) -> Asset | None:
221225
return None
222226
return Asset._from_user_banner(self._state, self.id, self._banner)
223227

228+
@property
229+
def avatar_decoration(self) -> Asset | None:
230+
"""Returns the user's avatar decoration, if available.
231+
232+
.. versionadded:: 2.5
233+
"""
234+
if self._avatar_decoration is None:
235+
return None
236+
return Asset._from_avatar_decoration(
237+
self._state, self.id, self._avatar_decoration.get("asset")
238+
)
239+
224240
@property
225241
def accent_colour(self) -> Colour | None:
226242
"""Returns the user's accent colour, if applicable.

0 commit comments

Comments
 (0)