Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion packages/discord.js/src/structures/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const { userMention } = require('@discordjs/formatters');
const { calculateUserDefaultAvatarIndex } = require('@discordjs/rest');
const { DiscordSnowflake } = require('@sapphire/snowflake');
const { _transformCollectibles } = require('../util/Transformers.js');
const { UserFlagsBitField } = require('../util/UserFlagsBitField.js');
const { Base } = require('./Base.js');

Expand Down Expand Up @@ -151,6 +152,30 @@ class User extends Base {
} else {
this.avatarDecorationData = null;
}

/**
* @typedef {Object} NameplateData
* @property {Snowflake} skuId The id of the nameplate's SKU
* @property {string} asset The nameplate's asset path
* @property {string} label The nameplate's label
* @property {NameplatePalette} palette Background color of the nameplate
*/

/**
* @typedef {Object} Collectibles
* @property {NameplateData} nameplate The user's nameplate data
*/

if (data.collectibles) {
/**
* The user's collectibles
*
* @type {Collectibles}
*/
this.collectibles = _transformCollectibles(data.collectibles);
} else {
this.collectibles = null;
}
}

/**
Expand Down Expand Up @@ -338,7 +363,11 @@ class User extends Base {
this.banner === user.banner &&
this.accentColor === user.accentColor &&
this.avatarDecorationData?.asset === user.avatarDecorationData?.asset &&
this.avatarDecorationData?.skuId === user.avatarDecorationData?.skuId
this.avatarDecorationData?.skuId === user.avatarDecorationData?.skuId &&
this.collectibles?.nameplate?.skuId === user.collectibles?.nameplate?.skuId &&
this.collectibles?.nameplate?.asset === user.collectibles?.nameplate?.asset &&
this.collectibles?.nameplate?.label === user.collectibles?.nameplate?.label &&
this.collectibles?.nameplate?.palette === user.collectibles?.nameplate?.palette
);
}

Expand All @@ -363,6 +392,12 @@ class User extends Base {
('avatar_decoration_data' in user
? this.avatarDecorationData?.asset === user.avatar_decoration_data?.asset &&
this.avatarDecorationData?.skuId === user.avatar_decoration_data?.sku_id
: true) &&
('collectibles' in user
? this.collectibles?.nameplate?.skuId === user.collectibles?.nameplate?.sku_id &&
this.collectibles?.nameplate?.asset === user.collectibles?.nameplate?.asset &&
this.collectibles?.nameplate?.label === user.collectibles?.nameplate?.label &&
this.collectibles?.nameplate?.palette === user.collectibles?.nameplate?.palette
: true)
);
}
Expand Down
5 changes: 5 additions & 0 deletions packages/discord.js/src/util/APITypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,11 @@
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/MessageFlags}
*/

/**
* @external NameplatePalette
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/NameplatePalette}
*/

/**
* @external OAuth2Scopes
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/OAuth2Scopes}
Expand Down
21 changes: 21 additions & 0 deletions packages/discord.js/src/util/Transformers.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,29 @@ function _transformAPIIncidentsData(data) {
};
}

/**
* Transforms a collectibles object to a camel-cased variant.
*
* @param {APICollectibles} collectibles The collectibles to transform
* @returns {Collectibles}
* @ignore
*/
function _transformCollectibles(collectibles) {
if (!collectibles.nameplate) return { nameplate: null };

return {
nameplate: {
skuId: collectibles.nameplate.sku_id,
asset: collectibles.nameplate.asset,
label: collectibles.nameplate.label,
palette: collectibles.nameplate.palette,
},
};
}

exports.toSnakeCase = toSnakeCase;
exports._transformAPIAutoModerationAction = _transformAPIAutoModerationAction;
exports._transformAPIMessageInteractionMetadata = _transformAPIMessageInteractionMetadata;
exports._transformGuildScheduledEventRecurrenceRule = _transformGuildScheduledEventRecurrenceRule;
exports._transformAPIIncidentsData = _transformAPIIncidentsData;
exports._transformCollectibles = _transformCollectibles;
13 changes: 13 additions & 0 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ import {
MessageFlags,
MessageReferenceType,
MessageType,
NameplatePalette,
OAuth2Scopes,
OverwriteType,
PermissionFlagsBits,
Expand Down Expand Up @@ -3509,6 +3510,17 @@ export interface AvatarDecorationData {
skuId: Snowflake;
}

export interface NameplateData {
asset: string;
label: string;
palette: NameplatePalette;
skuId: Snowflake;
}

export interface Collectibles {
nameplate: NameplateData | null;
}

export interface UnfurledMediaItemData {
url: string;
}
Expand All @@ -3531,6 +3543,7 @@ export class User extends Base {
public bot: boolean;
public get createdAt(): Date;
public get createdTimestamp(): number;
public collectibles: Collectibles | null;
public discriminator: string;
public get displayName(): string;
public get defaultAvatarURL(): string;
Expand Down