feat(User): add collectibles (#10939)

* feat(User): add `collectibles`

* docs: nullable collectibles and nameplate data

Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>

---------

Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>
This commit is contained in:
Danial Raza
2025-07-15 01:35:00 +02:00
committed by GitHub
parent 1105ec9abc
commit 5a611be8de
4 changed files with 75 additions and 1 deletions

View File

@@ -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');
@@ -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;
}
}
/**
@@ -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
);
}
@@ -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)
);
}

View File

@@ -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}

View File

@@ -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;

View File

@@ -170,6 +170,7 @@ import {
MessageFlags,
MessageReferenceType,
MessageType,
NameplatePalette,
OAuth2Scopes,
OverwriteType,
PermissionFlagsBits,
@@ -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;
}
@@ -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;