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 #889

Merged
merged 38 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
e9bc233
feat: implement avatar decorations
Victorsitou Dec 8, 2022
eca32a8
feat: support animated avatar decorations
Victorsitou Dec 8, 2022
fb7d442
docs: add changelog entry
Victorsitou Dec 8, 2022
3931f10
docs: note about avatar decoration
Victorsitou Dec 8, 2022
f911fa8
misc: remove format (png is always used)
Victorsitou Dec 8, 2022
5d4e89d
misc: add avatar_decoration to Member type_checking
Victorsitou Dec 8, 2022
970ad6d
docs: fix docs
Victorsitou Dec 8, 2022
8f13660
types: add avatar_decoration type & add missing types
Victorsitou Dec 8, 2022
cf9330a
lint: fix lint error
Victorsitou Dec 8, 2022
4d26a15
Merge branch 'master' into feat/avatar-decorations
Victorsitou Dec 16, 2022
c2e5833
misc: remove unnecessary header
Victorsitou Dec 18, 2022
8cc1423
Merge branch 'feat/avatar-decorations' of https://github.com/Victorsi…
Victorsitou Dec 18, 2022
9de76a1
Merge branch 'master' into feat/avatar-decorations
Victorsitou Dec 22, 2022
adcabe0
docs: remove note
Victorsitou Dec 24, 2022
dcc3dd4
docs: add note about animated png
Victorsitou Dec 24, 2022
4460877
Merge branch 'feat/avatar-decorations' of https://github.com/Victorsi…
Victorsitou Dec 24, 2022
2304d38
fix: return avatar decoration when member/user cache is disabled
Victorsitou Dec 24, 2022
149b884
docs: reword changelog
Victorsitou Dec 27, 2022
49455f6
docs: exclude `avatar_decoration` in WidgetMember
Victorsitou Dec 27, 2022
7681d1e
Merge branch 'feat/avatar-decorations' of https://github.com/Victorsi…
Victorsitou Dec 27, 2022
f0e7a7d
fix: update `_avatar_decoration` in GUILD_MEMBER_UPDATE
Victorsitou Dec 27, 2022
3f14388
Merge branch 'master' into feat/avatar-decorations
Victorsitou Jan 12, 2023
6f684dc
typing: improve
Victorsitou Jan 12, 2023
b187544
Merge branch 'master' into feat/avatar-decorations
Victorsitou Feb 22, 2023
ae5f2a8
Merge remote-tracking branch 'upstream/master' into feat/avatar-decor…
Victorsitou Jul 14, 2023
ace1289
fix: remove no format
Victorsitou Jul 14, 2023
74f7ad0
docs: exclude `avatar_decoration` in WidgetMember
Victorsitou Jul 15, 2023
91938d6
Merge remote-tracking branch 'upstream/master' into feat/avatar-decor…
Victorsitou Jul 15, 2023
2d4e3cf
Merge remote-tracking branch 'upstream/master' into feat/avatar-decor…
Victorsitou Mar 20, 2024
5998e62
feat: update to api changes
Victorsitou Mar 20, 2024
3156d92
docs: it's now always available (?)
Victorsitou Mar 20, 2024
7b982d7
docs: update version
Victorsitou Mar 20, 2024
80cad8d
Merge remote-tracking branch 'upstream/master' into feat/avatar-decor…
Victorsitou May 20, 2024
8f27216
fix: update avatar decoration asset url
Victorsitou May 20, 2024
fc463a8
feat: implement guild-specific avatar decoration
Victorsitou May 20, 2024
86d81e1
feat: update avatar decoration data on member update
Victorsitou May 20, 2024
80a8f0d
feat: split into display_avatar_decoration and guild_avatar_decoration
Victorsitou May 21, 2024
5d3aa8b
type(Member): avatar_decoration_data is optional
Victorsitou May 21, 2024
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/889.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add support for avatar decorations.
- Add :attr:`User.avatar_decoration`
Victorsitou marked this conversation as resolved.
Show resolved Hide resolved
10 changes: 10 additions & 0 deletions disnake/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,16 @@ def _from_guild_scheduled_event_image(cls, state, event_id: int, image_hash: str
animated=False,
)

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

def __str__(self) -> str:
return self._url

Expand Down
1 change: 1 addition & 0 deletions disnake/member.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ class Member(disnake.abc.Messageable, _UserTag):
banner: Optional[Asset]
accent_color: Optional[Colour]
accent_colour: Optional[Colour]
avatar_decoration: Optional[Asset]
Victorsitou marked this conversation as resolved.
Show resolved Hide resolved
Victorsitou marked this conversation as resolved.
Show resolved Hide resolved

@overload
def __init__(
Expand Down
5 changes: 4 additions & 1 deletion disnake/types/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ class User(PartialUser, total=False):
bot: bool
system: bool
mfa_enabled: bool
local: str
banner: Optional[str]
accent_color: Optional[int]
locale: str
verified: bool
email: Optional[str]
flags: int
premium_type: PremiumType
public_flags: int
avatar_decoration: Optional[str]
25 changes: 22 additions & 3 deletions disnake/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ class BaseUser(_UserTag):
"name",
"id",
"discriminator",
"bot",
"system",
"_avatar",
"_banner",
"_avatar_decoration",
"_accent_colour",
"bot",
"system",
"_public_flags",
"_state",
)
Expand All @@ -60,7 +61,8 @@ class BaseUser(_UserTag):
_state: ConnectionState
_avatar: Optional[str]
_banner: Optional[str]
_accent_colour: Optional[str]
_avatar_decoration: Optional[str]
_accent_colour: Optional[int]
_public_flags: int

def __init__(
Expand Down Expand Up @@ -93,6 +95,7 @@ def _update(self, data: Union[UserPayload, PartialUserPayload]) -> None:
self.discriminator = data["discriminator"]
self._avatar = data["avatar"]
self._banner = data.get("banner", None)
self._avatar_decoration = data.get("avatar_decoration", None)
self._accent_colour = data.get("accent_color", None)
self._public_flags = data.get("public_flags", 0)
self.bot = data.get("bot", False)
Expand All @@ -107,6 +110,7 @@ def _copy(cls, user: BaseUser) -> Self:
self.discriminator = user.discriminator
self._avatar = user._avatar
self._banner = user._banner
self._avatar_decoration = user._avatar_decoration
self._accent_colour = user._accent_colour
self.bot = user.bot
self._state = user._state
Expand Down Expand Up @@ -162,12 +166,27 @@ def banner(self) -> Optional[Asset]:
.. versionadded:: 2.0

.. note::

This information is only available via :meth:`Client.fetch_user`.
"""
if self._banner is None:
return None
return Asset._from_banner(self._state, self.id, self._banner)

@property
def avatar_decoration(self) -> Optional[Asset]:
"""Optional[:class:`Asset`]: Returns the user's avatar decoration asset, if available.
shiftinv marked this conversation as resolved.
Show resolved Hide resolved

.. versionadded:: 2.8

.. note::

This information is only available via :meth:`Client.fetch_user`.
shiftinv marked this conversation as resolved.
Show resolved Hide resolved
"""
if self._avatar_decoration is None:
return None
return Asset._from_avatar_decoration(self._state, self.id, self._avatar_decoration)

@property
def accent_colour(self) -> Optional[Colour]:
"""Optional[:class:`Colour`]: Returns the user's accent colour, if applicable.
Expand Down