forked from BFBAN/kook-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommandPack.ts
97 lines (80 loc) · 1.89 KB
/
commandPack.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
import { bot } from "../../bot";
import { filtration } from "../lib/util";
declare class baseCommandFactory {
}
// 白名单参数字段
const fieldConf = {
"v": { "min": 0, "max": 10, "type": "string" },
"type": {},
"time": {}
};
class baseCommandData {
public data: Map<any, any> = new Map<any, any>();
/**
* 取得指令第一参数
*/
public get mainValue(): any {
if (this.data && !this.data.has(0)) {
return undefined;
}
return this.data?.get(0);
};
/**
* 取得除第一位参数外字段
*/
public get other(): Map<any, any> {
let parameter: Map<any, any> = new Map();
this.data.forEach((value, key) => {
if (typeof key != "number") {
parameter.set(key, value);
}
});
return parameter;
}
get version(): string {
return this.other.get("v") ?? null;
};
get lang(): string {
return this.other.get("lang") ?? null;
}
get debug(): string {
return this.other.get("debug") ?? null;
}
}
class CommandFactory {
/***
* 打包ages的命令
* @param ages
*/
pack(ages: Array<any>): baseCommandData {
let command: baseCommandData = new baseCommandData();
try {
if (ages.length <= 0) {
throw "There is no value in the ages, please check";
}
for (let index = 0; index < ages.length; index++) {
let item = ages[index];
item.indexOf(":");
if (item.indexOf(":") >= 0) {
let splitString = item.split(":");
const key = splitString[0];
const val = splitString[1];
if (!key || !val) {
continue;
}
command.data?.set(key, filtration(val));
} else {
command.data?.set(index, filtration(item));
}
}
return command;
} catch (e) {
bot.logger.debug(e);
}
return command;
}
}
export default {
CommandFactory,
baseCommandData
};