Skip to content

Commit c731141

Browse files
authored
feat: support avatar decorations (#1329)
1 parent 6b8783e commit c731141

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

interactions/models/discord/asset.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import re
12
from typing import TYPE_CHECKING, Optional, Union
23

34
import attrs
@@ -74,7 +75,9 @@ def as_url(self, *, extension: str | None = None, size: int = 4096) -> str:
7475
@property
7576
def animated(self) -> bool:
7677
"""True if this asset is animated."""
77-
return bool(self.hash) and self.hash.startswith("a_")
78+
# damn hashes with version numbers
79+
_hash = re.sub(r"^v\d+_", "", self.hash or "")
80+
return bool(self.hash) and _hash.startswith("a_")
7881

7982
async def fetch(self, extension: Optional[str] = None, size: Optional[int] = None) -> bytes:
8083
"""

interactions/models/discord/user.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ class User(BaseUser):
133133
)
134134

135135
banner: Optional["Asset"] = attrs.field(repr=False, default=None, metadata=docs("The user's banner"))
136+
avatar_decoration: Optional["Asset"] = attrs.field(
137+
repr=False, default=None, metadata=docs("The user's avatar decoration")
138+
)
136139
accent_color: Optional["Color"] = attrs.field(
137140
default=None,
138141
converter=optional_c(Color),
@@ -156,6 +159,11 @@ def _process_dict(cls, data: Dict[str, Any], client: "Client") -> Dict[str, Any]
156159
if data.get("premium_type", None) is None:
157160
data["premium_type"] = 0
158161

162+
if data.get("avatar_decoration", None):
163+
data["avatar_decoration"] = Asset.from_path_hash(
164+
client, "avatar-decoration-presets/{}", data["avatar_decoration"]
165+
)
166+
159167
return data
160168

161169
@property

0 commit comments

Comments
 (0)