This repository was archived by the owner on Sep 16, 2024. It is now read-only.
forked from TMBotDev/TMBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.ts
101 lines (92 loc) · 3.66 KB
/
App.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
import axios from "axios";
import { BotManager } from "./src/hooks/BotManager";
import { JsonConfigFileClass } from "./src/utils/DataUtils";
import { Logger } from "./src/entities/system/Logger";
import { PluginLoader } from "./src/plugins/PluginLoader";
let logo = String.raw`
__ _ _ __
/ / __ __ __ _ (_)___ (_)___/ /___
/ /__/ // // ' \ / // _ \ / // _ // -_)
/____/\_,_//_/_/_//_//_//_//_/ \_,_/ \__/
`;
let logger = new Logger("Luminide");
export let version = {
code: [1, 1, 0],
alhpa: true,
beta: false
};
let config = new JsonConfigFileClass("./config.json", JSON.stringify({
Bot: {
debug: false,
websocket: {
address: "ws://localhost:5555",
reconnect: 5,
reconnect_time: 4
},
log: {
file: "luminide-{Y}{M}{D}.log",
message: true,
notice: true,
},
//"ChannelSystem": false
}
}, null, 2));
process.on("uncaughtException", (err, _ori) => {
logger.error(`程序出现未捕获的异常:`);
logger.error(`Stack: ${err.stack}`);
logger.errorPrint("Bot_Unknown_Error", "Unknown", `调用堆栈:
\`\`\`txt
${err.stack}
\`\`\`
`);
});
// process.on("uncaughtExceptionMonitor", (err, _ori) => {
// logger.error(`程序出现未捕获的异常:`);
// logger.error(`Stack: ${err.stack}`);
// });
async function loadPlugins() {
await PluginLoader.loadAllPlugins();
}
async function load() {
logger.info(`§6${logo}`);
logger.info(`正在初始化 Luminide…`);
logger.info(`开始批量连接 OneBot…`);
let keys = config.getKeys(), l = keys.length, i = 0;
// console.log(conf.read())
while (i < l) {
let name = keys[i++];
// console.log(name)
try {
let options = config.get(name);
let websocket = options["websocket"]["address"],
reconnect = options["websocket"]["reconnect"],
reconnectTime = options["websocket"]["reconnect_time"];
if (websocket.indexOf("ws://") != 0) {
throw new Error(`WebSocket连接地址必须以 [ws://] 开头!`);
} else if (typeof (reconnect) != "number") {
throw new Error(`配置 websocket.reconnect 应为整数!`);
} else if (typeof (reconnectTime) != "number") {
throw new Error(`配置 websocket.reconnect_time 应为整数!`);
} else if (typeof (options["log"]["message"]) != "boolean") {
throw new Error(`配置 log.message 应为布尔值!`);
} else if (typeof (options["log"]["notice"]) != "boolean") {
throw new Error(`配置 log.notice 应为布尔值!`);
} else if (typeof (options["log"]["file"]) != "string" && options["log"]["file"] != null) {
throw new Error(`配置 log.file 应为字符串或 null!`);
}
// else if (typeof (options["ChannelSystem"]) != "boolean") {
// throw new Error(`配置 ChannelSystem 应为布尔值!`);
// }
await BotManager.newBot(name, websocket, reconnect, reconnectTime, options);
} catch (e) {
logger.error(`连接 [${name}] 失败!`);
logger.error((e as Error).stack);
return;
}
}
await loadPlugins();
logger.info('>> §6Luminide §f启动成功!');
logger.info(`>> §e当前版本: §f${version.code.join(".")}-${version.alhpa ? "§dAlpha" : version.beta ? "§3Beta" : "§eRelease"}`);
logger.info(`>> §7『 ${Math.random() <= 0.1 ? (await axios.get("https://v1.hitokoto.cn/?encode=text")).data : "代码跑起来我们再聊。"} 』`);
}
load();