-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.ts
More file actions
39 lines (33 loc) · 1.19 KB
/
index.ts
File metadata and controls
39 lines (33 loc) · 1.19 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
37
38
39
import { init } from "./init";
import { findOpts } from "./lib/findOpts";
import { rlPrompt } from "./plugins/admin";
init().then(() => {
rl.on("line", async (input: string) => {
//log.debug(input);
while (input.includes(" ")) {
input = input.replaceAll(" ", " ");
}
const opts = input.trim().split(" ");
const opt = await findOpts(opts[0]);
if (opt.path == "err") {
if (input)
log.error(`未找到指定命令,请重试!`);
} else {
if (opts.length < 2) opts.push("");
try {
const plugin = await import(`./plugins/${opt.path}.ts`);
if (typeof plugin[opt.fnc] == "function") {
await (plugin[opt.fnc] as PluginFnc)(opts.slice(1)).catch(err => {
log.error(err);
});
} else {
log.error(`not found function ${opt.fnc}() at "${global._path}/src/plugins/${opt.path}.ts"`);
}
} catch (err) {
log.error(err);
}
}
rlPrompt();
});
});
type PluginFnc = (msg: string[]) => Promise<any>