From 9c42916cd20527e87dc24e878e15629382a77b58 Mon Sep 17 00:00:00 2001 From: minibox24 Date: Thu, 3 Dec 2020 11:27:19 +0900 Subject: [PATCH] add avatarURL defaultAvatarURL --- src/structures/user.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/structures/user.ts b/src/structures/user.ts index c0b002b..8d75147 100644 --- a/src/structures/user.ts +++ b/src/structures/user.ts @@ -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,20 @@ export class User extends Base { return `<@${this.id}>` } + avatarURL(format?: ImageFormats, size?: ImageSize, dynamic?: boolean) { + if (!format) format = 'webp' + if (!size) size = 512 + if (dynamic === undefined) dynamic = true + + return this.avatar + ? `${ImageURL(USER_AVATAR(this.id, dynamic ? this.avatar : this.avatar.replace('a_', '')), format, size)}` + : `${DEFAULT_USER_AVATAR(String(Number(this.discriminator) % 5))}.png` + } + + get defaultAvatarURL() { + return `${DEFAULT_USER_AVATAR(String(Number(this.discriminator) % 5))}.png` + } + constructor(client: Client, data: UserPayload) { super(client, data) this.id = data.id