forked from stoatchat/javascript-client-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServerRole.ts
More file actions
72 lines (63 loc) · 1.42 KB
/
Copy pathServerRole.ts
File metadata and controls
72 lines (63 loc) · 1.42 KB
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
import type { Role as APIRole } from "stoat-api";
import type { Client } from "../Client.js";
/**
* Server Role
*/
export class ServerRole {
protected client: Client;
protected serverId: string;
readonly id: string;
readonly name: string;
readonly permissions: {
a: bigint,
d: bigint
};
readonly colour?: string;
readonly hoist: boolean;
readonly rank: number;
/**
* Construct server role
* @param client Client
* @param serverId Server ID
* @param id Role ID
* @param data Role data
*/
constructor(client: Client, serverId: string, id: string, data: APIRole) {
this.client = client;
this.serverId = serverId;
this.id = id;
this.name = data.name;
this.permissions = {
a: BigInt(data.permissions.a),
d: BigInt(data.permissions.d)
};
this.colour = data.colour ?? undefined;
this.hoist = data.hoist || false;
this.rank = data.rank ?? 0;
}
/**
* Write to string as a role mention
* @returns Formatted String
*/
toString(): string {
return `<%${this.id}>`;
}
/**
* Server attached to this role
*/
get server() {
return this.client.servers.get(this.serverId);
}
/**
* Whether this role is assigned to our server member
*/
get assigned() {
return this.server?.member?.roles.includes(this.id) || false;
}
/**
* Delete this role
*/
delete() {
return this.server!.deleteRole(this.id);
}
}