forked from fengnz/fengdoorbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HandleAdminCommand.js
344 lines (293 loc) · 10.6 KB
/
HandleAdminCommand.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
function debugAdminCommand() {
debug()
}
function handleAdminCommand(body, paras, origParas) {
var share = getShareObject(body);
var payload = share.payload;
var chat = share.chat;
var callback_query_id = share.callback_query_id;
delete payload.parse_mode;
if (chat.type.indexOf("group") < 0) {
payload.text += "请将本机器人加入您的群中再使用此命令";
return payload;
}
if (!isAdminOrCreator(share.from.id, share.chat.id)) {
if (body.callback_query) {
var answerCallBackQueryPayload = {
"method": "answerCallbackQuery",
"callback_query_id": callback_query_id,
"text": "只有本群管理才可以使用此命令",
};
return answerCallBackQueryPayload;
} else {
payload.text += "只有本群管理才可以使用此命令";
addDeleteMeButton(payload);
return payload;
}
}
var groupSettings = getGroupSettings(chat);
if (paras[1]) {
switch (paras[1]) {
case 'notrobot':
//设置进群验证
if (paras[2]) {
if (paras[2] == "status") {
if (paras[3]) {
if (paras[3] == "on") {
if (gpSetFieldValue(chat, "notRobot.status", "on")) {
payload.text = "进群验证按钮启用成功";
groupSettings.notRobot.status = "on";
} else {
payload.text = "进群验证按钮启用失败";
}
} else {
if (gpSetFieldValue(chat, "notRobot.status", "off")) {
payload.text = "进群验证按钮禁用成功";
groupSettings.notRobot.status = "off";
} else {
payload.text = "进群验证按钮禁用失败";
}
}
payload.text += "\n";
}
if (groupSettings.notRobot.status && groupSettings.notRobot.status == "on") {
groupSettings.notRobot.status = "on";
payload.text += "进群验证按钮已打开, 点击以下按钮关闭";
} else {
groupSettings.notRobot.status = "off";
payload.text += "进群验证按钮已关闭, 点击以下按钮打开";
}
}
if (paras[2] == "timeout") {
if (paras[3]) {
if (/[0-9]+/.test(paras[3] + "")) {
var timeout = parseInt(paras[3]);
if (gpSetFieldValue(chat, "notRobot.timeout", timeout)) {
payload.text += "进群验证倒计时已经设置为: ";
payload.text += timeout;
groupSettings.notRobot.timeout = timeout;
payload.text += "\n";
payload.text += "注意,倒计时踢人需要在谷歌GAS设置触发器调用 removePendingUsers() 函数, 如果无法自动踢人请联系机器人服务器架设者";
if (timeout == 0) {
payload.text += "倒计时设置为0时,将不会自动踢除未验证的用户";
}
} else {
payload.text = "进群验证倒计时设置失败";
payload.text += "\n";
}
} else {
payload.text += "倒计时只能是数字,单位为妙钟";
payload.text += "\n";
}
}
}
} else {
payload.text += "使用以下命令设置进群验证";
payload.text += "\n";
payload.text += "\n";
payload.text += "/admin notRobot status - 开关进群验证,值可以是 on 或 off";
payload.text += "\n";
payload.text += "/admin notRobot timeout - 设置验证倒计时,可以是任何正数(秒)";
payload.text += "\n";
payload.text += "超过这个时间还没验证的用户会被踢出群. 设置成0则不踢";
payload.text += "\n";
payload.text += "注意! 需要在谷歌脚本使用触发器定期踢出未验证的用户";
payload.text += "\n";
}
setButtonsForAdminNotRobot(payload, groupSettings);
break;
case 'welcome':
if (paras[3]) {
var value = "off";
if (paras[3] === "on") {
value = "on";
}
switch (paras[2]) {
case "customtext":
// custom text uses different value rather than on or off
value = origParas.splice(3).join(" ");
case "status":
case "desc":
case "pinned":
case "killme":
case "custom":
var success = gpSetFieldValue(chat, "welcome." + paras[2], value);
if (success) {
payload.text += "设置成功 - ";
payload.text += paras[2] + ": " + value;
payload.text += "\n";
groupSettings.welcome[paras[2]] = value;
} else {
payload.text += "设置失败";
payload.text += "\n";
}
break;
default:
payload.text += "不支持的参数\n";
break;
}
}
var status = {};
status["on"] = "【开】";
status["off"] = "【关】";
var toggle = {};
toggle["on"] = "off";
toggle["off"] = "on";
if (!paras[3] && paras[2] === "customtext") {
payload.text += '明白,要设置自定义欢迎词,请回复本消息把欢迎词发给我,你可以在欢迎词中使用以下变量:\n';
payload.text += '$(desc) - 代表群描述\n';
payload.text += '$(pinnedMessage) - 代表置顶消息\n';
payload.text += '$(pinnedId) - 代表置顶消息的ID\n';
payload.text += '$(pinnedUrl) - 代表置顶消息的链接(只有公开群有)\n';
payload.text += '$(newMemberName) - 代表新成员的名字\n';
} else {
payload.text += '在这里可以打开欢迎词,欢迎词可选包含群描述和置顶消息,如果30秒自毁开启,欢迎词将在30秒后被删除\n';
payload.text += '请问还有什么我可以帮你的吗?';
}
var buttons = [
{
text: "切换欢迎词" + status[groupSettings.welcome.status],
callback_data: "admin:welcome:status:" + toggle[groupSettings.welcome.status]
},
];
if (groupSettings.welcome.status === "on") {
if (groupSettings.welcome.custom === "on") {
buttons.push(
{
text: "自定义消息" + status[groupSettings.welcome.custom],
callback_data: "admin:welcome:custom:" + toggle[groupSettings.welcome.custom]
}
);
buttons.push(
{
text: "编辑自定义消息",
callback_data: "admin:welcome:customtext"
}
);
} else {
buttons.push(
{
text: "群描述" + status[groupSettings.welcome.desc],
callback_data: "admin:welcome:desc:" + toggle[groupSettings.welcome.desc]
}
);
buttons.push(
{
text: "置顶消息" + status[groupSettings.welcome.pinned],
callback_data: "admin:welcome:pinned:" + toggle[groupSettings.welcome.pinned]
}
);
buttons.push(
{
text: "自定义消息" + status[groupSettings.welcome.custom],
callback_data: "admin:welcome:custom:" + toggle[groupSettings.welcome.custom]
}
);
}
buttons.push(
{
text: "30秒自毁" + status[groupSettings.welcome.killme],
callback_data: "admin:welcome:killme:" + toggle[groupSettings.welcome.killme]
}
);
}
buttons.push(
{
text: "返回主菜单",
callback_data: "admin"
}
);
var inlineKeyboardMarkup = generateInlineKeyboardMarkup(buttons, 2);
payload.reply_markup = inlineKeyboardMarkup;
break;
default:
payload.text = "欢迎使用Admin命令\n"
+ "\n"
+ "输入 admin welcome 设置欢迎词"
+ "\n"
+ "输入 admin notRobot 设置进群验证"
;
break;
}
} else {
payload.text += "欢迎来到机器人设置\n";
payload.text += "有什么我可以帮您的吗?\n";
var buttons = [
{
text: "欢迎词设置",
callback_data: "admin:welcome"
},
{
text: "进群验证",
callback_data: "admin:notrobot"
}
];
var inlineKeyboardMarkup = generateInlineKeyboardMarkup(buttons, 2);
payload.reply_markup = inlineKeyboardMarkup;
}
return payload;
}
function setButtonsForAdminNotRobot(payload, groupSettings) {
var status = {};
status["on"] = "【开】";
status["off"] = "【关】";
var toggle = {};
toggle["on"] = "off";
toggle["off"] = "on";
var buttons = [
];
buttons.push(
{
text: "进群验证按钮" + status[groupSettings.notRobot.status],
callback_data: "admin:notrobot:status:" + toggle[groupSettings.notRobot.status]
}
);
if (groupSettings.notRobot.status == "on") {
buttons.push(
{
text: "踢出倒计时【" + groupSettings.notRobot.timeout + "秒】" + "✅",
callback_data: "admin:notrobot:timeout:" + groupSettings.notRobot.timeout,
}
);
if (groupSettings.notRobot.timeout !== 0) {
buttons.push(
{
text: "踢出倒计时【" + 0 + "秒】",
callback_data: "admin:notrobot:timeout:" + 0,
}
);
}
if (groupSettings.notRobot.timeout !== 120) {
buttons.push(
{
text: "踢出倒计时【" + 120 + "秒】",
callback_data: "admin:notrobot:timeout:" + 120,
}
);
}
if (groupSettings.notRobot.timeout !== 3600) {
buttons.push(
{
text: "踢出倒计时【" + 1 + "小时】",
callback_data: "admin:notrobot:timeout:" + 3600,
}
);
}
if (groupSettings.notRobot.timeout !== 3600 * 24) {
buttons.push(
{
text: "踢出倒计时【" + 1 + "天】",
callback_data: "admin:notrobot:timeout:" + 3600 * 24,
}
);
}
}
buttons.push(
{
text: "返回主菜单",
callback_data: "admin"
}
);
var inlineKeyboardMarkup = generateInlineKeyboardMarkup(buttons, 2);
payload.reply_markup = inlineKeyboardMarkup;
}