Skip to content

Commit

Permalink
feat: update
Browse files Browse the repository at this point in the history
  • Loading branch information
Syjalo committed Jun 7, 2023
1 parent e82edd1 commit 54a01d3
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
9 changes: 5 additions & 4 deletions packages/discord.js/src/structures/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -205,7 +205,8 @@ class User extends Base {

/**
* The tag of this user
* <info>This user's username, or their legacy tag (e.g. `hydrabolt#0001`) if they're using the legacy username system</info>
* <info>This user's username, or their legacy tag (e.g. `hydrabolt#0001`)
* if they're using the legacy username system</info>
* @type {?string}
* @readonly
* @deprecated Use {@link User#username} instead.
Expand Down
2 changes: 1 addition & 1 deletion packages/rest/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions packages/rest/src/lib/CDN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' });
}

/**
Expand Down
8 changes: 4 additions & 4 deletions packages/rest/src/lib/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 54a01d3

Please sign in to comment.