-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
User.ts
91 lines (83 loc) · 2.23 KB
/
User.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// deno-lint-ignore-file no-explicit-any
import { type Client } from "../Client.ts";
import { Base } from "./Base.ts";
import type {
GatewayActivity,
PresenceUpdateStatus,
UserFlags,
UserPremiumType,
} from "../../deps.ts";
export class User extends Base {
/**
* the user's id
*/
id: string;
/**
* the user's username, not unique across the platform
*/
username: string;
/**
* the user's 4-digit discord-tag
*/
discriminator: string;
/**
* the user's [avatar hash](https://discord.com/developers/docs/reference#image-formatting)
*/
avatar: string | null;
/**
* the [flags](https://discord.com/developers/docs/resources/user#user-object-user-flags) on a user's account
*/
flags?: UserFlags | undefined;
/**
* the [type of Nitro subscription](https://discord.com/developers/docs/resources/user#user-object-premium-types) on a user's account
*/
premium_type?: UserPremiumType | undefined;
/**
* the public [flags](https://discord.com/developers/docs/resources/user#user-object-user-flags) on a user's account
*/
public_flags?: UserFlags | undefined;
/**
* user's rich presence
*/
presence?:
| {
status?: PresenceUpdateStatus;
activities?: GatewayActivity[];
}
| undefined;
avatar_decoration?: string | null;
constructor(client: Client, props: Record<string, any>) {
super(client);
Object.assign(this, props);
// word can't explains how much i hate this
this.id = props.id;
this.username = props.username;
this.discriminator = props.discriminator;
this.avatar = props.avatar;
}
/**
* The URL to the user's avatar.
*/
get avatarUrl() {
const isAnimated = this.avatar && this.avatar.startsWith("a_");
return this.avatar
? `${this.client.cdnHost}/avatars/${this.id}/${this.avatar}${
isAnimated ? ".gif" : ".png"
}`
: this.defaultAvatarUrl;
}
/**
* The URL to the user's default avatar. (avatar that is used when user have no avatar)
*/
get defaultAvatarUrl() {
return `${this.client.cdnHost}/embed/avatars/${
parseInt(this.discriminator.substring(1)) % 5
}.png`;
}
/**
* User's tag
*/
get tag() {
return `${this.username}#${this.discriminator}`;
}
}