Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat: user avatar decorations (#9710)
* feat: user avatar decorations

* lint

* Update typings/index.d.ts

Co-authored-by: David Malchin <malchin459@gmail.com>

---------

Co-authored-by: David Malchin <malchin459@gmail.com>
  • Loading branch information
aiko-chan-ai and D4isDAVID committed Jul 15, 2023
1 parent 630b9d5 commit cb11c56
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/structures/User.js
Expand Up @@ -122,6 +122,16 @@ class User extends Base {
*/
this.flags = new UserFlags(data.public_flags);
}

if ('avatar_decoration' in data) {
/**
* The user avatar decoration's hash
* @type {?string}
*/
this.avatarDecoration = data.avatar_decoration;
} else {
this.avatarDecoration ??= null;
}
}

/**
Expand Down Expand Up @@ -161,6 +171,16 @@ class User extends Base {
return this.client.rest.cdn.Avatar(this.id, this.avatar, format, size, dynamic);
}

/**
* A link to the user's avatar decoration.
* @param {StaticImageURLOptions} [options={}] Options for the image URL
* @returns {?string}
*/
avatarDecorationURL({ format, size } = {}) {
if (!this.avatarDecoration) return null;
return this.client.rest.cdn.AvatarDecoration(this.id, this.avatarDecoration, format, size);
}

/**
* A link to the user's default avatar
* @type {string}
Expand Down
2 changes: 2 additions & 0 deletions src/util/Constants.js
Expand Up @@ -73,6 +73,8 @@ exports.Endpoints = {
if (dynamic && hash.startsWith('a_')) format = 'gif';
return makeImageUrl(`${root}/avatars/${userId}/${hash}`, { format, size });
},
AvatarDecoration: (userId, hash, format = 'png', size) =>
makeImageUrl(`${root}/avatar-decorations/${userId}/${hash}`, { format, size }),
GuildMemberAvatar: (guildId, memberId, hash, format = 'webp', size, dynamic = false) => {
if (dynamic && hash.startsWith('a_')) format = 'gif';
return makeImageUrl(`${root}/guilds/${guildId}/users/${memberId}/avatars/${hash}`, { format, size });
Expand Down
3 changes: 3 additions & 0 deletions typings/index.d.ts
Expand Up @@ -2698,6 +2698,7 @@ export class User extends PartialTextBasedChannel(Base) {

public accentColor: number | null | undefined;
public avatar: string | null;
public avatarDecoration: string | null;
public banner: string | null | undefined;
public bot: boolean;
public readonly createdAt: Date;
Expand All @@ -2715,6 +2716,7 @@ export class User extends PartialTextBasedChannel(Base) {
public readonly tag: string;
public username: string;
public avatarURL(options?: ImageURLOptions): string | null;
public avatarDecorationURL(options?: StaticImageURLOptions): string | null;
public bannerURL(options?: ImageURLOptions): string | null;
public createDM(force?: boolean): Promise<DMChannel>;
public deleteDM(): Promise<DMChannel>;
Expand Down Expand Up @@ -3095,6 +3097,7 @@ export const Constants: {
size: AllowedImageSize,
dynamic: boolean,
): string;
AvatarDecoration(userId: Snowflake, hash: string, format: AllowedImageFormat, size: AllowedImageSize): string;
Banner(id: Snowflake, hash: string, format: DynamicImageFormat, size: AllowedImageSize, dynamic: boolean): string;
DefaultAvatar(index: number): string;
DiscoverySplash(guildId: Snowflake, hash: string, format: AllowedImageFormat, size: AllowedImageSize): string;
Expand Down

0 comments on commit cb11c56

Please sign in to comment.