-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
79 lines (73 loc) · 2.42 KB
/
index.js
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
import {Version} from "./components/index.js";
import YAML from "yaml";
import fs from "node:fs";
if (!global.segment) {
global.segment = (await import("oicq")).segment
}
if (!global.core) {
try {
global.core = (await import("oicq")).core
} catch (err) {
}
}
if (Bot?.logger?.info) {
Bot.logger.info("---------^_^---------");
Bot.logger.info(`[PaiMon-Plugin]:v${Version.version}初始化~`)
} else {
console.log(`[PaiMon-Plugin]:v${Version.version}初始化~`);
}
if (!fs.existsSync("./plugins/paimon-plugin/config/config/startCfg.yaml")) {
fs.writeFileSync("./plugins/paimon-plugin/config/config/startCfg.yaml", fs.readFileSync("./plugins/paimon-plugin/config/default_config/startCfg.yaml", "utf-8"), "utf-8")
Bot.logger.info("创建startCfg.yaml,可重启修改配置")
}
global.loadSandbox = YAML.parse(fs.readFileSync("./plugins/paimon-plugin/config/config/startCfg.yaml", "utf8")).sandbox;
let files = fs.readdirSync("./plugins/paimon-plugin/apps").filter(file => {
if (!loadSandbox && file.includes("sandbox")) {
return false;
}
return file.endsWith(".js")
});
let ret = [];
files.forEach(file => {
ret.push(import(`./apps/${file}`));
})
ret = await Promise.allSettled(ret);
global.isPmPlaying = {};
try {
fs.writeFileSync("./plugins/paimon-plugin/components/modules/code.js", "");
await import("./components/modules/loading.js");
logger.info("PaiMon-Plugin组件加载成功!!");
} catch (err) {
logger.info("PaiMon-Plugin组件加载失败!!");
logger.error(err);
}
global.commanding = false;
fs.watch("./plugins/paimon-plugin/components/modules/code.js", async (event, filename) => {
if (commanding) {
return;
}
global.commanding = true;
setTimeout(async () => {
try {
await import(`./components/modules/code.js?version=${new Date().getTime()}`);
} catch (err) {
ev.reply(err.toString())
}
Bot.logger.mark(`更新${filename}成功`);
global.commanding = false;
}, 500);
})
let apps = {}
for (let i in files) {
let name = files[i].replace(".js", "");
if (ret[i].status !== "fulfilled") {
logger.error(`载入插件错误:${logger.red(name)}`)
logger.error(ret[i].reason)
continue
}
apps[name] = ret[i].value[Object.keys(ret[i].value)[0]]
}
process.on("uncaughtException", err => {
Bot.logger.error(err)
})
export {apps}