Skip to content

Commit 5a611be

Browse files
feat(User): add collectibles (#10939)
* feat(User): add `collectibles` * docs: nullable collectibles and nameplate data Co-authored-by: Jiralite <[email protected]> --------- Co-authored-by: Jiralite <[email protected]>
1 parent 1105ec9 commit 5a611be

File tree

4 files changed

+75
-1
lines changed

4 files changed

+75
-1
lines changed

packages/discord.js/src/structures/User.js

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const { userMention } = require('@discordjs/formatters');
44
const { calculateUserDefaultAvatarIndex } = require('@discordjs/rest');
55
const { DiscordSnowflake } = require('@sapphire/snowflake');
6+
const { _transformCollectibles } = require('../util/Transformers.js');
67
const { UserFlagsBitField } = require('../util/UserFlagsBitField.js');
78
const { Base } = require('./Base.js');
89

@@ -151,6 +152,30 @@ class User extends Base {
151152
} else {
152153
this.avatarDecorationData = null;
153154
}
155+
156+
/**
157+
* @typedef {Object} NameplateData
158+
* @property {Snowflake} skuId The id of the nameplate's SKU
159+
* @property {string} asset The nameplate's asset path
160+
* @property {string} label The nameplate's label
161+
* @property {NameplatePalette} palette Background color of the nameplate
162+
*/
163+
164+
/**
165+
* @typedef {Object} Collectibles
166+
* @property {?NameplateData} nameplate The user's nameplate data
167+
*/
168+
169+
if (data.collectibles) {
170+
/**
171+
* The user's collectibles
172+
*
173+
* @type {?Collectibles}
174+
*/
175+
this.collectibles = _transformCollectibles(data.collectibles);
176+
} else {
177+
this.collectibles = null;
178+
}
154179
}
155180

156181
/**
@@ -338,7 +363,11 @@ class User extends Base {
338363
this.banner === user.banner &&
339364
this.accentColor === user.accentColor &&
340365
this.avatarDecorationData?.asset === user.avatarDecorationData?.asset &&
341-
this.avatarDecorationData?.skuId === user.avatarDecorationData?.skuId
366+
this.avatarDecorationData?.skuId === user.avatarDecorationData?.skuId &&
367+
this.collectibles?.nameplate?.skuId === user.collectibles?.nameplate?.skuId &&
368+
this.collectibles?.nameplate?.asset === user.collectibles?.nameplate?.asset &&
369+
this.collectibles?.nameplate?.label === user.collectibles?.nameplate?.label &&
370+
this.collectibles?.nameplate?.palette === user.collectibles?.nameplate?.palette
342371
);
343372
}
344373

@@ -363,6 +392,12 @@ class User extends Base {
363392
('avatar_decoration_data' in user
364393
? this.avatarDecorationData?.asset === user.avatar_decoration_data?.asset &&
365394
this.avatarDecorationData?.skuId === user.avatar_decoration_data?.sku_id
395+
: true) &&
396+
('collectibles' in user
397+
? this.collectibles?.nameplate?.skuId === user.collectibles?.nameplate?.sku_id &&
398+
this.collectibles?.nameplate?.asset === user.collectibles?.nameplate?.asset &&
399+
this.collectibles?.nameplate?.label === user.collectibles?.nameplate?.label &&
400+
this.collectibles?.nameplate?.palette === user.collectibles?.nameplate?.palette
366401
: true)
367402
);
368403
}

packages/discord.js/src/util/APITypes.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,11 @@
549549
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/MessageFlags}
550550
*/
551551

552+
/**
553+
* @external NameplatePalette
554+
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/NameplatePalette}
555+
*/
556+
552557
/**
553558
* @external OAuth2Scopes
554559
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/OAuth2Scopes}

packages/discord.js/src/util/Transformers.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,29 @@ function _transformAPIIncidentsData(data) {
9292
};
9393
}
9494

95+
/**
96+
* Transforms a collectibles object to a camel-cased variant.
97+
*
98+
* @param {APICollectibles} collectibles The collectibles to transform
99+
* @returns {Collectibles}
100+
* @ignore
101+
*/
102+
function _transformCollectibles(collectibles) {
103+
if (!collectibles.nameplate) return { nameplate: null };
104+
105+
return {
106+
nameplate: {
107+
skuId: collectibles.nameplate.sku_id,
108+
asset: collectibles.nameplate.asset,
109+
label: collectibles.nameplate.label,
110+
palette: collectibles.nameplate.palette,
111+
},
112+
};
113+
}
114+
95115
exports.toSnakeCase = toSnakeCase;
96116
exports._transformAPIAutoModerationAction = _transformAPIAutoModerationAction;
97117
exports._transformAPIMessageInteractionMetadata = _transformAPIMessageInteractionMetadata;
98118
exports._transformGuildScheduledEventRecurrenceRule = _transformGuildScheduledEventRecurrenceRule;
99119
exports._transformAPIIncidentsData = _transformAPIIncidentsData;
120+
exports._transformCollectibles = _transformCollectibles;

packages/discord.js/typings/index.d.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ import {
170170
MessageFlags,
171171
MessageReferenceType,
172172
MessageType,
173+
NameplatePalette,
173174
OAuth2Scopes,
174175
OverwriteType,
175176
PermissionFlagsBits,
@@ -3509,6 +3510,17 @@ export interface AvatarDecorationData {
35093510
skuId: Snowflake;
35103511
}
35113512

3513+
export interface NameplateData {
3514+
asset: string;
3515+
label: string;
3516+
palette: NameplatePalette;
3517+
skuId: Snowflake;
3518+
}
3519+
3520+
export interface Collectibles {
3521+
nameplate: NameplateData | null;
3522+
}
3523+
35123524
export interface UnfurledMediaItemData {
35133525
url: string;
35143526
}
@@ -3531,6 +3543,7 @@ export class User extends Base {
35313543
public bot: boolean;
35323544
public get createdAt(): Date;
35333545
public get createdTimestamp(): number;
3546+
public collectibles: Collectibles | null;
35343547
public discriminator: string;
35353548
public get displayName(): string;
35363549
public get defaultAvatarURL(): string;

0 commit comments

Comments
 (0)