-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtestExmpl.js
More file actions
88 lines (63 loc) · 2.1 KB
/
testExmpl.js
File metadata and controls
88 lines (63 loc) · 2.1 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
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
class CMenu {
constructor(id, name, regex) {
this._id = id;
this._name = name;
this._cmd = "!cmd_"+name.toLocaleLowerCase();
// if(regex === undefined)
regex = regex || name.toLocaleLowerCase() || false;
this._regex = (!regex || (Array.isArray(regex) && regex.length==0))? false: (regex instanceof RegExp)? regex: new RegExp("^("+( (Array.isArray(regex) && regex.length>0)? regex.join("|"): regex )+")$", "i")
// if(regex instanceof RegExp)
// this._regex = regex;
// else if(Array.isArray(regex) && regex.length>0)
// this._regex = new RegExp("^("+(regex.join("|"))+")$", "i");
// else if(regex)
// this._regex = new RegExp("^("+regex+")$", "i");
}
get cmd() {
return this._cmd;
}
get name() {
return this._name;
}
isHere(str) {
return this._regex? this._regex.test(str): false;
}
}
const MMenu = global.MMenu = {
Close: new CMenu(-1, "Close"),
None: new CMenu(0, "None"),
Start: new CMenu(1, "Start", [ "start", "старт" ]),
Restart: new CMenu(2, "Restart", [ "restart", "reset", "рестарт" ]),
Help: new CMenu(3, "Help", [ "help", "помощь" ]),
Menu: new CMenu(4, "Menu", [ "menu", "меню" ]),
Settings: new CMenu(5, "Settings", [ "settings", "настройки" ]),
QuestStart: new CMenu(6, "QuestStart", [ "to help", "помочь" ]),
ATask: new CMenu(7, "ATask", [ "" ]),
GetBalance: new CMenu(8, "GetBalance", [ "баланс", "balance" ]),
};
const hearCMenu = (menu, /* conditions, */ handle) => {
// if (typeof conditions == 'function') {
// handle = conditions;
// conditions = [ /* menu.name */ ];
// }
// if (!Array.isArray(conditions)) {
// conditions = [ conditions ];
// }
updates.hear(
[
(text, { state }) => ( state.command === menu.cmd ),
(text, { state }) => menu.isHere(text),
// ...conditions
],
handle
);
};
// hearCMenu(MMenu.Start, async (context, next)=> {
// //
// });
function getCmd(menu) {
return menu._cmd;
}
function itsMenu(menu, str) {
return menu.isHere(str);
}