From 54a01d34c9ea6199a40cf67dbeba8729032669c4 Mon Sep 17 00:00:00 2001 From: Synbulat Biishev Date: Wed, 7 Jun 2023 22:36:47 +0300 Subject: [PATCH] feat: update --- packages/discord.js/src/structures/User.js | 9 +++++---- packages/rest/src/index.ts | 2 +- packages/rest/src/lib/CDN.ts | 9 +++++---- packages/rest/src/lib/utils/utils.ts | 8 ++++---- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/packages/discord.js/src/structures/User.js b/packages/discord.js/src/structures/User.js index 16825406d821..092cc3c6ffcc 100644 --- a/packages/discord.js/src/structures/User.js +++ b/packages/discord.js/src/structures/User.js @@ -2,7 +2,7 @@ const process = require('node:process'); const { userMention } = require('@discordjs/builders'); -const { calculateUserDefaultAvatarType } = require('@discordjs/rest'); +const { calculateUserDefaultAvatarIndex } = require('@discordjs/rest'); const { DiscordSnowflake } = require('@sapphire/snowflake'); const Base = require('./Base'); const TextBasedChannel = require('./interfaces/TextBasedChannel'); @@ -169,8 +169,8 @@ class User extends Base { * @readonly */ get defaultAvatarURL() { - const type = this.discriminator === '0' ? calculateUserDefaultAvatarType(this.id) : this.discriminator % 5; - return this.client.rest.cdn.defaultAvatar(type); + const index = this.discriminator === '0' ? calculateUserDefaultAvatarIndex(this.id) : this.discriminator % 5; + return this.client.rest.cdn.defaultAvatar(index); } /** @@ -205,7 +205,8 @@ class User extends Base { /** * The tag of this user - * This user's username, or their legacy tag (e.g. `hydrabolt#0001`) if they're using the legacy username system + * This user's username, or their legacy tag (e.g. `hydrabolt#0001`) + * if they're using the legacy username system * @type {?string} * @readonly * @deprecated Use {@link User#username} instead. diff --git a/packages/rest/src/index.ts b/packages/rest/src/index.ts index fc88068fa642..b6af7b7ef7df 100644 --- a/packages/rest/src/index.ts +++ b/packages/rest/src/index.ts @@ -5,7 +5,7 @@ export * from './lib/errors/RateLimitError.js'; export * from './lib/RequestManager.js'; export * from './lib/REST.js'; export * from './lib/utils/constants.js'; -export { calculateUserDefaultAvatarType, makeURLSearchParams, parseResponse } from './lib/utils/utils.js'; +export { calculateUserDefaultAvatarIndex, makeURLSearchParams, parseResponse } from './lib/utils/utils.js'; /** * The {@link https://github.com/discordjs/discord.js/blob/main/packages/rest/#readme | @discordjs/rest} version diff --git a/packages/rest/src/lib/CDN.ts b/packages/rest/src/lib/CDN.ts index bf33774bb374..a42966bd8829 100644 --- a/packages/rest/src/lib/CDN.ts +++ b/packages/rest/src/lib/CDN.ts @@ -121,12 +121,13 @@ export class CDN { /** * Generates a default avatar URL * - * @param type - The default avatar type + * @param index - The default avatar index * @remarks - * `type` is calculated via `(userId >> 22) % 5` or `discriminator % 5` with the legacy username system. + * To calculate the index for a user do `(userId >> 22) % 6`, + * or `discriminator % 5` if they're using the legacy username system. */ - public defaultAvatar(type: number): string { - return this.makeURL(`/embed/avatars/${type}`, { extension: 'png' }); + public defaultAvatar(index: number): string { + return this.makeURL(`/embed/avatars/${index}`, { extension: 'png' }); } /** diff --git a/packages/rest/src/lib/utils/utils.ts b/packages/rest/src/lib/utils/utils.ts index df2df82d26dc..ee8832921790 100644 --- a/packages/rest/src/lib/utils/utils.ts +++ b/packages/rest/src/lib/utils/utils.ts @@ -114,10 +114,10 @@ export async function onRateLimit(manager: RequestManager, rateLimitData: RateLi } /** - * Calculates the default avatar type for a given user id. + * Calculates the default avatar index for a given user id. * - * @param userId - The user id to calculate the default avatar type for + * @param userId - The user id to calculate the default avatar index for */ -export function calculateUserDefaultAvatarType(userId: string) { - return Number(BigInt(userId) >> 22n) % 5; +export function calculateUserDefaultAvatarIndex(userId: string) { + return Number(BigInt(userId) >> 22n) % 6; }