feat: Updated decoration links & prop

#1037
This commit is contained in:
Elysia
2024-10-04 17:46:10 +07:00
parent 963201698f
commit ebc18df352
4 changed files with 39 additions and 25 deletions

View File

@@ -202,7 +202,7 @@ class GuildScheduledEvent extends Base {
* @returns {?string} * @returns {?string}
*/ */
coverImageURL({ format, size } = {}) { coverImageURL({ format, size } = {}) {
return this.image && this.client.rest.cdn.guildScheduledEventCover(this.id, this.image, format, size); return this.image && this.client.rest.cdn.GuildScheduledEventCover(this.id, this.image, format, size);
} }
/** /**

View File

@@ -136,17 +136,6 @@ class User extends Base {
this.flags = new UserFlags(data.public_flags); this.flags = new UserFlags(data.public_flags);
} }
if ('avatar_decoration' in data) {
/**
* The user avatar decoration's hash
* @type {?string}
* @deprecated Use `avatarDecorationData` instead
*/
this.avatarDecoration = data.avatar_decoration;
} else {
this.avatarDecoration ??= null;
}
/** /**
* @typedef {Object} AvatarDecorationData * @typedef {Object} AvatarDecorationData
* @property {string} asset The avatar decoration hash * @property {string} asset The avatar decoration hash
@@ -191,6 +180,16 @@ class User extends Base {
} }
} }
/**
* The user avatar decoration's hash
* @type {?string}
* @deprecated Use `avatarDecorationData` instead
* Removed in v4
*/
get avatarDecoration() {
return this.avatarDecorationData?.asset || null;
}
/** /**
* Whether this User is a partial * Whether this User is a partial
* @type {boolean} * @type {boolean}
@@ -231,13 +230,12 @@ class User extends Base {
/** /**
* A link to the user's avatar decoration. * A link to the user's avatar decoration.
* @param {StaticImageURLOptions} [options={}] Options for the image URL * @param {StaticImageURLOptions} [options={}] Options for the image URL
* <info> The `format` option is not supported for this image URL</info>
* @returns {?string} * @returns {?string}
*/ */
avatarDecorationURL({ format, size } = {}) { avatarDecorationURL({ size } = {}) {
if (this.avatarDecorationData) { if (!this.avatarDecorationData) return null;
return this.client.rest.cdn.AvatarDecoration(this.id, this.avatarDecorationData.asset, format, size); return this.client.rest.cdn.AvatarDecoration(this.avatarDecorationData.asset, size);
}
return this.avatarDecoration && this.client.rest.cdn.AvatarDecoration(this.id, this.avatarDecoration, format, size);
} }
/** /**
@@ -361,7 +359,6 @@ class User extends Base {
this.flags?.bitfield === user.flags?.bitfield && this.flags?.bitfield === user.flags?.bitfield &&
this.banner === user.banner && this.banner === user.banner &&
this.accentColor === user.accentColor && this.accentColor === user.accentColor &&
this.avatarDecoration === user.avatarDecoration &&
this.avatarDecorationData?.asset === user.avatarDecorationData?.asset && this.avatarDecorationData?.asset === user.avatarDecorationData?.asset &&
this.avatarDecorationData?.skuId === user.avatarDecorationData?.skuId this.avatarDecorationData?.skuId === user.avatarDecorationData?.skuId
); );
@@ -384,7 +381,6 @@ class User extends Base {
this.flags?.bitfield === user.public_flags && this.flags?.bitfield === user.public_flags &&
('banner' in user ? this.banner === user.banner : true) && ('banner' in user ? this.banner === user.banner : true) &&
('accent_color' in user ? this.accentColor === user.accent_color : true) && ('accent_color' in user ? this.accentColor === user.accent_color : true) &&
('avatar_decoration' in user ? this.avatarDecoration === user.avatar_decoration : true) &&
('avatar_decoration_data' in user ('avatar_decoration_data' in user
? this.avatarDecorationData?.asset === user.avatar_decoration_data?.asset && ? this.avatarDecorationData?.asset === user.avatar_decoration_data?.asset &&
this.avatarDecorationData?.skuId === user.avatar_decoration_data?.sku_id this.avatarDecorationData?.skuId === user.avatar_decoration_data?.sku_id

View File

@@ -96,13 +96,17 @@ exports.Endpoints = {
if (dynamic && hash.startsWith('a_')) format = 'gif'; if (dynamic && hash.startsWith('a_')) format = 'gif';
return makeImageUrl(`${root}/avatars/${userId}/${hash}`, { format, size }); return makeImageUrl(`${root}/avatars/${userId}/${hash}`, { format, size });
}, },
AvatarDecoration: (userId, hash, format = 'png', size) => AvatarDecoration: (hash, size) =>
makeImageUrl(`${root}/avatar-decorations/${userId}/${hash}`, { format, size }), makeImageUrl(`${root}/avatar-decoration-presets/${hash}`, { format: 'png', size }),
ClanBadge: (guildId, hash) => `${root}/clan-badges/${guildId}/${hash}.png`, ClanBadge: (guildId, hash) => `${root}/clan-badges/${guildId}/${hash}.png`,
GuildMemberAvatar: (guildId, memberId, hash, format = 'webp', size, dynamic = false) => { GuildMemberAvatar: (guildId, memberId, hash, format = 'webp', size, dynamic = false) => {
if (dynamic && hash.startsWith('a_')) format = 'gif'; if (dynamic && hash.startsWith('a_')) format = 'gif';
return makeImageUrl(`${root}/guilds/${guildId}/users/${memberId}/avatars/${hash}`, { format, size }); return makeImageUrl(`${root}/guilds/${guildId}/users/${memberId}/avatars/${hash}`, { format, size });
}, },
GuildMemberBanner: (guildId, memberId, hash, format = 'webp', size, dynamic = false) => {
if (dynamic && hash.startsWith('a_')) format = 'gif';
return makeImageUrl(`${root}/guilds/${guildId}/users/${memberId}/banners/${hash}`, { format, size });
},
Banner: (id, hash, format, size, dynamic = false) => { Banner: (id, hash, format, size, dynamic = false) => {
if (dynamic && hash.startsWith('a_')) format = 'gif'; if (dynamic && hash.startsWith('a_')) format = 'gif';
return makeImageUrl(`${root}/banners/${id}/${hash}`, { format, size }); return makeImageUrl(`${root}/banners/${id}/${hash}`, { format, size });
@@ -127,7 +131,7 @@ exports.Endpoints = {
}`, }`,
RoleIcon: (roleId, hash, format = 'webp', size) => RoleIcon: (roleId, hash, format = 'webp', size) =>
makeImageUrl(`${root}/role-icons/${roleId}/${hash}`, { size, format }), makeImageUrl(`${root}/role-icons/${roleId}/${hash}`, { size, format }),
guildScheduledEventCover: (scheduledEventId, coverHash, format, size) => GuildScheduledEventCover: (scheduledEventId, coverHash, format, size) =>
makeImageUrl(`${root}/guild-events/${scheduledEventId}/${coverHash}`, { size, format }), makeImageUrl(`${root}/guild-events/${scheduledEventId}/${coverHash}`, { size, format }),
}; };
}, },

20
typings/index.d.ts vendored
View File

@@ -3398,7 +3398,7 @@ export class User extends PartialTextBasedChannel(Base) {
public accentColor: number | null | undefined; public accentColor: number | null | undefined;
public avatar: string | null; public avatar: string | null;
/** @deprecated Use {@link User.avatarDecorationData} instead */ /** @deprecated Use {@link User.avatarDecorationData} instead */
public avatarDecoration: string | null; public readonly avatarDecoration: string | null;
public avatarDecorationData: AvatarDecorationData | null; public avatarDecorationData: AvatarDecorationData | null;
public banner: string | null | undefined; public banner: string | null | undefined;
public bannerColor: string | null | undefined; public bannerColor: string | null | undefined;
@@ -3423,7 +3423,7 @@ export class User extends PartialTextBasedChannel(Base) {
public readonly friendNickname: string | null | undefined; public readonly friendNickname: string | null | undefined;
public clan: UserClan | null; public clan: UserClan | null;
public avatarURL(options?: ImageURLOptions): string | null; public avatarURL(options?: ImageURLOptions): string | null;
public avatarDecorationURL(options?: StaticImageURLOptions): string | null; public avatarDecorationURL(options?: Omit<StaticImageURLOptions, 'format'>): string | null;
public bannerURL(options?: ImageURLOptions): string | null; public bannerURL(options?: ImageURLOptions): string | null;
public clanBadgeURL(): string | null; public clanBadgeURL(): string | null;
public createDM(force?: boolean): Promise<DMChannel>; public createDM(force?: boolean): Promise<DMChannel>;
@@ -3815,7 +3815,7 @@ export const Constants: {
size: AllowedImageSize, size: AllowedImageSize,
dynamic: boolean, dynamic: boolean,
): string; ): string;
AvatarDecoration(userId: Snowflake, hash: string, format: AllowedImageFormat, size: AllowedImageSize): string; AvatarDecoration(hash: string, size: AllowedImageSize): string;
ClanBadge(guildId: Snowflake, hash: string): string; ClanBadge(guildId: Snowflake, hash: string): string;
Banner(id: Snowflake, hash: string, format: DynamicImageFormat, size: AllowedImageSize, dynamic: boolean): string; Banner(id: Snowflake, hash: string, format: DynamicImageFormat, size: AllowedImageSize, dynamic: boolean): string;
DefaultAvatar(index: number): string; DefaultAvatar(index: number): string;
@@ -3830,6 +3830,14 @@ export const Constants: {
size?: AllowedImageSize, size?: AllowedImageSize,
dynamic?: boolean, dynamic?: boolean,
): string; ): string;
GuildMemberBanner(
guildId: Snowflake,
memberId: Snowflake,
hash: string,
format?: DynamicImageFormat,
size?: AllowedImageSize,
dynamic?: boolean,
): string;
Icon( Icon(
guildId: Snowflake, guildId: Snowflake,
hash: string, hash: string,
@@ -3846,6 +3854,12 @@ export const Constants: {
hash: string, hash: string,
{ format, size }: { format: AllowedImageFormat; size: AllowedImageSize }, { format, size }: { format: AllowedImageFormat; size: AllowedImageSize },
): string; ): string;
GuildScheduledEventCover(
scheduledEventId: Snowflake,
coverHash: string,
format: AllowedImageFormat,
size: AllowedImageSize,
): string;
}; };
botGateway: string; botGateway: string;
invite(root: string, code: string, eventId?: Snowflake): string; invite(root: string, code: string, eventId?: Snowflake): string;