-
Notifications
You must be signed in to change notification settings - Fork 2
/
菜单自定义.js
163 lines (132 loc) · 3.7 KB
/
菜单自定义.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
// [rule: 菜单]
// [rule: 菜单管理]
// github仓库:zhacha222/sillyGirljs
// 有问题tg频道留言 https://t.me/silly_MaiArk
let right = ""
let left = ""
let str = ""
let menutext = ""
let n = ""
let menuStr = ""
var GetContent=GetContent()
try{
var menu1 = bucketGet("sillyGirl", "menu")
str=JSON.parse(menu1)}catch(e){str = []}
function choose(){ //命令筛选
if(GetContent=="菜单"){
menu()
}else if (GetContent=="菜单管理"){
if (isAdmin) {
manager()
}
return;
}
}
function manager() {
for(var i=0,j=1;i<str.length;i++,j++){
for (var key in str[i]) {
menutext += j+'.' + key + ` - ` + str[i][key]+`\n`
}
}
sendText(`请选择对象进行编辑:(-删除指令,0增加指令,q退出, wq保存)\n`+menutext)
msg=input()
if(msg==0){
add()
return manager()
}else if (0>msg&&msg>-j){
n = msg.split(`-`)[1] -1
del()
return manager()
}else if (msg == "q" || msg == "Q" || msg == "" ) {
sendText("已退出设置。")
return;
}else if (msg == "wq" ) {
bucketSet("sillyGirl", "menu", JSON.stringify(str))
sendText("已保存修改")
return;
}else {
sendText('指令错误,请重新输入:')
sleep(600)
menutext = ""
return manager()
}
}
function add(){
sendText(`请输入新增指令名称:`);
var order = input();
sendText(`请输入用法示例:`);
var answer = input();
datar = {"name": ""}
var new_key = order
var old_key = "name"
datar.name = answer
datar[new_key] = datar[old_key];
delete datar[old_key];
str.push(datar)
menutext = ""
}
function del(){
str.splice(n,1)
menutext = ""
}
function menu() {
var aa = bucketGet("sillyGirl", "menu")
var menu=JSON.parse(aa)
var menuStr = ""
var max = 6;
//排序菜单多在下少在上
var len = menu.length;
for (let i = 0; i < len; i++) {
for (let j = 0; j < len - 1 - i; j++) {
// 相邻元素两两对比,元素交换,大的元素交换到后面
var key1;
var key2;
for (key1 in menu[j]) {
}
for (key2 in menu[j + 1]) {
}
if (key1.length > key2.length) {
var temp = menu[j];
menu[j] = menu[j + 1];
menu[j + 1] = temp;
}
}
}
//获取最大长度
for (const key in menu[menu.length - 1]) {
if (key.length >= max) {
max = key.length + 1;
}
}
for (let index = 0; index < max; index++) {
if (index == Math.floor(max / 2)) {
menuStr += "—机器人菜单—";
} else {
menuStr += "—";
}
}
menuStr += "\n";
for (let index = 0; index < max; index++) {
if (index == Math.floor(max / 2)) {
menuStr += "右面为用法示例";
} else {
menuStr += "—";
}
}
menuStr += "\n";
menu.forEach(item => {
for (const key in item) {
left = key;
right = item[key];
if (key.length < max) {
for (let index = 0; index < max - key.length; index++) {
left += "—";
}
}
menuStr += left + right + "\n"
}
});
sendText(menuStr)
return
}
choose()