Skip to content

Commit 8ac0e1e

Browse files
sdanialrazaJiralite
andcommitted
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 9d6fdf8 commit 8ac0e1e

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
@@ -5,6 +5,7 @@ const { calculateUserDefaultAvatarIndex } = require('@discordjs/rest');
55
const { DiscordSnowflake } = require('@sapphire/snowflake');
66
const Base = require('./Base');
77
const TextBasedChannel = require('./interfaces/TextBasedChannel');
8+
const { _transformCollectibles } = require('../util/Transformers.js');
89
const UserFlagsBitField = require('../util/UserFlagsBitField');
910
const { emitDeprecationWarningForUserFetchFlags } = require('../util/Util');
1011

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

158183
/**
@@ -314,7 +339,11 @@ class User extends Base {
314339
this.accentColor === user.accentColor &&
315340
this.avatarDecoration === user.avatarDecoration &&
316341
this.avatarDecorationData?.asset === user.avatarDecorationData?.asset &&
317-
this.avatarDecorationData?.skuId === user.avatarDecorationData?.skuId
342+
this.avatarDecorationData?.skuId === user.avatarDecorationData?.skuId &&
343+
this.collectibles?.nameplate?.skuId === user.collectibles?.nameplate?.skuId &&
344+
this.collectibles?.nameplate?.asset === user.collectibles?.nameplate?.asset &&
345+
this.collectibles?.nameplate?.label === user.collectibles?.nameplate?.label &&
346+
this.collectibles?.nameplate?.palette === user.collectibles?.nameplate?.palette
318347
);
319348
}
320349

@@ -339,6 +368,12 @@ class User extends Base {
339368
('avatar_decoration_data' in user
340369
? this.avatarDecorationData?.asset === user.avatar_decoration_data?.asset &&
341370
this.avatarDecorationData?.skuId === user.avatar_decoration_data?.sku_id
371+
: true) &&
372+
('collectibles' in user
373+
? this.collectibles?.nameplate?.skuId === user.collectibles?.nameplate?.sku_id &&
374+
this.collectibles?.nameplate?.asset === user.collectibles?.nameplate?.asset &&
375+
this.collectibles?.nameplate?.label === user.collectibles?.nameplate?.label &&
376+
this.collectibles?.nameplate?.palette === user.collectibles?.nameplate?.palette
342377
: true)
343378
);
344379
}

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

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

553+
/**
554+
* @external NameplatePalette
555+
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/NameplatePalette}
556+
*/
557+
553558
/**
554559
* @external OAuth2Scopes
555560
* @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
@@ -95,10 +95,31 @@ function _transformAPIIncidentsData(data) {
9595
};
9696
}
9797

98+
/**
99+
* Transforms a collectibles object to a camel-cased variant.
100+
*
101+
* @param {APICollectibles} collectibles The collectibles to transform
102+
* @returns {Collectibles}
103+
* @ignore
104+
*/
105+
function _transformCollectibles(collectibles) {
106+
if (!collectibles.nameplate) return { nameplate: null };
107+
108+
return {
109+
nameplate: {
110+
skuId: collectibles.nameplate.sku_id,
111+
asset: collectibles.nameplate.asset,
112+
label: collectibles.nameplate.label,
113+
palette: collectibles.nameplate.palette,
114+
},
115+
};
116+
}
117+
98118
module.exports = {
99119
toSnakeCase,
100120
_transformAPIAutoModerationAction,
101121
_transformAPIMessageInteractionMetadata,
102122
_transformGuildScheduledEventRecurrenceRule,
103123
_transformAPIIncidentsData,
124+
_transformCollectibles,
104125
};

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ import {
8080
InteractionType,
8181
InviteTargetType,
8282
MessageType,
83+
NameplatePalette,
8384
OAuth2Scopes,
8485
RESTPostAPIApplicationCommandsJSONBody,
8586
Snowflake,
@@ -3794,6 +3795,17 @@ export interface AvatarDecorationData {
37943795
skuId: Snowflake;
37953796
}
37963797

3798+
export interface NameplateData {
3799+
asset: string;
3800+
label: string;
3801+
palette: NameplatePalette;
3802+
skuId: Snowflake;
3803+
}
3804+
3805+
export interface Collectibles {
3806+
nameplate: NameplateData | null;
3807+
}
3808+
37973809
export interface UnfurledMediaItemData {
37983810
url: string;
37993811
}
@@ -3819,6 +3831,7 @@ export class User extends Base {
38193831
public bot: boolean;
38203832
public get createdAt(): Date;
38213833
public get createdTimestamp(): number;
3834+
public collectibles: Collectibles | null;
38223835
public discriminator: string;
38233836
public get displayName(): string;
38243837
public get defaultAvatarURL(): string;

0 commit comments

Comments
 (0)