-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
User.ts
78 lines (62 loc) · 1.63 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
import type { UserPayload, WSPayload } from "@guildedjs/api";
import { parseToStamp } from "../util";
import { Base } from "./Base";
import type { Client } from "./Client";
export class User extends Base<UserPayload> {
/** The name for this user */
name: string;
/** The type of this user */
readonly type: UserType;
/** The avatar image associated with this user */
avatar: string | null = null;
/** The banner image associated with this user */
banner: string | null = null;
/** When this user was created */
readonly _createdAt: number | null;
constructor(client: Client, data: UserPayload) {
super(client, data);
this.name = data.name;
this._createdAt = parseToStamp(data.createdAt)!;
this.type = data.type === "bot" ? UserType.Bot : UserType.User;
this._update(data);
}
get createdAt(): Date | null {
return this._createdAt ? new Date(this._createdAt) : null;
}
_update(data: Partial<UserPayload>): this {
if ("avatar" in data) {
this.avatar = data.avatar ?? null;
}
if ("banner" in data) {
this.banner = data.banner ?? null;
}
return this;
}
}
export class ClientUser extends User {
// User who has created this bot
readonly createdBy: string;
// The bot ID (not to be confused with the user ID) of this bot
readonly botId: string;
constructor(
client: Client,
data: WSPayload<"_WelcomeMessage">["user"] & {
createdBy: string;
botId: string;
},
) {
super(client, {
...data,
type: "bot",
});
this.createdBy = data.createdBy;
this.botId = data.botId;
}
fetch(): Promise<User> {
return this.client.users.fetchClient();
}
}
export enum UserType {
Bot = 0,
User = 1,
}