forked from stoatchat/javascript-client-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPublicBot.ts
More file actions
58 lines (51 loc) · 1.36 KB
/
Copy pathPublicBot.ts
File metadata and controls
58 lines (51 loc) · 1.36 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
import type { File as APIFile, PublicBot as APIPublicBot } from "stoat-api";
import type { Client } from "../Client.js";
import { Channel } from "./Channel.js";
import { File } from "./File.js";
import { Server } from "./Server.js";
/**
* Public Bot Class
*/
export class PublicBot {
#client: Client;
readonly id: string;
readonly username: string;
readonly avatar?: File;
readonly description?: string;
/**
* Construct Public Bot
* @param client Client
* @param data Data
*/
constructor(client: Client, data: APIPublicBot) {
this.#client = client;
this.id = data._id;
this.username = data.username;
this.avatar = data.avatar
? new File(client, {
_id: data.avatar,
tag: "avatars",
} as APIFile)
: undefined;
this.description = data.description!;
}
/**
* Add the bot to a server
* @param server Server
*/
addToServer(server: Server | string): void {
this.#client.api.post(`/bots/${this.id as ""}/invite`, {
server: server instanceof Server ? server.id : server,
});
}
/**
* Add the bot to a group
* @param group Group
*/
addToGroup(group: Channel | string): void {
// TODO: should use GroupChannel once that is added
this.#client.api.post(`/bots/${this.id as ""}/invite`, {
group: group instanceof Channel ? group.id : group,
});
}
}