This commit is contained in:
DjDeveloperr 2020-12-05 12:40:06 +05:30
commit 9c67ff6c84
2 changed files with 14 additions and 1 deletions

View File

@ -10,4 +10,4 @@ export const ImageURL = (
if (url.includes('a_')) {
return `${url}.${format === undefined ? 'gif' : format}?size=${size}`
} else return `${url}.${format === 'gif' ? 'png' : format}?size=${size}`
}
}

View File

@ -2,6 +2,9 @@ import { Client } from '../models/client.ts'
import { UserPayload } from '../types/user.ts'
import { UserFlagsManager } from '../utils/userFlags.ts'
import { Base } from './base.ts'
import { ImageURL } from './cdn.ts'
import { ImageSize, ImageFormats } from '../types/cdn.ts'
import { DEFAULT_USER_AVATAR, USER_AVATAR } from '../types/endpoint.ts'
export class User extends Base {
id: string
@ -37,6 +40,16 @@ export class User extends Base {
return `<@${this.id}>`
}
avatarURL(format: ImageFormats = 'png', size: ImageSize = 512): string {
return this.avatar != null
? `${ImageURL(USER_AVATAR(this.id, this.avatar), format, size)}`
: `${DEFAULT_USER_AVATAR(String(Number(this.discriminator) % 5))}.png`
}
get defaultAvatarURL(): string {
return `${DEFAULT_USER_AVATAR(String(Number(this.discriminator) % 5))}.png`
}
constructor(client: Client, data: UserPayload) {
super(client, data)
this.id = data.id