-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
36 lines (31 loc) · 1.16 KB
/
index.js
File metadata and controls
36 lines (31 loc) · 1.16 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
import fs from "node:fs"
import { BotName, pluginName, PluginPackage } from "#GamePush.components"
const startTime = Date.now()
let apps = {}
if (BotName !== "karin") {
// 获取应用目录下的所有JS文件,排除task.js
const appsDir = `./plugins/${pluginName}/apps`
const files = fs
.readdirSync(appsDir)
.filter((file) => file.endsWith(".js") && file.toLowerCase() !== "task.js")
.filter((file) => file.toLowerCase() !== "base.js")
const loadPromises = files.map((file) => import(`./apps/${file}`))
const results = await Promise.allSettled(loadPromises)
results.forEach((result, index) => {
const file = files[index]
const name = file.replace(".js", "")
if (result.status === "fulfilled") {
const exports = Object.keys(result.value)
if (exports.length > 0) {
apps[name] = result.value[exports[0]]
}
} else {
logger.error(`载入插件错误:${logger.red(name)}`)
logger.error(result.reason)
}
})
}
export { apps }
logger.info("-----------------")
logger.info(`${pluginName} v${PluginPackage.version} 加载成功~ 耗时: ${Date.now() - startTime}ms`)
logger.info("-------^_^-------")