Skip to content
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

feat: implement Avatar Decorations #2131

Merged
merged 10 commits into from Jan 31, 2024
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -84,6 +84,8 @@ These changes are available on the `master` branch, but have not yet been releas
([#2178](https://github.com/Pycord-Development/pycord/pull/2178))
- Added `applied_tags` parameter to `Webhook.send()` method.
([#2322](https://github.com/Pycord-Development/pycord/pull/2322))
- Added `User.avatar_decoration`.
([#2131](https://github.com/Pycord-Development/pycord/pull/2131))

### Changed

Expand Down
17 changes: 17 additions & 0 deletions discord/asset.py
Expand Up @@ -182,6 +182,23 @@ def _from_avatar(cls, state, user_id: int, avatar: str) -> Asset:
animated=animated,
)

@classmethod
def _from_avatar_decoration(
cls, state, user_id: int, avatar_decoration: str
) -> Asset:
animated = avatar_decoration.startswith("a_")
endpoint = (
"avatar-decoration-presets"
# if avatar_decoration.startswith(("v3", "v2"))
# else f"avatar-decorations/{user_id}"
)
return cls(
state,
url=f"{cls.BASE}/{endpoint}/{avatar_decoration}.png?size=1024",
key=avatar_decoration,
animated=animated,
)

@classmethod
def _from_guild_avatar(
cls, state, guild_id: int, member_id: int, avatar: str
Expand Down
16 changes: 16 additions & 0 deletions discord/user.py
Expand Up @@ -70,6 +70,7 @@ class BaseUser(_UserTag):
"bot",
"system",
"_public_flags",
"_avatar_decoration",
"_state",
)

Expand All @@ -84,6 +85,7 @@ class BaseUser(_UserTag):
_avatar: str | None
_banner: str | None
_accent_colour: int | None
_avatar_decoration: dict | None
_public_flags: int

def __init__(self, *, state: ConnectionState, data: UserPayload) -> None:
Expand Down Expand Up @@ -134,6 +136,7 @@ def _update(self, data: UserPayload) -> None:
self._avatar = data["avatar"]
self._banner = data.get("banner", None)
self._accent_colour = data.get("accent_color", None)
self._avatar_decoration = data.get("avatar_decoration_data", None)
self._public_flags = data.get("public_flags", 0)
self.bot = data.get("bot", False)
self.system = data.get("system", False)
Expand All @@ -149,6 +152,7 @@ def _copy(cls: type[BU], user: BU) -> BU:
self._avatar = user._avatar
self._banner = user._banner
self._accent_colour = user._accent_colour
self._avatar_decoration = user._avatar_decoration
self.bot = user.bot
self._state = user._state
self._public_flags = user._public_flags
Expand Down Expand Up @@ -221,6 +225,18 @@ def banner(self) -> Asset | None:
return None
return Asset._from_user_banner(self._state, self.id, self._banner)

@property
def avatar_decoration(self) -> Asset | None:
"""Returns the user's avatar decoration, if available.

.. versionadded:: 2.5
"""
if self._avatar_decoration is None:
return None
return Asset._from_avatar_decoration(
self._state, self.id, self._avatar_decoration.get("asset")
)

@property
def accent_colour(self) -> Colour | None:
"""Returns the user's accent colour, if applicable.
Expand Down