mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
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:
@@ -3,6 +3,7 @@
|
|||||||
const { userMention } = require('@discordjs/formatters');
|
const { userMention } = require('@discordjs/formatters');
|
||||||
const { calculateUserDefaultAvatarIndex } = require('@discordjs/rest');
|
const { calculateUserDefaultAvatarIndex } = require('@discordjs/rest');
|
||||||
const { DiscordSnowflake } = require('@sapphire/snowflake');
|
const { DiscordSnowflake } = require('@sapphire/snowflake');
|
||||||
|
const { _transformCollectibles } = require('../util/Transformers.js');
|
||||||
const { UserFlagsBitField } = require('../util/UserFlagsBitField.js');
|
const { UserFlagsBitField } = require('../util/UserFlagsBitField.js');
|
||||||
const { Base } = require('./Base.js');
|
const { Base } = require('./Base.js');
|
||||||
|
|
||||||
@@ -151,6 +152,30 @@ class User extends Base {
|
|||||||
} else {
|
} else {
|
||||||
this.avatarDecorationData = null;
|
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.banner === user.banner &&
|
||||||
this.accentColor === user.accentColor &&
|
this.accentColor === user.accentColor &&
|
||||||
this.avatarDecorationData?.asset === user.avatarDecorationData?.asset &&
|
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
|
('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
|
||||||
|
: 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)
|
: true)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -549,6 +549,11 @@
|
|||||||
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/MessageFlags}
|
* @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
|
* @external OAuth2Scopes
|
||||||
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/OAuth2Scopes}
|
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/OAuth2Scopes}
|
||||||
|
|||||||
@@ -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.toSnakeCase = toSnakeCase;
|
||||||
exports._transformAPIAutoModerationAction = _transformAPIAutoModerationAction;
|
exports._transformAPIAutoModerationAction = _transformAPIAutoModerationAction;
|
||||||
exports._transformAPIMessageInteractionMetadata = _transformAPIMessageInteractionMetadata;
|
exports._transformAPIMessageInteractionMetadata = _transformAPIMessageInteractionMetadata;
|
||||||
exports._transformGuildScheduledEventRecurrenceRule = _transformGuildScheduledEventRecurrenceRule;
|
exports._transformGuildScheduledEventRecurrenceRule = _transformGuildScheduledEventRecurrenceRule;
|
||||||
exports._transformAPIIncidentsData = _transformAPIIncidentsData;
|
exports._transformAPIIncidentsData = _transformAPIIncidentsData;
|
||||||
|
exports._transformCollectibles = _transformCollectibles;
|
||||||
|
|||||||
13
packages/discord.js/typings/index.d.ts
vendored
13
packages/discord.js/typings/index.d.ts
vendored
@@ -170,6 +170,7 @@ import {
|
|||||||
MessageFlags,
|
MessageFlags,
|
||||||
MessageReferenceType,
|
MessageReferenceType,
|
||||||
MessageType,
|
MessageType,
|
||||||
|
NameplatePalette,
|
||||||
OAuth2Scopes,
|
OAuth2Scopes,
|
||||||
OverwriteType,
|
OverwriteType,
|
||||||
PermissionFlagsBits,
|
PermissionFlagsBits,
|
||||||
@@ -3509,6 +3510,17 @@ export interface AvatarDecorationData {
|
|||||||
skuId: Snowflake;
|
skuId: Snowflake;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface NameplateData {
|
||||||
|
asset: string;
|
||||||
|
label: string;
|
||||||
|
palette: NameplatePalette;
|
||||||
|
skuId: Snowflake;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Collectibles {
|
||||||
|
nameplate: NameplateData | null;
|
||||||
|
}
|
||||||
|
|
||||||
export interface UnfurledMediaItemData {
|
export interface UnfurledMediaItemData {
|
||||||
url: string;
|
url: string;
|
||||||
}
|
}
|
||||||
@@ -3531,6 +3543,7 @@ export class User extends Base {
|
|||||||
public bot: boolean;
|
public bot: boolean;
|
||||||
public get createdAt(): Date;
|
public get createdAt(): Date;
|
||||||
public get createdTimestamp(): number;
|
public get createdTimestamp(): number;
|
||||||
|
public collectibles: Collectibles | null;
|
||||||
public discriminator: string;
|
public discriminator: string;
|
||||||
public get displayName(): string;
|
public get displayName(): string;
|
||||||
public get defaultAvatarURL(): string;
|
public get defaultAvatarURL(): string;
|
||||||
|
|||||||
Reference in New Issue
Block a user