-
Notifications
You must be signed in to change notification settings - Fork 1
/
SDK.ts
123 lines (115 loc) · 3.79 KB
/
SDK.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import { Proxy, getBotsResponse } from "./types/ReturnTypes";
import { resInfo } from "./types/ResInfoObj";
class AbstractRPC {
static ClassName = "";
static async _generateMethodCall(
methodname: string,
params: Record<string, any>
) {
const method = Object.entries(params);
let paramStr = method.length ? "?" : "";
method.forEach(([key, value]) => {
paramStr += `${key}=${value}&`;
});
const res = await fetch(
"/rpc/" + this.ClassName + "." + methodname + paramStr
);
const json = await res.json();
return json.result;
}
static async _generatePOSTMethodCall(methodname, params) {
const res = await fetch("/rpc/" + this.ClassName + "." + methodname, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(params),
});
const json = await res.json();
return json.result;
}
}
export class Bots extends AbstractRPC {
static ClassName = "Bots";
public static async getBots(): Promise<getBotsResponse> {
return await this._generateMethodCall("getBots", {});
}
public static async botCount(): Promise<number> {
return await this._generateMethodCall("botCount", {});
}
public static async addBot(
name: string,
password: string
): Promise<{ error: string } | number> {
return await this._generateMethodCall("addBot", { name, password });
}
public static async submitSteamGuardCode(
botIndex: number,
steamGuardCode: string
) {
return await this._generateMethodCall("submitSteamGuardCode", {
botIndex,
steamGuardCode,
});
}
public static async removeBot(name: string) {
return await this._generateMethodCall("removeBot", { name });
}
}
export class Settings extends AbstractRPC {
static ClassName = "Settings";
public static async getQuoteFile() {
return await this._generateMethodCall("getQuoteFile", {});
}
public static async setQuoteFile(quoteFile: string) {
return await this._generatePOSTMethodCall("setQuoteFile", { quoteFile });
}
public static async getPlugins() {
return await this._generateMethodCall("getPlugins", {});
}
public static async getProxies(): Promise<Proxy[]> {
return await this._generateMethodCall("getProxies", {});
}
public static async addProxy(proxy: Proxy) {
return await this._generatePOSTMethodCall("addProxy", { proxy });
}
public static tailConsoleFile() {
return new EventSource("/rpc/Settings.tailConsoleFile");
}
}
export class Comments extends AbstractRPC {
static ClassName = "Comment";
public static async comment(count: string, steamID: string, resInfo: resInfo) {
return await this._generateMethodCall("comment", { count, steamID, resInfo });
}
public static async commentCount() {
return await this._generateMethodCall("commentCount", {});
}
}
export class Docs extends AbstractRPC {
static ClassName = "Docs";
public static async getDocFolders() {
return await this._generateMethodCall("getDocFolders", {});
}
public static async getDocFile(file: string) {
return await this._generateMethodCall("getDocFile", { file });
}
public static async getLatestChangelog() {
return await this._generateMethodCall("getLatestChangelog", {});
}
}
export class Frontend extends AbstractRPC {
static ClassName = "Frontend";
public static async getSteamProfile(steamID: string) {
return await this._generateMethodCall("getSteamProfile", { steamID });
}
}
export class Commands extends AbstractRPC {
static ClassName = "Commands";
public static async getCommandList() {
return await this._generateMethodCall("getCommandList", {});
}
public static async executeCommand(command: string, args: any[], resInfo: resInfo) {
return await this._generateMethodCall("executeCommand", { command, args, resInfo });
}
}