-
Notifications
You must be signed in to change notification settings - Fork 10
/
mod.ts
executable file
路62 lines (55 loc) 路 1.81 KB
/
mod.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
import { parse } from "https://deno.land/std@0.137.0/encoding/yaml.ts";
import { readJson } from "./json.ts";
let botwayConfigPath: any = Deno.env.get("HOME") + "/.botway" + "/botway.json";
if (Deno.build.os == "windows") {
botwayConfigPath =
Deno.env.get("USERPROFILE") + "\\.botway" + "\\botway.json";
}
const botwayConfig: any = await readJson(botwayConfigPath);
const botConfig: any = parse(await Deno.readTextFile("./.botway.yaml"));
const getBotInfo = (value: string) => {
return botConfig["bot"][value];
};
export const getToken = () => {
if (getBotInfo("lang") != "deno") {
console.log("ERROR: Botway is not running in Deno");
} else {
try {
return botwayConfig["botway"]["bots"][getBotInfo("name")]["bot_token"];
} catch (err: any) {
console.log(err.stack || String(err));
}
}
};
export const getAppId = () => {
if (getBotInfo("lang") != "deno") {
console.log("ERROR: Botway is not running in Deno");
} else {
try {
if (getBotInfo("type") == "slack") {
return botwayConfig["botway"]["bots"][getBotInfo("name")][
"bot_app_token"
];
} else {
return botwayConfig["botway"]["bots"][getBotInfo("name")]["bot_app_id"];
}
} catch (err: any) {
console.log(err.stack || String(err));
}
}
};
export const getGuildId = (serverName: string) => {
if (getBotInfo("lang") != "deno") {
console.log("ERROR: Botway is not running in Deno");
} else if (getBotInfo("type") != "discord") {
console.log("ERROR: Botway is not running in Discord");
} else {
try {
return botwayConfig["botway"]["bots"][getBotInfo("name")]["guilds"][
serverName
]["server_id"];
} catch (err: any) {
console.log(err.stack || String(err));
}
}
};