fix: avatarURL doesn't correctly return the default avatar (#119)

* fix(User|Member): avatarURL with default avatar

* Member#avatarURL fallback
This commit is contained in:
Drylozu 2022-10-12 11:23:30 -05:00 committed by GitHub
parent 388540e401
commit 6c6f982100
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 39 deletions

View File

@ -10,11 +10,7 @@ import type { AvatarOptions } from './user';
import { User } from './user';
import { Guild } from './guilds';
import { Util } from '../utils/util';
import {
USER_AVATAR,
USER_DEFAULT_AVATAR,
THREAD_USER,
} from '@biscuitland/api-types';
import { USER_AVATAR, THREAD_USER } from '@biscuitland/api-types';
import { Permissions } from './special/permissions';
/**
@ -180,24 +176,16 @@ export class Member implements Model {
return member;
}
/** gets the members's guild avatar, not to be confused with Member.user.avatarURL() */
/** gets the members's guild avatar if the user has one, gets the user's avatar instead */
avatarURL(options: AvatarOptions): string {
let url: string;
if (this.user.bot) {
if (!this.avatarHash) {
return this.user.avatarURL(options);
}
if (!this.avatarHash) {
url = USER_DEFAULT_AVATAR(Number(this.user.discriminator) % 5);
} else {
url = USER_AVATAR(
return Util.formatImageURL(USER_AVATAR(
this.user.id,
this.avatarHash
);
}
return Util.formatImageURL(url, options.size ?? 128, options.format);
), options.size ?? 128, options.format);
}
/**

View File

@ -121,7 +121,7 @@ export class Permissions implements BitField<bigint> {
}
}
static sum(permissions: Array<bigint | number>) {
static sum(permissions: (bigint | number)[]) {
return permissions.reduce((y, x) => BigInt(y) | BigInt(x), Permissions.None);
}

View File

@ -103,15 +103,14 @@ export class User implements Model {
/** gets the user's avatar */
avatarURL(options: AvatarOptions): string {
let url: string;
if (!this.avatarHash) {
url = USER_DEFAULT_AVATAR(Number(this.discriminator) % 5);
} else {
url = USER_AVATAR(this.id, this.avatarHash);
return USER_DEFAULT_AVATAR(Number(this.discriminator) % 5);
}
return Util.formatImageURL(url, options.size ?? 128, options.format);
return Util.formatImageURL(USER_AVATAR(
this.id,
this.avatarHash
), options.size ?? 128, options.format);
}
openDM(): Promise<DMChannel> {