mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-03 05:26:07 +00:00
fix: use calculateUserDefaultAvatarIndex function
This commit is contained in:
parent
0392de7964
commit
28133b2c1f
@ -5,8 +5,8 @@ import type { Snowflake } from 'discord-api-types/v10';
|
|||||||
*
|
*
|
||||||
* @param userId - The user id to calculate the default avatar index for
|
* @param userId - The user id to calculate the default avatar index for
|
||||||
*/
|
*/
|
||||||
export function calculateUserDefaultAvatarIndex(userId: Snowflake) {
|
export function calculateUserDefaultAvatarIndex(userId: Snowflake, discriminator: string) {
|
||||||
return Number(BigInt(userId) >> 22n) % 6;
|
return discriminator === '0' ? Number(BigInt(userId) >> 22n) % 6 : Number.parseInt(discriminator) % 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import type { APIUser } from 'discord-api-types/v10';
|
import type { APIUser } from 'discord-api-types/v10';
|
||||||
|
import { calculateUserDefaultAvatarIndex } from '../api';
|
||||||
import type { MessageCreateBodyRequest, ObjectToLower } from '../common';
|
import type { MessageCreateBodyRequest, ObjectToLower } from '../common';
|
||||||
import type { ImageOptions } from '../common/types/options';
|
import type { ImageOptions } from '../common/types/options';
|
||||||
import { DiscordBase } from './extra/DiscordBase';
|
import { DiscordBase } from './extra/DiscordBase';
|
||||||
@ -34,9 +35,7 @@ export class User extends DiscordBase<APIUser> {
|
|||||||
|
|
||||||
avatarURL(options?: ImageOptions) {
|
avatarURL(options?: ImageOptions) {
|
||||||
if (!this.avatar) {
|
if (!this.avatar) {
|
||||||
const avatarIndex =
|
return this.rest.cdn.embed.avatars.get(calculateUserDefaultAvatarIndex(this.id, this.discriminator));
|
||||||
this.discriminator === '0' ? Number(BigInt(this.id) >> 22n) % 6 : Number.parseInt(this.discriminator) % 5;
|
|
||||||
return this.rest.cdn.embed.avatars.get(avatarIndex);
|
|
||||||
}
|
}
|
||||||
return this.rest.cdn.avatars(this.id).get(this.avatar, options);
|
return this.rest.cdn.avatars(this.id).get(this.avatar, options);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user