forked from stoatchat/javascript-client-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServerBan.ts
More file actions
48 lines (42 loc) · 1.02 KB
/
Copy pathServerBan.ts
File metadata and controls
48 lines (42 loc) · 1.02 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
import type {
BannedUser as APIBannedUser,
ServerBan as APIServerBan,
MemberCompositeKey,
} from "stoat-api";
import type { Client } from "../Client.js";
import { BannedUser } from "./BannedUser.js";
import type { Server } from "./Server.js";
/**
* Server Ban
*/
export class ServerBan {
protected client: Client;
readonly id: MemberCompositeKey;
readonly reason?: string;
readonly user?: BannedUser;
/**
* Construct Server Ban
* @param client Client
* @param data Data
*/
constructor(client: Client, data: APIServerBan, user?: APIBannedUser) {
this.client = client;
this.id = data._id;
this.reason = data.reason!;
this.user = user ? new BannedUser(client, user) : undefined;
}
/**
* Server
*/
get server(): Server | undefined {
return this.client.servers.get(this.id.server);
}
/**
* Remove this server ban
*/
async pardon(): Promise<void> {
await this.client.api.delete(
`/servers/${this.id.server as ""}/bans/${this.id.user as ""}`,
);
}
}