@alemonjs/qq-bot 2.1.33 → 2.1.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -8
- package/dist/assets/index.css +1 -1
- package/dist/assets/index.js +12 -5
- package/dist/index.html +1 -1
- package/lib/config.d.ts +44 -19
- package/lib/config.js +39 -35
- package/lib/desktop.d.ts +4 -1
- package/lib/desktop.js +53 -57
- package/lib/format.d.ts +26 -5
- package/lib/format.js +84 -101
- package/lib/hook.d.ts +82 -65
- package/lib/hook.js +35 -32
- package/lib/index.d.ts +6 -4
- package/lib/index.js +13 -16
- package/lib/index.webhook.d.ts +4 -1
- package/lib/index.webhook.js +12 -14
- package/lib/index.websoket.d.ts +6 -3
- package/lib/index.websoket.js +131 -41
- package/lib/message/AT_MESSAGE_CREATE.d.ts +36 -33
- package/lib/message/AT_MESSAGE_CREATE.js +1 -1
- package/lib/message/CHANNEL_CREATE.d.ts +17 -14
- package/lib/message/CHANNEL_CREATE.js +1 -1
- package/lib/message/CHANNEL_DELETE.d.ts +22 -14
- package/lib/message/CHANNEL_DELETE.js +1 -1
- package/lib/message/CHANNEL_UPDATE.d.ts +22 -14
- package/lib/message/CHANNEL_UPDATE.js +1 -1
- package/lib/message/DIRECT_MESSAGE_CREATE.d.ts +35 -27
- package/lib/message/DIRECT_MESSAGE_CREATE.js +1 -1
- package/lib/message/DIRECT_MESSAGE_DELETE.d.ts +23 -15
- package/lib/message/DIRECT_MESSAGE_DELETE.js +1 -1
- package/lib/message/ERROR.d.ts +4 -1
- package/lib/message/ERROR.js +1 -1
- package/lib/message/GUILD_CREATE.d.ts +22 -14
- package/lib/message/GUILD_CREATE.js +1 -1
- package/lib/message/GUILD_DELETE.d.ts +22 -14
- package/lib/message/GUILD_DELETE.js +1 -1
- package/lib/message/GUILD_MEMBER_ADD.d.ts +21 -13
- package/lib/message/GUILD_MEMBER_ADD.js +1 -1
- package/lib/message/GUILD_MEMBER_REMOVE.d.ts +21 -13
- package/lib/message/GUILD_MEMBER_REMOVE.js +1 -1
- package/lib/message/GUILD_MEMBER_UPDATE.d.ts +21 -13
- package/lib/message/GUILD_MEMBER_UPDATE.js +1 -1
- package/lib/message/GUILD_UPDATE.d.ts +22 -14
- package/lib/message/GUILD_UPDATE.js +1 -1
- package/lib/message/INTERACTION_CREATE.d.ts +52 -44
- package/lib/message/INTERACTION_CREATE.js +1 -1
- package/lib/message/MESSAGE_CREATE.d.ts +12 -1
- package/lib/message/MESSAGE_CREATE.js +1 -1
- package/lib/message/MESSAGE_DELETE.d.ts +12 -1
- package/lib/message/MESSAGE_DELETE.js +1 -1
- package/lib/message/MESSAGE_REACTION_ADD.d.ts +15 -12
- package/lib/message/MESSAGE_REACTION_ADD.js +1 -1
- package/lib/message/MESSAGE_REACTION_REMOVE.d.ts +15 -12
- package/lib/message/MESSAGE_REACTION_REMOVE.js +1 -1
- package/lib/message/PUBLIC_MESSAGE_DELETE.d.ts +20 -13
- package/lib/message/PUBLIC_MESSAGE_DELETE.js +1 -1
- package/lib/message/READY.d.ts +11 -5
- package/lib/message/READY.js +1 -1
- package/lib/message/group/C2C_MESSAGE_CREATE.d.ts +18 -15
- package/lib/message/group/C2C_MESSAGE_CREATE.js +1 -1
- package/lib/message/group/C2C_MSG_RECEIVE.d.ts +13 -3
- package/lib/message/group/C2C_MSG_RECEIVE.js +1 -1
- package/lib/message/group/C2C_MSG_REJECT.d.ts +9 -3
- package/lib/message/group/C2C_MSG_REJECT.js +1 -1
- package/lib/message/group/FRIEND_ADD.d.ts +13 -3
- package/lib/message/group/FRIEND_ADD.js +1 -1
- package/lib/message/group/FRIEND_DEL.d.ts +9 -3
- package/lib/message/group/FRIEND_DEL.js +1 -1
- package/lib/message/group/GROUP_ADD_ROBOT.d.ts +23 -4
- package/lib/message/group/GROUP_ADD_ROBOT.js +1 -1
- package/lib/message/group/GROUP_AT_MESSAGE_CREATE.d.ts +38 -32
- package/lib/message/group/GROUP_AT_MESSAGE_CREATE.js +1 -1
- package/lib/message/group/GROUP_DEL_ROBOT.d.ts +19 -4
- package/lib/message/group/GROUP_DEL_ROBOT.js +1 -1
- package/lib/message/group/GROUP_JOIN_REQUEST.d.ts +83 -22
- package/lib/message/group/GROUP_JOIN_REQUEST.js +1 -1
- package/lib/message/group/GROUP_MEMBER_ADD.d.ts +8 -5
- package/lib/message/group/GROUP_MEMBER_ADD.js +1 -1
- package/lib/message/group/GROUP_MEMBER_REMOVE.d.ts +8 -5
- package/lib/message/group/GROUP_MEMBER_REMOVE.js +1 -1
- package/lib/message/group/GROUP_MESSAGE_CREATE.d.ts +38 -32
- package/lib/message/group/GROUP_MESSAGE_CREATE.js +1 -1
- package/lib/message/group/GROUP_MSG_RECEIVE.d.ts +14 -4
- package/lib/message/group/GROUP_MSG_RECEIVE.js +1 -1
- package/lib/message/group/GROUP_MSG_REJECT.d.ts +10 -4
- package/lib/message/group/GROUP_MSG_REJECT.js +1 -1
- package/lib/message/group/MESSAGE_AUDIT_PASS.d.ts +12 -6
- package/lib/message/group/MESSAGE_AUDIT_PASS.js +1 -1
- package/lib/message/group/MESSAGE_AUDIT_REJECT.d.ts +12 -6
- package/lib/message/group/MESSAGE_AUDIT_REJECT.js +1 -1
- package/lib/register.d.ts +12 -9
- package/lib/register.js +1246 -1404
- package/lib/sdk/api.d.ts +937 -306
- package/lib/sdk/api.js +1481 -893
- package/lib/sdk/client.webhook.d.ts +25 -8
- package/lib/sdk/client.webhook.js +185 -189
- package/lib/sdk/client.websoket.d.ts +31 -9
- package/lib/sdk/client.websoket.js +369 -392
- package/lib/sdk/config.d.ts +6 -2
- package/lib/sdk/config.js +9 -6
- package/lib/sdk/instance.d.ts +11 -3
- package/lib/sdk/instance.js +72 -84
- package/lib/sdk/intents.d.ts +89 -3
- package/lib/sdk/intents.js +116 -33
- package/lib/sdk/message.d.ts +7 -4
- package/lib/sdk/message.group.d.ts +38 -35
- package/lib/sdk/message.group.js +1 -1
- package/lib/sdk/message.guild.d.ts +40 -37
- package/lib/sdk/message.guild.js +1 -1
- package/lib/sdk/message.js +1 -1
- package/lib/sdk/message.public.d.ts +8 -5
- package/lib/sdk/message.public.js +1 -1
- package/lib/sdk/qr-auth.d.ts +55 -0
- package/lib/sdk/qr-auth.js +166 -0
- package/lib/sdk/registry.d.ts +34 -24
- package/lib/sdk/registry.js +134 -114
- package/lib/sdk/session.d.ts +19 -15
- package/lib/sdk/session.js +51 -54
- package/lib/sdk/typing.d.ts +410 -184
- package/lib/sdk/typing.js +1 -1
- package/lib/sdk/webhook.secret.d.ts +33 -13
- package/lib/sdk/webhook.secret.js +50 -36
- package/lib/sends.d.ts +42 -25
- package/lib/sends.js +519 -541
- package/lib/types.d.ts +52 -41
- package/lib/types.js +1 -1
- package/lib/upload.d.ts +47 -18
- package/lib/upload.js +80 -51
- package/lib/utils.d.ts +9 -1
- package/lib/utils.js +10 -5
- package/package.json +10 -7
- package/LICENSE +0 -21
package/lib/register.js
CHANGED
|
@@ -1,1408 +1,1250 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
1
|
+
import { getIdentity, getMaster, getQQBotConfig, platform } from "./config.js";
|
|
2
|
+
import { chunkedUpload } from "./upload.js";
|
|
3
|
+
import { AT_MESSAGE_CREATE, C2C_MESSAGE_CREATE, DIRECT_MESSAGE_CREATE, GROUP_AT_MESSAGE_CREATE, MESSAGE_CREATE } from "./sends.js";
|
|
4
|
+
import { FormatEvent, ResultCode, cbpPlatform, createResult, logger } from "alemonjs";
|
|
5
|
+
import { createHash } from "node:crypto";
|
|
6
|
+
import { basename } from "node:path";
|
|
7
|
+
import { readFile, stat } from "node:fs/promises";
|
|
8
8
|
|
|
9
|
+
//#region src/register.ts
|
|
10
|
+
/**
|
|
11
|
+
* notice 事件中平台支持以 event_id 被动回复的 tag
|
|
12
|
+
* (QQ 官方「发送消息」文档:群聊支持 GROUP_ADD_ROBOT / GROUP_MSG_RECEIVE,
|
|
13
|
+
* 单聊支持 C2C_MSG_RECEIVE / FRIEND_ADD;event_id 取网关信封 payload.id)
|
|
14
|
+
*/
|
|
15
|
+
const GROUP_EVENT_REPLY_TAGS = /* @__PURE__ */ new Set(["GROUP_ADD_ROBOT", "GROUP_MSG_RECEIVE"]);
|
|
16
|
+
const C2C_EVENT_REPLY_TAGS = /* @__PURE__ */ new Set(["C2C_MSG_RECEIVE", "FRIEND_ADD"]);
|
|
17
|
+
/**
|
|
18
|
+
* notice / member 类事件 tag:事件不含平台认可的被动回复 msg_id(MessageId 为合成值或缺省),
|
|
19
|
+
* 消息发送统一降级为群主动消息(仅携带 ChannelId,不透传 MessageId)。
|
|
20
|
+
* 事件回复 tag 也在其中:缺失 event_id 时同样落到主动消息
|
|
21
|
+
*/
|
|
22
|
+
const GROUP_NOTICE_TAGS = /* @__PURE__ */ new Set([
|
|
23
|
+
"GROUP_ADD_ROBOT",
|
|
24
|
+
"GROUP_DEL_ROBOT",
|
|
25
|
+
"GROUP_MEMBER_ADD",
|
|
26
|
+
"GROUP_MEMBER_REMOVE",
|
|
27
|
+
"GROUP_JOIN_REQUEST",
|
|
28
|
+
"GROUP_MSG_RECEIVE",
|
|
29
|
+
"GROUP_MSG_REJECT",
|
|
30
|
+
"MESSAGE_AUDIT_PASS",
|
|
31
|
+
"MESSAGE_AUDIT_REJECT"
|
|
32
|
+
]);
|
|
33
|
+
/**
|
|
34
|
+
* 好友 / C2C notice 类事件 tag:同上,降级为私聊主动消息(仅携带 UserId)
|
|
35
|
+
*/
|
|
36
|
+
const C2C_NOTICE_TAGS = /* @__PURE__ */ new Set([
|
|
37
|
+
"C2C_MSG_RECEIVE",
|
|
38
|
+
"C2C_MSG_REJECT",
|
|
39
|
+
"FRIEND_ADD",
|
|
40
|
+
"FRIEND_DEL"
|
|
41
|
+
]);
|
|
9
42
|
const register = (client, options) => {
|
|
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
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
.postRichMediaByUser(userId, { file_type: fileType, url: params?.url, file_data: params?.data })
|
|
1215
|
-
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
1216
|
-
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
1217
|
-
consume([res]);
|
|
1218
|
-
}
|
|
1219
|
-
else if (data.action === 'media.upload') {
|
|
1220
|
-
const target = normalizeTarget(data.payload.target);
|
|
1221
|
-
if (!target) {
|
|
1222
|
-
consume([createResult(ResultCode.Warn, 'QQ media.upload requires target', null)]);
|
|
1223
|
-
return;
|
|
1224
|
-
}
|
|
1225
|
-
const res = await uploadMedia(target, data.payload.params || {})
|
|
1226
|
-
.then(value => createResult(ResultCode.Ok, data.action, value))
|
|
1227
|
-
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
1228
|
-
consume([res]);
|
|
1229
|
-
}
|
|
1230
|
-
else if (data.action === 'media.send') {
|
|
1231
|
-
const target = normalizeTarget(data.payload.target);
|
|
1232
|
-
if (!target) {
|
|
1233
|
-
consume([createResult(ResultCode.FailParams, 'media.send 缺少 target', null)]);
|
|
1234
|
-
return;
|
|
1235
|
-
}
|
|
1236
|
-
if (!validateTargetBot(target)) {
|
|
1237
|
-
consume([createResult(ResultCode.FailParams, `BotId ${target.BotId} is not active`, null)]);
|
|
1238
|
-
return;
|
|
1239
|
-
}
|
|
1240
|
-
const params = data.payload.params || {};
|
|
1241
|
-
if (params.fileId) {
|
|
1242
|
-
const send = target.scope === 'group'
|
|
1243
|
-
? client.groupOpenMessages(target.targetId, { msg_type: 7, content: params.content || '', media: { file_info: params.fileId } })
|
|
1244
|
-
: target.scope === 'c2c'
|
|
1245
|
-
? client.usersOpenMessages(target.targetId, { msg_type: 7, content: params.content || '', media: { file_info: params.fileId } })
|
|
1246
|
-
: null;
|
|
1247
|
-
if (!send) {
|
|
1248
|
-
consume([createResult(ResultCode.Warn, 'QQ media.send only supports group and c2c targets', null)]);
|
|
1249
|
-
return;
|
|
1250
|
-
}
|
|
1251
|
-
const res = await send
|
|
1252
|
-
.then(value => createResult(ResultCode.Ok, data.action, { id: value.id }))
|
|
1253
|
-
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
1254
|
-
consume([res]);
|
|
1255
|
-
return;
|
|
1256
|
-
}
|
|
1257
|
-
const upload = await uploadMedia(target, params)
|
|
1258
|
-
.then(value => value.fileId)
|
|
1259
|
-
.catch(error => {
|
|
1260
|
-
consume([createResult(ResultCode.Fail, data.action, error)]);
|
|
1261
|
-
return null;
|
|
1262
|
-
});
|
|
1263
|
-
if (!upload) {
|
|
1264
|
-
return;
|
|
1265
|
-
}
|
|
1266
|
-
await onactions({ action: 'media.send', payload: { target, params: { ...params, fileId: upload, url: undefined, data: undefined, filePath: undefined } } }, consume);
|
|
1267
|
-
}
|
|
1268
|
-
else if (data.action === 'connection.status') {
|
|
1269
|
-
const status = client.getConnectionStatus();
|
|
1270
|
-
consume([
|
|
1271
|
-
createResult(ResultCode.Ok, data.action, {
|
|
1272
|
-
Platform: platform,
|
|
1273
|
-
state: status.state,
|
|
1274
|
-
bots: [{ BotId: botId, ...status }]
|
|
1275
|
-
})
|
|
1276
|
-
]);
|
|
1277
|
-
}
|
|
1278
|
-
else if (data.action === 'media.upload.prepare') {
|
|
1279
|
-
const userId = getUserId();
|
|
1280
|
-
const groupId = getGroupOpenId();
|
|
1281
|
-
const res = await (userId ? client.usersUploadPrepare(userId, data.payload.params) : client.groupUploadPrepare(groupId, data.payload.params))
|
|
1282
|
-
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
1283
|
-
.catch(err => createResult(ResultCode.Fail, data.action, err?.response?.data ?? err?.message ?? err));
|
|
1284
|
-
consume([res]);
|
|
1285
|
-
}
|
|
1286
|
-
else if (data.action === 'media.upload.part.finish') {
|
|
1287
|
-
const userId = getUserId();
|
|
1288
|
-
const groupId = getGroupOpenId();
|
|
1289
|
-
const res = await (userId ? client.usersUploadPartFinish(userId, data.payload.params) : client.groupUploadPartFinish(groupId, data.payload.params))
|
|
1290
|
-
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
1291
|
-
.catch(err => createResult(ResultCode.Fail, data.action, err?.response?.data ?? err?.message ?? err));
|
|
1292
|
-
consume([res]);
|
|
1293
|
-
}
|
|
1294
|
-
else if (data.action === 'media.upload.chunked') {
|
|
1295
|
-
const userId = getUserId();
|
|
1296
|
-
const groupId = getGroupOpenId();
|
|
1297
|
-
const params = data.payload.params ?? {};
|
|
1298
|
-
const res = await chunkedUpload(client, userId ? 'user' : 'group', userId || groupId, params.file ?? params.file_path, {
|
|
1299
|
-
file_type: params.file_type ?? 1,
|
|
1300
|
-
file_name: params.file_name,
|
|
1301
|
-
srv_send_msg: params.srv_send_msg
|
|
1302
|
-
})
|
|
1303
|
-
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
1304
|
-
.catch(err => createResult(ResultCode.Fail, data.action, err?.response?.data ?? err?.message ?? err));
|
|
1305
|
-
consume([res]);
|
|
1306
|
-
}
|
|
1307
|
-
else if (data.action === 'stream.message.send') {
|
|
1308
|
-
const res = await client
|
|
1309
|
-
.streamMessages(getUserId(), data.payload.params ?? {})
|
|
1310
|
-
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
1311
|
-
.catch(err => createResult(ResultCode.Fail, data.action, err?.response?.data ?? err?.message ?? err));
|
|
1312
|
-
consume([res]);
|
|
1313
|
-
}
|
|
1314
|
-
else if (data.action === 'message.input.notify') {
|
|
1315
|
-
const params = data.payload.params ?? {};
|
|
1316
|
-
const res = await client
|
|
1317
|
-
.usersOpenMessages(getUserId(), {
|
|
1318
|
-
msg_type: 6,
|
|
1319
|
-
input_notify: { input_type: params.input_type ?? 1, input_second: params.input_second ?? 60 },
|
|
1320
|
-
msg_seq: params.msg_seq,
|
|
1321
|
-
msg_id: params.msg_id
|
|
1322
|
-
})
|
|
1323
|
-
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
1324
|
-
.catch(err => createResult(ResultCode.Fail, data.action, err?.response?.data ?? err?.message ?? err));
|
|
1325
|
-
consume([res]);
|
|
1326
|
-
}
|
|
1327
|
-
else if (data.action === 'permission.get') {
|
|
1328
|
-
const res = await client
|
|
1329
|
-
.channelsPermissions(getChannelId(), getUserId())
|
|
1330
|
-
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
1331
|
-
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
1332
|
-
consume([res]);
|
|
1333
|
-
}
|
|
1334
|
-
else if (data.action === 'permission.set') {
|
|
1335
|
-
const params = data.payload.params;
|
|
1336
|
-
const res = await client
|
|
1337
|
-
.channelsPermissionsPut(getChannelId(), getUserId(), params?.allow ?? '0', params?.deny ?? '0')
|
|
1338
|
-
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
1339
|
-
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
1340
|
-
consume([res]);
|
|
1341
|
-
}
|
|
1342
|
-
else if (data.action === 'reaction.list') {
|
|
1343
|
-
const res = await client
|
|
1344
|
-
.channelsMessagesReactionsUsers(getChannelId(), data.payload.MessageId, 1, data.payload.EmojiId, { limit: data.payload.params?.limit ?? 20 })
|
|
1345
|
-
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
1346
|
-
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
1347
|
-
consume([res]);
|
|
1348
|
-
}
|
|
1349
|
-
else if (data.action === 'channel.announce') {
|
|
1350
|
-
const guildId = getGuildId();
|
|
1351
|
-
const params = data.payload.params;
|
|
1352
|
-
if (params?.remove) {
|
|
1353
|
-
const res = await client
|
|
1354
|
-
.guildsAnnouncesDelete(guildId, params?.messageId ?? 'all')
|
|
1355
|
-
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
1356
|
-
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
1357
|
-
consume([res]);
|
|
1358
|
-
}
|
|
1359
|
-
else {
|
|
1360
|
-
const res = await client
|
|
1361
|
-
.guildsAnnounces(guildId, { message_id: params?.messageId, channel_id: params?.channelId })
|
|
1362
|
-
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
1363
|
-
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
1364
|
-
consume([res]);
|
|
1365
|
-
}
|
|
1366
|
-
}
|
|
1367
|
-
else {
|
|
1368
|
-
consume([createResult(ResultCode.Fail, '未知请求,请尝试升级版本', null)]);
|
|
1369
|
-
}
|
|
1370
|
-
}
|
|
1371
|
-
catch (error) {
|
|
1372
|
-
consume([createResult(ResultCode.Fail, '请求失败', error)]);
|
|
1373
|
-
}
|
|
1374
|
-
};
|
|
1375
|
-
const onapis = async (data, consume) => {
|
|
1376
|
-
const key = data.payload?.key;
|
|
1377
|
-
const params = data.payload?.params;
|
|
1378
|
-
try {
|
|
1379
|
-
const keys = key.split('.');
|
|
1380
|
-
let parent = null;
|
|
1381
|
-
let target = client;
|
|
1382
|
-
for (const k of keys) {
|
|
1383
|
-
if (target === null || target === undefined || !(k in target)) {
|
|
1384
|
-
consume([createResult(ResultCode.Fail, '未知请求,请尝试升级版本', null)]);
|
|
1385
|
-
return;
|
|
1386
|
-
}
|
|
1387
|
-
parent = target;
|
|
1388
|
-
target = target[k];
|
|
1389
|
-
}
|
|
1390
|
-
if (typeof target !== 'function') {
|
|
1391
|
-
consume([createResult(ResultCode.Fail, '目标不是可调用方法', null)]);
|
|
1392
|
-
return;
|
|
1393
|
-
}
|
|
1394
|
-
const res = await target.call(parent, ...params);
|
|
1395
|
-
consume([createResult(ResultCode.Ok, '请求完成', res)]);
|
|
1396
|
-
}
|
|
1397
|
-
catch (error) {
|
|
1398
|
-
consume([createResult(ResultCode.Fail, '请求失败', error)]);
|
|
1399
|
-
}
|
|
1400
|
-
};
|
|
1401
|
-
if (options?.bindActions !== false) {
|
|
1402
|
-
cbp.onactions((data, consume) => void onactions(data, consume));
|
|
1403
|
-
cbp.onapis((data, consume) => void onapis(data, consume));
|
|
1404
|
-
}
|
|
1405
|
-
return { onAction: onactions, onApi: onapis };
|
|
43
|
+
const MAX_MEDIA_SIZE = 104857600;
|
|
44
|
+
const config = getQQBotConfig();
|
|
45
|
+
const botId = String(options?.botId ?? config?.app_id ?? "");
|
|
46
|
+
const url = `ws://127.0.0.1:${process.env?.port || config?.port || 17117}`;
|
|
47
|
+
const cbp = options?.cbp ?? cbpPlatform(url);
|
|
48
|
+
/**
|
|
49
|
+
* group
|
|
50
|
+
*
|
|
51
|
+
* GROUP_AT_MESSAGE_CREATE
|
|
52
|
+
* C2C_MESSAGE_CREATE
|
|
53
|
+
*/
|
|
54
|
+
const createUserAvatarURL = (authorId) => {
|
|
55
|
+
return `https://q.qlogo.cn/qqapp/${botId}/${authorId}/640`;
|
|
56
|
+
};
|
|
57
|
+
const getGroupMessageMeta = (event) => {
|
|
58
|
+
const author = event?.author;
|
|
59
|
+
const UserId = author?.id ?? "";
|
|
60
|
+
const memberOpenId = author?.member_openid ?? "";
|
|
61
|
+
const groupId = event?.group_id ?? event?.group_openid ?? "";
|
|
62
|
+
const messageId = event?.id ?? "";
|
|
63
|
+
const [isMaster, UserKey] = UserId ? getMaster(UserId) : [false, ""];
|
|
64
|
+
return {
|
|
65
|
+
UserId,
|
|
66
|
+
UserKey,
|
|
67
|
+
isMaster,
|
|
68
|
+
UserName: author?.username ?? "",
|
|
69
|
+
UserAvatar: UserId ? createUserAvatarURL(UserId) : "",
|
|
70
|
+
groupId,
|
|
71
|
+
messageId,
|
|
72
|
+
openId: memberOpenId ? `C2C:${memberOpenId}` : ""
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
const getGroupAuditMeta = (event) => {
|
|
76
|
+
return {
|
|
77
|
+
groupId: event?.group_openid ?? "",
|
|
78
|
+
messageId: event?.message_id ?? event?.audit_id ?? "",
|
|
79
|
+
auditTime: event?.audit_time ?? ""
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
const getMediaItems = (attachments) => {
|
|
83
|
+
return (attachments || []).flatMap((attachment) => {
|
|
84
|
+
if (!attachment?.url) return [];
|
|
85
|
+
const mimeType = attachment.content_type || "";
|
|
86
|
+
return [{
|
|
87
|
+
Type: mimeType.startsWith("image/") ? "image" : mimeType.startsWith("audio/") ? "audio" : mimeType.startsWith("video/") ? "video" : "file",
|
|
88
|
+
Url: attachment.url,
|
|
89
|
+
...attachment.filename && { FileName: attachment.filename },
|
|
90
|
+
...typeof attachment.size === "number" && { FileSize: attachment.size },
|
|
91
|
+
...mimeType && { MimeType: mimeType }
|
|
92
|
+
}];
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
const normalizeTarget = (target) => {
|
|
96
|
+
if (!target?.targetId || !target.scope) return;
|
|
97
|
+
return target;
|
|
98
|
+
};
|
|
99
|
+
const validateTargetBot = (target) => {
|
|
100
|
+
return !target.BotId || target.BotId === botId;
|
|
101
|
+
};
|
|
102
|
+
const mediaCache = /* @__PURE__ */ new Map();
|
|
103
|
+
const mediaType = (type) => type === "image" ? 1 : type === "video" ? 2 : type === "audio" ? 3 : 4;
|
|
104
|
+
const prepareMedia = async (target, params) => {
|
|
105
|
+
if ([
|
|
106
|
+
params?.url,
|
|
107
|
+
params?.data,
|
|
108
|
+
params?.filePath,
|
|
109
|
+
params?.fileId
|
|
110
|
+
].filter((value) => value !== void 0 && value !== "").length !== 1) throw new Error("Provide exactly one media source: url, data, filePath, or fileId");
|
|
111
|
+
if (params.fileId) return {
|
|
112
|
+
fileId: String(params.fileId),
|
|
113
|
+
reused: true
|
|
114
|
+
};
|
|
115
|
+
let data = params.data;
|
|
116
|
+
let buffer;
|
|
117
|
+
let filePath;
|
|
118
|
+
let fileSize;
|
|
119
|
+
let hashes;
|
|
120
|
+
let name = params.name;
|
|
121
|
+
let hashSource = String(params.url || "");
|
|
122
|
+
if (params.filePath) {
|
|
123
|
+
const metadata = await stat(String(params.filePath));
|
|
124
|
+
if (!metadata.isFile()) throw new Error("media filePath must point to a regular file");
|
|
125
|
+
if (metadata.size > MAX_MEDIA_SIZE) throw new Error("QQ media files must not exceed 100 MiB");
|
|
126
|
+
filePath = String(params.filePath);
|
|
127
|
+
fileSize = metadata.size;
|
|
128
|
+
hashes = await client.getMediaFileHashes(filePath);
|
|
129
|
+
hashSource = hashes.sha256;
|
|
130
|
+
name ||= basename(filePath);
|
|
131
|
+
if (fileSize < 5242880) {
|
|
132
|
+
buffer = await readFile(filePath);
|
|
133
|
+
data = `base64://${buffer.toString("base64")}`;
|
|
134
|
+
}
|
|
135
|
+
} else if (data) {
|
|
136
|
+
hashSource = data;
|
|
137
|
+
const value = data.replace(/^base64:\/\//, "");
|
|
138
|
+
buffer = Buffer.from(value, "base64");
|
|
139
|
+
if (buffer.length > MAX_MEDIA_SIZE) throw new Error("QQ media files must not exceed 100 MiB");
|
|
140
|
+
}
|
|
141
|
+
const key = [
|
|
142
|
+
botId,
|
|
143
|
+
target.scope,
|
|
144
|
+
target.targetId,
|
|
145
|
+
params.type,
|
|
146
|
+
createHash("sha256").update(hashSource).digest("hex")
|
|
147
|
+
].join(":");
|
|
148
|
+
const cached = mediaCache.get(key);
|
|
149
|
+
if (cached && (!cached.expiresAt || cached.expiresAt > Date.now())) return {
|
|
150
|
+
fileId: cached.fileId,
|
|
151
|
+
expiresAt: cached.expiresAt,
|
|
152
|
+
reused: true
|
|
153
|
+
};
|
|
154
|
+
return {
|
|
155
|
+
key,
|
|
156
|
+
url: params.url,
|
|
157
|
+
data,
|
|
158
|
+
buffer,
|
|
159
|
+
filePath,
|
|
160
|
+
fileSize,
|
|
161
|
+
hashes,
|
|
162
|
+
name,
|
|
163
|
+
reused: false
|
|
164
|
+
};
|
|
165
|
+
};
|
|
166
|
+
const uploadMedia = async (target, params) => {
|
|
167
|
+
if (!validateTargetBot(target)) throw new Error(`BotId ${target.BotId} is not active`);
|
|
168
|
+
if (target.scope !== "group" && target.scope !== "c2c") throw new Error("QQ media upload only supports group and c2c targets");
|
|
169
|
+
const prepared = await prepareMedia(target, params);
|
|
170
|
+
if (prepared.fileId) return prepared;
|
|
171
|
+
const fileType = mediaType(params.type);
|
|
172
|
+
const value = prepared.filePath && prepared.fileSize && prepared.fileSize >= 5242880 ? await client.postChunkedRichMedia({
|
|
173
|
+
scope: target.scope,
|
|
174
|
+
targetId: target.targetId,
|
|
175
|
+
fileType,
|
|
176
|
+
filePath: prepared.filePath,
|
|
177
|
+
size: prepared.fileSize,
|
|
178
|
+
hashes: prepared.hashes,
|
|
179
|
+
name: prepared.name
|
|
180
|
+
}) : prepared.buffer && prepared.buffer.length >= 5242880 ? await client.postChunkedRichMedia({
|
|
181
|
+
scope: target.scope,
|
|
182
|
+
targetId: target.targetId,
|
|
183
|
+
fileType,
|
|
184
|
+
data: prepared.buffer,
|
|
185
|
+
name: prepared.name
|
|
186
|
+
}) : target.scope === "group" ? await client.postRichMediaByGroup(target.targetId, {
|
|
187
|
+
file_type: fileType,
|
|
188
|
+
url: prepared.url,
|
|
189
|
+
file_data: prepared.data,
|
|
190
|
+
srv_send_msg: false
|
|
191
|
+
}) : await client.postRichMediaByUser(target.targetId, {
|
|
192
|
+
file_type: fileType,
|
|
193
|
+
url: prepared.url,
|
|
194
|
+
file_data: prepared.data,
|
|
195
|
+
srv_send_msg: false
|
|
196
|
+
});
|
|
197
|
+
const expiresAt = value.ttl ? Date.now() + value.ttl * 1e3 : void 0;
|
|
198
|
+
if (prepared.key) mediaCache.set(prepared.key, {
|
|
199
|
+
fileId: value.file_info,
|
|
200
|
+
expiresAt
|
|
201
|
+
});
|
|
202
|
+
return {
|
|
203
|
+
fileId: value.file_info,
|
|
204
|
+
expiresAt,
|
|
205
|
+
reused: false
|
|
206
|
+
};
|
|
207
|
+
};
|
|
208
|
+
const createUserMeta = (UserId, extra = {}) => {
|
|
209
|
+
const [IsMaster, UserKey] = getIdentity(UserId);
|
|
210
|
+
return {
|
|
211
|
+
UserId,
|
|
212
|
+
UserKey,
|
|
213
|
+
IsMaster,
|
|
214
|
+
IsBot: false,
|
|
215
|
+
...extra
|
|
216
|
+
};
|
|
217
|
+
};
|
|
218
|
+
client.on("GROUP_ADD_ROBOT", (event) => {
|
|
219
|
+
cbp.send(FormatEvent.create("guild.join").addPlatform({
|
|
220
|
+
Platform: platform,
|
|
221
|
+
value: event,
|
|
222
|
+
BotId: botId
|
|
223
|
+
}).addGuild({
|
|
224
|
+
GuildId: event.group_openid,
|
|
225
|
+
SpaceId: `GROUP:${event.group_openid}`
|
|
226
|
+
}).addChannel({ ChannelId: event.group_openid }).addUser(createUserMeta(event.op_member_openid, { UserAvatar: createUserAvatarURL(event.op_member_openid) })).addMessage({ MessageId: event.id }).add({ tag: "GROUP_ADD_ROBOT" }).value);
|
|
227
|
+
});
|
|
228
|
+
client.on("GROUP_DEL_ROBOT", (event) => {
|
|
229
|
+
cbp.send(FormatEvent.create("guild.exit").addPlatform({
|
|
230
|
+
Platform: platform,
|
|
231
|
+
value: event,
|
|
232
|
+
BotId: botId
|
|
233
|
+
}).addGuild({
|
|
234
|
+
GuildId: event.group_openid,
|
|
235
|
+
SpaceId: `GROUP:${event.group_openid}`
|
|
236
|
+
}).addChannel({ ChannelId: event.group_openid }).addUser(createUserMeta(event.op_member_openid, { UserAvatar: createUserAvatarURL(event.op_member_openid) })).add({ tag: "GROUP_DEL_ROBOT" }).value);
|
|
237
|
+
});
|
|
238
|
+
client.on("GROUP_MESSAGE_CREATE", (event) => {
|
|
239
|
+
if (event?.author?.bot) return;
|
|
240
|
+
const msg = getMessageContent(event);
|
|
241
|
+
const meta = getGroupMessageMeta(event);
|
|
242
|
+
cbp.send(FormatEvent.create("message.create").addPlatform({
|
|
243
|
+
Platform: platform,
|
|
244
|
+
value: event,
|
|
245
|
+
BotId: botId,
|
|
246
|
+
IsAtMe: false,
|
|
247
|
+
IsPrivate: false
|
|
248
|
+
}).addGuild({
|
|
249
|
+
GuildId: meta.groupId,
|
|
250
|
+
SpaceId: `GROUP:${meta.groupId}`
|
|
251
|
+
}).addChannel({ ChannelId: meta.groupId }).addUser({
|
|
252
|
+
UserId: meta.UserId,
|
|
253
|
+
UserKey: meta.UserKey,
|
|
254
|
+
UserAvatar: meta.UserAvatar,
|
|
255
|
+
UserName: meta.UserName,
|
|
256
|
+
IsMaster: meta.isMaster,
|
|
257
|
+
IsBot: false
|
|
258
|
+
}).addMessage({ MessageId: meta.messageId }).addText({ MessageText: msg?.trim() }).addMedia({ MessageMedia: getMediaItems(event.attachments) }).addOpen({ OpenId: meta.openId }).add({ tag: "GROUP_MESSAGE_CREATE" }).value);
|
|
259
|
+
});
|
|
260
|
+
client.on("GROUP_MEMBER_ADD", (event) => {
|
|
261
|
+
const UserId = event.op_member_openid ?? event.member_openid ?? "";
|
|
262
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
263
|
+
cbp.send(FormatEvent.create("member.add").addPlatform({
|
|
264
|
+
Platform: platform,
|
|
265
|
+
value: event,
|
|
266
|
+
BotId: botId
|
|
267
|
+
}).addGuild({
|
|
268
|
+
GuildId: event.group_openid ?? "",
|
|
269
|
+
SpaceId: `GROUP:${event.group_openid ?? ""}`
|
|
270
|
+
}).addChannel({ ChannelId: event.group_openid ?? "" }).addUser({
|
|
271
|
+
UserId,
|
|
272
|
+
UserKey,
|
|
273
|
+
UserName: event?.username ?? "",
|
|
274
|
+
UserAvatar: createUserAvatarURL(UserId),
|
|
275
|
+
IsMaster: isMaster,
|
|
276
|
+
IsBot: false
|
|
277
|
+
}).add({ tag: "GROUP_MEMBER_ADD" }).value);
|
|
278
|
+
});
|
|
279
|
+
client.on("GROUP_MEMBER_REMOVE", (event) => {
|
|
280
|
+
const UserId = event.op_member_openid ?? event.member_openid ?? "";
|
|
281
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
282
|
+
cbp.send(FormatEvent.create("member.remove").addPlatform({
|
|
283
|
+
Platform: platform,
|
|
284
|
+
value: event,
|
|
285
|
+
BotId: botId
|
|
286
|
+
}).addGuild({
|
|
287
|
+
GuildId: event.group_openid ?? "",
|
|
288
|
+
SpaceId: `GROUP:${event.group_openid ?? ""}`
|
|
289
|
+
}).addChannel({ ChannelId: event.group_openid ?? "" }).addUser({
|
|
290
|
+
UserId,
|
|
291
|
+
UserKey,
|
|
292
|
+
UserName: event?.username ?? "",
|
|
293
|
+
UserAvatar: createUserAvatarURL(UserId),
|
|
294
|
+
IsMaster: isMaster,
|
|
295
|
+
IsBot: false
|
|
296
|
+
}).add({ tag: "GROUP_MEMBER_REMOVE" }).value);
|
|
297
|
+
});
|
|
298
|
+
client.on("GROUP_JOIN_REQUEST", (event) => {
|
|
299
|
+
const UserId = event.member_openid ?? "";
|
|
300
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
301
|
+
cbp.send(FormatEvent.create("notice.create").addPlatform({
|
|
302
|
+
Platform: platform,
|
|
303
|
+
value: event,
|
|
304
|
+
BotId: botId
|
|
305
|
+
}).addGuild({
|
|
306
|
+
GuildId: event.group_openid ?? "",
|
|
307
|
+
SpaceId: `GROUP:${event.group_openid ?? ""}`
|
|
308
|
+
}).addChannel({ ChannelId: event.group_openid ?? "" }).addUser({
|
|
309
|
+
UserId,
|
|
310
|
+
UserKey,
|
|
311
|
+
UserName: event?.username ?? "",
|
|
312
|
+
UserAvatar: createUserAvatarURL(UserId),
|
|
313
|
+
IsMaster: isMaster,
|
|
314
|
+
IsBot: event.bot ?? false
|
|
315
|
+
}).addMessage({ MessageId: `group_join_request_${event.group_openid}_${event.join_request_id}` }).add({ tag: "GROUP_JOIN_REQUEST" }).value);
|
|
316
|
+
});
|
|
317
|
+
client.on("GROUP_AT_MESSAGE_CREATE", (event) => {
|
|
318
|
+
if (event?.author?.bot) return;
|
|
319
|
+
const msg = getMessageContent(event);
|
|
320
|
+
const meta = getGroupMessageMeta(event);
|
|
321
|
+
cbp.send(FormatEvent.create("message.create").addPlatform({
|
|
322
|
+
Platform: platform,
|
|
323
|
+
value: event,
|
|
324
|
+
BotId: botId,
|
|
325
|
+
IsAtMe: true,
|
|
326
|
+
IsPrivate: false
|
|
327
|
+
}).addGuild({
|
|
328
|
+
GuildId: meta.groupId,
|
|
329
|
+
SpaceId: `GROUP:${meta.groupId}`
|
|
330
|
+
}).addChannel({ ChannelId: meta.groupId }).addUser({
|
|
331
|
+
UserId: meta.UserId,
|
|
332
|
+
UserKey: meta.UserKey,
|
|
333
|
+
UserAvatar: meta.UserAvatar,
|
|
334
|
+
UserName: meta.UserName,
|
|
335
|
+
IsMaster: meta.isMaster,
|
|
336
|
+
IsBot: false
|
|
337
|
+
}).addMessage({ MessageId: meta.messageId }).addText({ MessageText: msg?.trim() }).addMedia({ MessageMedia: getMediaItems(event.attachments) }).addOpen({ OpenId: meta.openId }).add({ tag: "GROUP_AT_MESSAGE_CREATE" }).value);
|
|
338
|
+
});
|
|
339
|
+
client.on("C2C_MESSAGE_CREATE", (event) => {
|
|
340
|
+
const UserId = event.author.id;
|
|
341
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
342
|
+
const UserAvatar = createUserAvatarURL(event.author.id);
|
|
343
|
+
cbp.send(FormatEvent.create("private.message.create").addPlatform({
|
|
344
|
+
Platform: platform,
|
|
345
|
+
value: event,
|
|
346
|
+
BotId: botId,
|
|
347
|
+
IsAtMe: false,
|
|
348
|
+
IsPrivate: true
|
|
349
|
+
}).addUser({
|
|
350
|
+
UserId: event.author.id,
|
|
351
|
+
UserKey,
|
|
352
|
+
UserAvatar,
|
|
353
|
+
UserName: event?.author?.username,
|
|
354
|
+
IsMaster: isMaster,
|
|
355
|
+
IsBot: false
|
|
356
|
+
}).addMessage({ MessageId: event.id }).addText({ MessageText: event.content?.trim() }).addMedia({ MessageMedia: getMediaItems(event.attachments) }).addOpen({ OpenId: `C2C:${event.author.user_openid}` }).add({ tag: "C2C_MESSAGE_CREATE" }).value);
|
|
357
|
+
});
|
|
358
|
+
/**
|
|
359
|
+
* guild
|
|
360
|
+
*/
|
|
361
|
+
client.on("DIRECT_MESSAGE_CREATE", (event) => {
|
|
362
|
+
if (event?.author?.bot) return;
|
|
363
|
+
const msg = event?.content ?? "";
|
|
364
|
+
const UserAvatar = event?.author?.avatar;
|
|
365
|
+
const UserId = event.author.id;
|
|
366
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
367
|
+
cbp.send(FormatEvent.create("private.message.create").addPlatform({
|
|
368
|
+
Platform: platform,
|
|
369
|
+
value: event,
|
|
370
|
+
BotId: botId,
|
|
371
|
+
IsAtMe: false,
|
|
372
|
+
IsPrivate: true
|
|
373
|
+
}).addUser({
|
|
374
|
+
UserId: event?.author?.id ?? "",
|
|
375
|
+
UserKey,
|
|
376
|
+
UserName: event?.author?.username ?? "",
|
|
377
|
+
UserAvatar,
|
|
378
|
+
IsMaster: isMaster,
|
|
379
|
+
IsBot: event.author?.bot
|
|
380
|
+
}).addMessage({ MessageId: event.id }).addText({ MessageText: msg?.trim() }).addMedia({ MessageMedia: getMediaItems(event.attachments) }).addOpen({ OpenId: `DIRECT:${event.guild_id}` }).add({ tag: "DIRECT_MESSAGE_CREATE" }).value);
|
|
381
|
+
});
|
|
382
|
+
client.on("AT_MESSAGE_CREATE", (event) => {
|
|
383
|
+
if (event?.author?.bot) return;
|
|
384
|
+
const msg = getMessageContent(event);
|
|
385
|
+
const UserAvatar = event?.author?.avatar;
|
|
386
|
+
const UserId = event.author.id;
|
|
387
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
388
|
+
cbp.send(FormatEvent.create("message.create").addPlatform({
|
|
389
|
+
Platform: platform,
|
|
390
|
+
value: event,
|
|
391
|
+
BotId: botId,
|
|
392
|
+
IsAtMe: true,
|
|
393
|
+
IsPrivate: false
|
|
394
|
+
}).addGuild({
|
|
395
|
+
GuildId: event.guild_id,
|
|
396
|
+
SpaceId: `GUILD:${event.channel_id}`
|
|
397
|
+
}).addChannel({ ChannelId: event.channel_id }).addUser({
|
|
398
|
+
UserId: event?.author?.id ?? "",
|
|
399
|
+
UserKey,
|
|
400
|
+
UserName: event?.author?.username ?? "",
|
|
401
|
+
UserAvatar,
|
|
402
|
+
IsMaster: isMaster,
|
|
403
|
+
IsBot: event.author?.bot
|
|
404
|
+
}).addMessage({ MessageId: event.id }).addText({ MessageText: msg?.trim() }).addMedia({ MessageMedia: getMediaItems(event.attachments) }).addOpen({ OpenId: `DIRECT:${event.guild_id}` }).add({ tag: "AT_MESSAGE_CREATE" }).value);
|
|
405
|
+
});
|
|
406
|
+
/**
|
|
407
|
+
*
|
|
408
|
+
* @param event
|
|
409
|
+
* @returns
|
|
410
|
+
*/
|
|
411
|
+
const getMessageContent = (event) => {
|
|
412
|
+
let msg = event?.content ?? "";
|
|
413
|
+
if (event?.mentions) for (const item of event.mentions) {
|
|
414
|
+
if (item?.id) {
|
|
415
|
+
msg = msg.replace(`<@!${item.id}>`, "").trim();
|
|
416
|
+
msg = msg.replace(`<@${item.id}>`, "").trim();
|
|
417
|
+
}
|
|
418
|
+
if (item?.username) msg = msg.replace(`[${item.username}]`, "").trim();
|
|
419
|
+
}
|
|
420
|
+
return msg;
|
|
421
|
+
};
|
|
422
|
+
client.on("MESSAGE_CREATE", (event) => {
|
|
423
|
+
if (event.author?.bot) return;
|
|
424
|
+
if ((/* @__PURE__ */ new RegExp(/DELETE$/)).test(event.eventType)) return;
|
|
425
|
+
const UserId = event.author.id;
|
|
426
|
+
const msg = getMessageContent(event);
|
|
427
|
+
const UserAvatar = event?.author?.avatar;
|
|
428
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
429
|
+
cbp.send(FormatEvent.create("message.create").addPlatform({
|
|
430
|
+
Platform: platform,
|
|
431
|
+
value: event,
|
|
432
|
+
BotId: botId,
|
|
433
|
+
IsAtMe: false,
|
|
434
|
+
IsPrivate: false
|
|
435
|
+
}).addGuild({
|
|
436
|
+
GuildId: event.guild_id,
|
|
437
|
+
SpaceId: `GUILD:${event.channel_id}`
|
|
438
|
+
}).addChannel({ ChannelId: event.channel_id }).addUser({
|
|
439
|
+
UserId: event?.author?.id ?? "",
|
|
440
|
+
UserKey,
|
|
441
|
+
UserName: event?.author?.username ?? "",
|
|
442
|
+
UserAvatar,
|
|
443
|
+
IsMaster: isMaster,
|
|
444
|
+
IsBot: false
|
|
445
|
+
}).addMessage({ MessageId: event.id }).addText({ MessageText: msg?.trim() }).addMedia({ MessageMedia: getMediaItems(event.attachments) }).addOpen({ OpenId: `DIRECT:${event.guild_id}` }).add({ tag: "MESSAGE_CREATE" }).value);
|
|
446
|
+
});
|
|
447
|
+
client.on("INTERACTION_CREATE", async (event) => {
|
|
448
|
+
try {
|
|
449
|
+
await client.interactionResponse("group", event.id, 0);
|
|
450
|
+
} catch (err) {
|
|
451
|
+
createResult(ResultCode.Fail, "interactionResponse failed", err?.response?.data ?? err?.message ?? err);
|
|
452
|
+
}
|
|
453
|
+
if (event.scene === "group") {
|
|
454
|
+
const UserAvatar = createUserAvatarURL(event.group_member_openid);
|
|
455
|
+
const UserId = event.group_member_openid;
|
|
456
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
457
|
+
const MessageText = event.data.resolved.button_data?.trim() || "";
|
|
458
|
+
const e = FormatEvent.create("interaction.create").addPlatform({
|
|
459
|
+
Platform: platform,
|
|
460
|
+
value: event,
|
|
461
|
+
BotId: botId,
|
|
462
|
+
IsAtMe: false,
|
|
463
|
+
IsPrivate: false
|
|
464
|
+
}).addGuild({
|
|
465
|
+
GuildId: event.group_openid,
|
|
466
|
+
SpaceId: `GROUP:${event.group_openid}`
|
|
467
|
+
}).addChannel({ ChannelId: event.group_openid }).addUser({
|
|
468
|
+
UserId: event.group_member_openid,
|
|
469
|
+
UserKey,
|
|
470
|
+
UserAvatar,
|
|
471
|
+
IsMaster: isMaster,
|
|
472
|
+
IsBot: false
|
|
473
|
+
}).addMessage({ MessageId: event.id }).addText({ MessageText }).addInteraction({
|
|
474
|
+
InteractionId: event.id,
|
|
475
|
+
InteractionData: JSON.stringify(event.data.resolved),
|
|
476
|
+
Target: {
|
|
477
|
+
scope: "group",
|
|
478
|
+
targetId: event.group_openid,
|
|
479
|
+
BotId: botId
|
|
480
|
+
}
|
|
481
|
+
}).addOpen({ OpenId: `C2C:${event.group_member_openid}` }).add({ tag: "INTERACTION_CREATE_GROUP" }).value;
|
|
482
|
+
cbp.send(e);
|
|
483
|
+
} else if (event.scene === "c2c") {
|
|
484
|
+
const UserAvatar = createUserAvatarURL(event.user_openid);
|
|
485
|
+
const UserId = event.user_openid;
|
|
486
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
487
|
+
const MessageText = event.data.resolved.button_data?.trim() || "";
|
|
488
|
+
const e = FormatEvent.create("private.interaction.create").addPlatform({
|
|
489
|
+
Platform: platform,
|
|
490
|
+
value: event,
|
|
491
|
+
BotId: botId,
|
|
492
|
+
IsAtMe: false,
|
|
493
|
+
IsPrivate: true
|
|
494
|
+
}).addUser({
|
|
495
|
+
UserId: event.user_openid,
|
|
496
|
+
UserKey,
|
|
497
|
+
UserAvatar,
|
|
498
|
+
IsMaster: isMaster,
|
|
499
|
+
IsBot: false
|
|
500
|
+
}).addMessage({ MessageId: event.id }).addText({ MessageText }).addInteraction({
|
|
501
|
+
InteractionId: event.id,
|
|
502
|
+
InteractionData: JSON.stringify(event.data.resolved),
|
|
503
|
+
Target: {
|
|
504
|
+
scope: "c2c",
|
|
505
|
+
targetId: event.user_openid,
|
|
506
|
+
BotId: botId
|
|
507
|
+
}
|
|
508
|
+
}).addOpen({ OpenId: `C2C:${event.user_openid}` }).add({ tag: "INTERACTION_CREATE_C2C" }).value;
|
|
509
|
+
cbp.send(e);
|
|
510
|
+
} else if (event.scene === "guild") {
|
|
511
|
+
const UserAvatar = createUserAvatarURL(event.data.resolved.user_id);
|
|
512
|
+
const UserId = event.data.resolved.user_id;
|
|
513
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
514
|
+
const MessageText = event.data.resolved.button_data?.trim() || "";
|
|
515
|
+
const e = FormatEvent.create("interaction.create").addPlatform({
|
|
516
|
+
Platform: platform,
|
|
517
|
+
value: event,
|
|
518
|
+
BotId: botId,
|
|
519
|
+
IsAtMe: false,
|
|
520
|
+
IsPrivate: false
|
|
521
|
+
}).addGuild({
|
|
522
|
+
GuildId: event.guild_id,
|
|
523
|
+
SpaceId: `GUILD:${event.channel_id}`
|
|
524
|
+
}).addChannel({ ChannelId: event.channel_id }).addUser({
|
|
525
|
+
UserId: event.data.resolved.user_id,
|
|
526
|
+
UserKey,
|
|
527
|
+
UserAvatar,
|
|
528
|
+
IsMaster: isMaster,
|
|
529
|
+
IsBot: false
|
|
530
|
+
}).addMessage({ MessageId: event.data.resolved.message_id }).addText({ MessageText }).addInteraction({
|
|
531
|
+
InteractionId: event.id,
|
|
532
|
+
InteractionData: JSON.stringify(event.data.resolved),
|
|
533
|
+
Target: {
|
|
534
|
+
scope: "channel",
|
|
535
|
+
targetId: event.channel_id,
|
|
536
|
+
BotId: botId
|
|
537
|
+
}
|
|
538
|
+
}).addOpen({ OpenId: `DIRECT:${event.guild_id}` }).add({ tag: "INTERACTION_CREATE_GUILD" }).value;
|
|
539
|
+
cbp.send(e);
|
|
540
|
+
} else logger.warn({
|
|
541
|
+
code: ResultCode.Fail,
|
|
542
|
+
message: "暂未更新支持此类型的交互事件",
|
|
543
|
+
data: event
|
|
544
|
+
});
|
|
545
|
+
});
|
|
546
|
+
client.on("MESSAGE_DELETE", (event) => {
|
|
547
|
+
const msg = event?.message ?? event;
|
|
548
|
+
cbp.send(FormatEvent.create("message.delete").addPlatform({
|
|
549
|
+
Platform: platform,
|
|
550
|
+
value: event,
|
|
551
|
+
BotId: botId
|
|
552
|
+
}).addGuild({
|
|
553
|
+
GuildId: msg?.guild_id ?? "",
|
|
554
|
+
SpaceId: `GUILD:${msg?.channel_id ?? ""}`
|
|
555
|
+
}).addChannel({ ChannelId: msg?.channel_id ?? "" }).addMessage({ MessageId: msg?.id ?? "" }).add({ tag: "MESSAGE_DELETE" }).value);
|
|
556
|
+
});
|
|
557
|
+
client.on("PUBLIC_MESSAGE_DELETE", (event) => {
|
|
558
|
+
const msg = event.message;
|
|
559
|
+
cbp.send(FormatEvent.create("message.delete").addPlatform({
|
|
560
|
+
Platform: platform,
|
|
561
|
+
value: event,
|
|
562
|
+
BotId: botId
|
|
563
|
+
}).addGuild({
|
|
564
|
+
GuildId: msg.guild_id ?? "",
|
|
565
|
+
SpaceId: `GUILD:${msg.channel_id ?? ""}`
|
|
566
|
+
}).addChannel({ ChannelId: msg.channel_id ?? "" }).addMessage({ MessageId: msg.id ?? "" }).add({ tag: "PUBLIC_MESSAGE_DELETE" }).value);
|
|
567
|
+
});
|
|
568
|
+
client.on("DIRECT_MESSAGE_DELETE", (event) => {
|
|
569
|
+
const msg = event.message;
|
|
570
|
+
cbp.send(FormatEvent.create("private.message.delete").addPlatform({
|
|
571
|
+
Platform: platform,
|
|
572
|
+
value: event,
|
|
573
|
+
BotId: botId
|
|
574
|
+
}).addMessage({ MessageId: msg.id ?? "" }).add({ tag: "DIRECT_MESSAGE_DELETE" }).value);
|
|
575
|
+
});
|
|
576
|
+
client.on("MESSAGE_REACTION_ADD", (event) => {
|
|
577
|
+
cbp.send(FormatEvent.create("message.reaction.add").addPlatform({
|
|
578
|
+
Platform: platform,
|
|
579
|
+
value: event,
|
|
580
|
+
BotId: botId
|
|
581
|
+
}).addGuild({
|
|
582
|
+
GuildId: event.guild_id ?? "",
|
|
583
|
+
SpaceId: `GUILD:${event.channel_id ?? ""}`
|
|
584
|
+
}).addChannel({ ChannelId: event.channel_id ?? "" }).addMessage({ MessageId: event.target?.id ?? "" }).add({ tag: "MESSAGE_REACTION_ADD" }).value);
|
|
585
|
+
});
|
|
586
|
+
client.on("MESSAGE_REACTION_REMOVE", (event) => {
|
|
587
|
+
cbp.send(FormatEvent.create("message.reaction.remove").addPlatform({
|
|
588
|
+
Platform: platform,
|
|
589
|
+
value: event,
|
|
590
|
+
BotId: botId
|
|
591
|
+
}).addGuild({
|
|
592
|
+
GuildId: event.guild_id ?? "",
|
|
593
|
+
SpaceId: `GUILD:${event.channel_id ?? ""}`
|
|
594
|
+
}).addChannel({ ChannelId: event.channel_id ?? "" }).addMessage({ MessageId: event.target?.id ?? "" }).add({ tag: "MESSAGE_REACTION_REMOVE" }).value);
|
|
595
|
+
});
|
|
596
|
+
client.on("CHANNEL_CREATE", (event) => {
|
|
597
|
+
cbp.send(FormatEvent.create("channel.create").addPlatform({
|
|
598
|
+
Platform: platform,
|
|
599
|
+
value: event,
|
|
600
|
+
BotId: botId
|
|
601
|
+
}).addGuild({
|
|
602
|
+
GuildId: event.guild_id ?? "",
|
|
603
|
+
SpaceId: `GUILD:${event.guild_id ?? ""}`
|
|
604
|
+
}).addChannel({ ChannelId: event.id ?? "" }).add({ tag: "CHANNEL_CREATE" }).value);
|
|
605
|
+
});
|
|
606
|
+
client.on("CHANNEL_DELETE", (event) => {
|
|
607
|
+
cbp.send(FormatEvent.create("channel.delete").addPlatform({
|
|
608
|
+
Platform: platform,
|
|
609
|
+
value: event,
|
|
610
|
+
BotId: botId
|
|
611
|
+
}).addGuild({
|
|
612
|
+
GuildId: event.guild_id ?? "",
|
|
613
|
+
SpaceId: `GUILD:${event.guild_id ?? ""}`
|
|
614
|
+
}).addChannel({ ChannelId: event.id ?? "" }).add({ tag: "CHANNEL_DELETE" }).value);
|
|
615
|
+
});
|
|
616
|
+
client.on("GUILD_CREATE", (event) => {
|
|
617
|
+
cbp.send(FormatEvent.create("guild.join").addPlatform({
|
|
618
|
+
Platform: platform,
|
|
619
|
+
value: event,
|
|
620
|
+
BotId: botId
|
|
621
|
+
}).addGuild({
|
|
622
|
+
GuildId: event.id ?? "",
|
|
623
|
+
SpaceId: `GUILD:${event.id ?? ""}`
|
|
624
|
+
}).addUser({
|
|
625
|
+
UserId: event.op_user_id ?? "",
|
|
626
|
+
UserKey: "",
|
|
627
|
+
IsMaster: false,
|
|
628
|
+
IsBot: false
|
|
629
|
+
}).add({ tag: "GUILD_CREATE" }).value);
|
|
630
|
+
});
|
|
631
|
+
client.on("GUILD_DELETE", (event) => {
|
|
632
|
+
cbp.send(FormatEvent.create("guild.exit").addPlatform({
|
|
633
|
+
Platform: platform,
|
|
634
|
+
value: event,
|
|
635
|
+
BotId: botId
|
|
636
|
+
}).addGuild({
|
|
637
|
+
GuildId: event.id ?? "",
|
|
638
|
+
SpaceId: `GUILD:${event.id ?? ""}`
|
|
639
|
+
}).addUser({
|
|
640
|
+
UserId: event.op_user_id ?? "",
|
|
641
|
+
UserKey: "",
|
|
642
|
+
IsMaster: false,
|
|
643
|
+
IsBot: false
|
|
644
|
+
}).add({ tag: "GUILD_DELETE" }).value);
|
|
645
|
+
});
|
|
646
|
+
client.on("GUILD_MEMBER_ADD", (event) => {
|
|
647
|
+
const UserId = event.user?.id ?? "";
|
|
648
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
649
|
+
cbp.send(FormatEvent.create("member.add").addPlatform({
|
|
650
|
+
Platform: platform,
|
|
651
|
+
value: event,
|
|
652
|
+
BotId: botId
|
|
653
|
+
}).addGuild({
|
|
654
|
+
GuildId: event.guild_id ?? "",
|
|
655
|
+
SpaceId: `GUILD:${event.guild_id ?? ""}`
|
|
656
|
+
}).addUser({
|
|
657
|
+
UserId,
|
|
658
|
+
UserKey,
|
|
659
|
+
UserName: event.user?.username ?? "",
|
|
660
|
+
UserAvatar: createUserAvatarURL(UserId),
|
|
661
|
+
IsMaster: isMaster,
|
|
662
|
+
IsBot: false
|
|
663
|
+
}).add({ tag: "GUILD_MEMBER_ADD" }).value);
|
|
664
|
+
});
|
|
665
|
+
client.on("GUILD_MEMBER_REMOVE", (event) => {
|
|
666
|
+
const UserId = event.user?.id ?? "";
|
|
667
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
668
|
+
cbp.send(FormatEvent.create("member.remove").addPlatform({
|
|
669
|
+
Platform: platform,
|
|
670
|
+
value: event,
|
|
671
|
+
BotId: botId
|
|
672
|
+
}).addGuild({
|
|
673
|
+
GuildId: event.guild_id ?? "",
|
|
674
|
+
SpaceId: `GUILD:${event.guild_id ?? ""}`
|
|
675
|
+
}).addUser({
|
|
676
|
+
UserId,
|
|
677
|
+
UserKey,
|
|
678
|
+
UserName: event.user?.username ?? "",
|
|
679
|
+
UserAvatar: createUserAvatarURL(UserId),
|
|
680
|
+
IsMaster: isMaster,
|
|
681
|
+
IsBot: false
|
|
682
|
+
}).add({ tag: "GUILD_MEMBER_REMOVE" }).value);
|
|
683
|
+
});
|
|
684
|
+
client.on("GUILD_MEMBER_UPDATE", (event) => {
|
|
685
|
+
const UserId = event.user?.id ?? "";
|
|
686
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
687
|
+
cbp.send(FormatEvent.create("member.update").addPlatform({
|
|
688
|
+
Platform: platform,
|
|
689
|
+
value: event,
|
|
690
|
+
BotId: botId
|
|
691
|
+
}).addGuild({
|
|
692
|
+
GuildId: event.guild_id ?? "",
|
|
693
|
+
SpaceId: `GUILD:${event.guild_id ?? ""}`
|
|
694
|
+
}).addUser({
|
|
695
|
+
UserId,
|
|
696
|
+
UserKey,
|
|
697
|
+
UserName: event.user?.username ?? "",
|
|
698
|
+
UserAvatar: createUserAvatarURL(UserId),
|
|
699
|
+
IsMaster: isMaster,
|
|
700
|
+
IsBot: false
|
|
701
|
+
}).add({ tag: "GUILD_MEMBER_UPDATE" }).value);
|
|
702
|
+
});
|
|
703
|
+
client.on("FRIEND_ADD", (event) => {
|
|
704
|
+
cbp.send(FormatEvent.create("private.friend.add").addPlatform({
|
|
705
|
+
Platform: platform,
|
|
706
|
+
value: event,
|
|
707
|
+
BotId: botId
|
|
708
|
+
}).addUser(createUserMeta(event.openid ?? "")).addMessage({ MessageId: event.id }).add({ tag: "FRIEND_ADD" }).value);
|
|
709
|
+
});
|
|
710
|
+
client.on("FRIEND_DEL", (event) => {
|
|
711
|
+
cbp.send(FormatEvent.create("private.friend.remove").addPlatform({
|
|
712
|
+
Platform: platform,
|
|
713
|
+
value: event,
|
|
714
|
+
BotId: botId
|
|
715
|
+
}).addUser(createUserMeta(event.openid ?? "")).add({ tag: "FRIEND_DEL" }).value);
|
|
716
|
+
});
|
|
717
|
+
client.on("CHANNEL_UPDATE", (event) => {
|
|
718
|
+
cbp.send(FormatEvent.create("channel.update").addPlatform({
|
|
719
|
+
Platform: platform,
|
|
720
|
+
value: event,
|
|
721
|
+
BotId: botId
|
|
722
|
+
}).addGuild({
|
|
723
|
+
GuildId: event.guild_id ?? "",
|
|
724
|
+
SpaceId: `GUILD:${event.guild_id ?? ""}`
|
|
725
|
+
}).addChannel({ ChannelId: event.id ?? "" }).add({ tag: "CHANNEL_UPDATE" }).value);
|
|
726
|
+
});
|
|
727
|
+
client.on("GUILD_UPDATE", (event) => {
|
|
728
|
+
cbp.send(FormatEvent.create("guild.update").addPlatform({
|
|
729
|
+
Platform: platform,
|
|
730
|
+
value: event,
|
|
731
|
+
BotId: botId
|
|
732
|
+
}).addGuild({
|
|
733
|
+
GuildId: event.id ?? "",
|
|
734
|
+
SpaceId: `GUILD:${event.id ?? ""}`
|
|
735
|
+
}).add({ tag: "GUILD_UPDATE" }).value);
|
|
736
|
+
});
|
|
737
|
+
client.on("GROUP_MSG_RECEIVE", (event) => {
|
|
738
|
+
cbp.send(FormatEvent.create("notice.create").addPlatform({
|
|
739
|
+
Platform: platform,
|
|
740
|
+
value: event,
|
|
741
|
+
BotId: botId
|
|
742
|
+
}).addGuild({
|
|
743
|
+
GuildId: event.group_openid,
|
|
744
|
+
SpaceId: `GROUP:${event.group_openid}`
|
|
745
|
+
}).addChannel({ ChannelId: event.group_openid }).addUser(createUserMeta(event.op_member_openid)).addMessage({ MessageId: event.id }).add({ tag: "GROUP_MSG_RECEIVE" }).value);
|
|
746
|
+
});
|
|
747
|
+
client.on("GROUP_MSG_REJECT", (event) => {
|
|
748
|
+
cbp.send(FormatEvent.create("notice.create").addPlatform({
|
|
749
|
+
Platform: platform,
|
|
750
|
+
value: event,
|
|
751
|
+
BotId: botId
|
|
752
|
+
}).addGuild({
|
|
753
|
+
GuildId: event.group_openid,
|
|
754
|
+
SpaceId: `GROUP:${event.group_openid}`
|
|
755
|
+
}).addChannel({ ChannelId: event.group_openid }).addUser(createUserMeta(event.op_member_openid)).addMessage({ MessageId: `group_msg_reject_${event.group_openid}_${event.timestamp}` }).add({ tag: "GROUP_MSG_REJECT" }).value);
|
|
756
|
+
});
|
|
757
|
+
client.on("MESSAGE_AUDIT_PASS", (event) => {
|
|
758
|
+
const meta = getGroupAuditMeta(event);
|
|
759
|
+
cbp.send(FormatEvent.create("notice.create").addPlatform({
|
|
760
|
+
Platform: platform,
|
|
761
|
+
value: event,
|
|
762
|
+
BotId: botId
|
|
763
|
+
}).addGuild({
|
|
764
|
+
GuildId: meta.groupId,
|
|
765
|
+
SpaceId: `GROUP:${meta.groupId}`
|
|
766
|
+
}).addChannel({ ChannelId: meta.groupId }).addMessage({ MessageId: meta.messageId }).add({ tag: "MESSAGE_AUDIT_PASS" }).value);
|
|
767
|
+
});
|
|
768
|
+
client.on("MESSAGE_AUDIT_REJECT", (event) => {
|
|
769
|
+
const meta = getGroupAuditMeta(event);
|
|
770
|
+
cbp.send(FormatEvent.create("notice.create").addPlatform({
|
|
771
|
+
Platform: platform,
|
|
772
|
+
value: event,
|
|
773
|
+
BotId: botId
|
|
774
|
+
}).addGuild({
|
|
775
|
+
GuildId: meta.groupId,
|
|
776
|
+
SpaceId: `GROUP:${meta.groupId}`
|
|
777
|
+
}).addChannel({ ChannelId: meta.groupId }).addMessage({ MessageId: meta.messageId }).add({ tag: "MESSAGE_AUDIT_REJECT" }).value);
|
|
778
|
+
});
|
|
779
|
+
client.on("C2C_MSG_RECEIVE", (event) => {
|
|
780
|
+
cbp.send(FormatEvent.create("private.notice.create").addPlatform({
|
|
781
|
+
Platform: platform,
|
|
782
|
+
value: event,
|
|
783
|
+
BotId: botId
|
|
784
|
+
}).addUser(createUserMeta(event.openid ?? "")).addMessage({ MessageId: event.id }).add({ tag: "C2C_MSG_RECEIVE" }).value);
|
|
785
|
+
});
|
|
786
|
+
client.on("C2C_MSG_REJECT", (event) => {
|
|
787
|
+
cbp.send(FormatEvent.create("private.notice.create").addPlatform({
|
|
788
|
+
Platform: platform,
|
|
789
|
+
value: event,
|
|
790
|
+
BotId: botId
|
|
791
|
+
}).addUser(createUserMeta(event.openid ?? "")).addMessage({ MessageId: `c2c_msg_reject_${event.openid}_${event.timestamp}` }).add({ tag: "C2C_MSG_REJECT" }).value);
|
|
792
|
+
});
|
|
793
|
+
client.on("ERROR", console.error);
|
|
794
|
+
const api = {
|
|
795
|
+
active: { send: {
|
|
796
|
+
target: async (target, val, replyId) => {
|
|
797
|
+
if (!validateTargetBot(target)) return [createResult(ResultCode.FailParams, `BotId ${target.BotId} is not active`, null)];
|
|
798
|
+
if (target.scope === "group") return GROUP_AT_MESSAGE_CREATE(client, {
|
|
799
|
+
ChannelId: target.targetId,
|
|
800
|
+
MessageId: replyId
|
|
801
|
+
}, val);
|
|
802
|
+
if (target.scope === "c2c") return C2C_MESSAGE_CREATE(client, {
|
|
803
|
+
UserId: target.targetId,
|
|
804
|
+
MessageId: replyId
|
|
805
|
+
}, val);
|
|
806
|
+
if (target.scope === "channel") return AT_MESSAGE_CREATE(client, {
|
|
807
|
+
ChannelId: target.targetId,
|
|
808
|
+
MessageId: replyId
|
|
809
|
+
}, val);
|
|
810
|
+
if (target.scope === "direct") return DIRECT_MESSAGE_CREATE(client, {
|
|
811
|
+
UserId: target.targetId,
|
|
812
|
+
MessageId: replyId
|
|
813
|
+
}, val);
|
|
814
|
+
return [createResult(ResultCode.FailParams, `Unsupported target scope: ${target.scope}`, null)];
|
|
815
|
+
},
|
|
816
|
+
channel: async (SpaceId, val) => {
|
|
817
|
+
if (/^GUILD:/.test(SpaceId)) {
|
|
818
|
+
const id = SpaceId.replace("GUILD:", "");
|
|
819
|
+
return await AT_MESSAGE_CREATE(client, { ChannelId: id }, val);
|
|
820
|
+
}
|
|
821
|
+
if (/^GROUP:/.test(SpaceId)) {
|
|
822
|
+
const id = SpaceId.replace("GROUP:", "");
|
|
823
|
+
return await GROUP_AT_MESSAGE_CREATE(client, { ChannelId: id }, val);
|
|
824
|
+
}
|
|
825
|
+
return [];
|
|
826
|
+
},
|
|
827
|
+
user: async (OpenId, val) => {
|
|
828
|
+
if (/^C2C:/.test(OpenId)) {
|
|
829
|
+
const id = OpenId.replace("C2C:", "");
|
|
830
|
+
return await C2C_MESSAGE_CREATE(client, { UserId: id }, val);
|
|
831
|
+
} else if (/^DIRECT:/.test(OpenId)) {
|
|
832
|
+
const id = OpenId.replace("DIRECT:", "");
|
|
833
|
+
return await DIRECT_MESSAGE_CREATE(client, { UserId: id }, val);
|
|
834
|
+
} else if (/^GUILD:/.test(OpenId)) {
|
|
835
|
+
const id = OpenId.replace("GUILD:", "");
|
|
836
|
+
return await AT_MESSAGE_CREATE(client, { ChannelId: id }, val);
|
|
837
|
+
}
|
|
838
|
+
return [];
|
|
839
|
+
}
|
|
840
|
+
} },
|
|
841
|
+
use: {
|
|
842
|
+
send: async (event, val, options) => {
|
|
843
|
+
if (!val || val.length <= 0) return [];
|
|
844
|
+
const tag = event._tag;
|
|
845
|
+
if (tag === "GROUP_AT_MESSAGE_CREATE") return await GROUP_AT_MESSAGE_CREATE(client, event, val, options);
|
|
846
|
+
if (tag === "GROUP_MESSAGE_CREATE") return await GROUP_AT_MESSAGE_CREATE(client, event, val, options);
|
|
847
|
+
if (tag === "C2C_MESSAGE_CREATE") return await C2C_MESSAGE_CREATE(client, event, val, options);
|
|
848
|
+
if (tag === "DIRECT_MESSAGE_CREATE") return await DIRECT_MESSAGE_CREATE(client, event, val);
|
|
849
|
+
if (tag === "AT_MESSAGE_CREATE") return await AT_MESSAGE_CREATE(client, event, val);
|
|
850
|
+
if (tag === "MESSAGE_CREATE") return await MESSAGE_CREATE(client, event, val);
|
|
851
|
+
if (tag === "INTERACTION_CREATE_GROUP") return await GROUP_AT_MESSAGE_CREATE(client, event, val, options);
|
|
852
|
+
if (tag === "INTERACTION_CREATE_C2C") return await C2C_MESSAGE_CREATE(client, event, val, options);
|
|
853
|
+
if (tag === "INTERACTION_CREATE_GUILD") return await AT_MESSAGE_CREATE(client, event, val);
|
|
854
|
+
if (GROUP_EVENT_REPLY_TAGS.has(tag) && event.MessageId) return await GROUP_AT_MESSAGE_CREATE(client, event, val, options);
|
|
855
|
+
if (C2C_EVENT_REPLY_TAGS.has(tag) && event.MessageId) return await C2C_MESSAGE_CREATE(client, event, val, options);
|
|
856
|
+
if (GROUP_NOTICE_TAGS.has(tag) && event.ChannelId) return await GROUP_AT_MESSAGE_CREATE(client, { ChannelId: event.ChannelId }, val, options);
|
|
857
|
+
if (C2C_NOTICE_TAGS.has(tag) && event.UserId) return await C2C_MESSAGE_CREATE(client, { UserId: event.UserId }, val, options);
|
|
858
|
+
return [createResult(ResultCode.Fail, `message.send: unsupported event tag "${tag}"`, null)];
|
|
859
|
+
},
|
|
860
|
+
mention: (event) => {
|
|
861
|
+
const value = event.value || {};
|
|
862
|
+
const Metions = [];
|
|
863
|
+
if (value.mentions) {
|
|
864
|
+
const MessageMention = (event.value["mentions"] || []).map((item) => {
|
|
865
|
+
const UserId = item.id;
|
|
866
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
867
|
+
return {
|
|
868
|
+
UserId: item.id,
|
|
869
|
+
IsMaster: isMaster,
|
|
870
|
+
UserName: item.username,
|
|
871
|
+
IsBot: item.bot ?? false,
|
|
872
|
+
UserKey
|
|
873
|
+
};
|
|
874
|
+
});
|
|
875
|
+
return new Promise((resolve) => resolve(MessageMention));
|
|
876
|
+
} else return new Promise((resolve) => resolve(Metions));
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
};
|
|
880
|
+
const onactions = async (data, consume) => {
|
|
881
|
+
const event = data.payload.event ?? {};
|
|
882
|
+
const getGroupOpenId = () => data.payload.ChannelId ?? data.payload.params?.groupOpenId ?? data.payload.GuildId ?? event.ChannelId ?? event.GuildId ?? "";
|
|
883
|
+
const getMemberOpenId = () => data.payload.params?.memberOpenId ?? data.payload.UserId ?? event.UserId ?? "";
|
|
884
|
+
const getGuildId = () => data.payload.GuildId ?? event.GuildId ?? "";
|
|
885
|
+
const getUserId = () => data.payload.UserId ?? event.UserId ?? "";
|
|
886
|
+
const getChannelId = () => data.payload.ChannelId ?? event.ChannelId ?? "";
|
|
887
|
+
try {
|
|
888
|
+
if (data.action === "me.info") {
|
|
889
|
+
const res = await client.usersMe();
|
|
890
|
+
const UserId = res.id;
|
|
891
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
892
|
+
const botInfo = {
|
|
893
|
+
UserId: res?.id,
|
|
894
|
+
UserName: res?.username,
|
|
895
|
+
UserAvatar: createUserAvatarURL(res?.id),
|
|
896
|
+
IsBot: true,
|
|
897
|
+
IsMaster: isMaster,
|
|
898
|
+
UserKey
|
|
899
|
+
};
|
|
900
|
+
consume([createResult(ResultCode.Ok, "请求完成", botInfo)]);
|
|
901
|
+
} else if (data.action === "message.send") {
|
|
902
|
+
const event = data.payload.event;
|
|
903
|
+
const paramFormat = data.payload.params.format;
|
|
904
|
+
const options = data.payload.params?.forceVerifyImageResource !== void 0 ? { forceVerifyImageResource: data.payload.params.forceVerifyImageResource } : void 0;
|
|
905
|
+
consume(await api.use.send(event, paramFormat, options));
|
|
906
|
+
} else if (data.action === "mention.get") {
|
|
907
|
+
const event = data.payload.event;
|
|
908
|
+
const metions = await api.use.mention(event);
|
|
909
|
+
consume([createResult(ResultCode.Ok, "请求完成", metions)]);
|
|
910
|
+
} else if (data.action === "message.send.channel") {
|
|
911
|
+
const channelId = data.payload.ChannelId;
|
|
912
|
+
const paramFormat = data.payload.params.format;
|
|
913
|
+
consume(await api.active.send.channel(channelId, paramFormat));
|
|
914
|
+
} else if (data.action === "message.send.user") {
|
|
915
|
+
const userId = data.payload.UserId;
|
|
916
|
+
const paramFormat = data.payload.params.format;
|
|
917
|
+
consume(await api.active.send.user(userId, paramFormat));
|
|
918
|
+
} else if (data.action === "message.send.target") {
|
|
919
|
+
const target = normalizeTarget(data.payload.target);
|
|
920
|
+
if (!target) {
|
|
921
|
+
consume([createResult(ResultCode.FailParams, "message.send.target 缺少 target", null)]);
|
|
922
|
+
return;
|
|
923
|
+
}
|
|
924
|
+
consume(await api.active.send.target(target, data.payload.params?.format || [], data.payload.params?.replyId));
|
|
925
|
+
} else if (data.action === "message.delete") {
|
|
926
|
+
const messageId = data.payload.MessageId;
|
|
927
|
+
const params = data.payload.params ?? {};
|
|
928
|
+
const target = normalizeTarget(data.payload.target);
|
|
929
|
+
if (target && !validateTargetBot(target)) {
|
|
930
|
+
consume([createResult(ResultCode.FailParams, `BotId ${target.BotId} is not active`, null)]);
|
|
931
|
+
return;
|
|
932
|
+
}
|
|
933
|
+
const scope = target?.scope ?? params.scope ?? params.messageType;
|
|
934
|
+
consume([await (scope === "group" ? client.grouMessageDelte(String(target?.targetId ?? params.groupId ?? data.payload.GroupId ?? data.payload.ChannelId), messageId) : scope === "user" || scope === "c2c" ? client.userMessageDelete(String(target?.targetId ?? params.userId ?? data.payload.UserId), messageId) : scope === "direct" ? client.dmsMessageDelete(String(target?.targetId ?? params.guildId ?? data.payload.GuildId ?? data.payload.ChannelId), messageId) : client.channelsMessagesDelete(target?.targetId ?? data.payload.ChannelId, messageId)).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
935
|
+
} else if (data.action === "interaction.ack") {
|
|
936
|
+
const params = data.payload.params ?? {};
|
|
937
|
+
const interactionId = String(params.interactionId ?? data.payload.InteractionId ?? "");
|
|
938
|
+
const mode = data.payload.target?.scope === "channel" || data.payload.target?.scope === "direct" || params.mode === "guild" ? "guild" : "group";
|
|
939
|
+
if (!interactionId) {
|
|
940
|
+
consume([createResult(ResultCode.Fail, "interaction.ack 缺少 InteractionId", null)]);
|
|
941
|
+
return;
|
|
942
|
+
}
|
|
943
|
+
const res = await client.interactionResponse(mode, interactionId, params.code).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err));
|
|
944
|
+
consume([res]);
|
|
945
|
+
consume([res]);
|
|
946
|
+
} else if (data.action === "message.pin") consume([await client.channelsPinsPut(getChannelId(), data.payload.MessageId).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
947
|
+
else if (data.action === "message.unpin") consume([await client.channelsPinsDelete(getChannelId(), data.payload.MessageId).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
948
|
+
else if (data.action === "reaction.add") consume([await client.channelsMessagesReactionsPut(getChannelId(), data.payload.MessageId, 1, data.payload.EmojiId).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
949
|
+
else if (data.action === "reaction.remove") consume([await client.channelsMessagesReactionsDelete(getChannelId(), data.payload.MessageId, 1, data.payload.EmojiId).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
950
|
+
else if (data.action === "message.get") consume([await client.channelsMessagesById(getChannelId(), data.payload.MessageId).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
951
|
+
else if (data.action === "interaction.response") {
|
|
952
|
+
const interactionId = data.payload.interaction_id;
|
|
953
|
+
const code = data.payload.code ?? 0;
|
|
954
|
+
consume([await client.interactionResponse("group", interactionId, code).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err?.response?.data ?? err?.message ?? err))]);
|
|
955
|
+
} else if (data.action === "member.info") {
|
|
956
|
+
const guildId = data.payload.params?.guildId ?? getGuildId();
|
|
957
|
+
const userId = data.payload.params?.userId ?? getUserId();
|
|
958
|
+
consume([await client.guildsMembersMessage(guildId, userId).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
959
|
+
} else if (data.action === "member.list") {
|
|
960
|
+
const guildId = getGuildId();
|
|
961
|
+
const after = data.payload.params?.After ?? "0";
|
|
962
|
+
const limit = data.payload.params?.Limit ?? 100;
|
|
963
|
+
consume([await client.guildsMembers(guildId, {
|
|
964
|
+
after,
|
|
965
|
+
limit
|
|
966
|
+
}).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
967
|
+
} else if (data.action === "member.kick") consume([await client.guildsMembersDelete(getGuildId(), getUserId()).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
968
|
+
else if (data.action === "member.ban") {
|
|
969
|
+
const guildId = getGuildId();
|
|
970
|
+
const userId = getUserId();
|
|
971
|
+
const duration = data.payload.params?.duration ?? 0;
|
|
972
|
+
const mute_seconds = String(duration > 0 ? duration : 604800);
|
|
973
|
+
consume([await client.guildsMemberMute(guildId, userId, { mute_seconds }).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
974
|
+
} else if (data.action === "member.unban") consume([await client.guildsMemberMute(getGuildId(), getUserId(), { mute_seconds: "0" }).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
975
|
+
else if (data.action === "member.mute") {
|
|
976
|
+
const guildId = getGuildId();
|
|
977
|
+
const userId = getUserId();
|
|
978
|
+
const duration = data.payload.params?.duration ?? 0;
|
|
979
|
+
const mute_seconds = String(duration);
|
|
980
|
+
consume([await client.guildsMemberMute(guildId, userId, { mute_seconds }).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
981
|
+
} else if (data.action === "guild.info") consume([await client.guilds(getGuildId()).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
982
|
+
else if (data.action === "guild.list") consume([await client.usersMeGuilds({
|
|
983
|
+
before: "",
|
|
984
|
+
after: "",
|
|
985
|
+
limit: 100
|
|
986
|
+
}).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
987
|
+
else if (data.action === "guild.mute") {
|
|
988
|
+
const guildId = getGuildId();
|
|
989
|
+
const duration = data.payload.params?.duration ?? 0;
|
|
990
|
+
const mute_seconds = String(duration);
|
|
991
|
+
consume([await client.guildsMuteAll(guildId, { mute_seconds }).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
992
|
+
} else if (data.action === "group.info") consume([await client.groupsInfo(getGroupOpenId()).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
993
|
+
else if (data.action === "group.botState") consume([await client.groupsBotState(getGroupOpenId()).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
994
|
+
else if (data.action === "group.member.info") consume([await client.groupsMembersMessage(getGroupOpenId(), getMemberOpenId()).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
995
|
+
else if (data.action === "group.joinRequest.list") {
|
|
996
|
+
const params = data.payload.params ?? {};
|
|
997
|
+
consume([await client.groupsJoinRequestList(getGroupOpenId(), {
|
|
998
|
+
cursor: params.cursor,
|
|
999
|
+
limit: params.limit
|
|
1000
|
+
}).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1001
|
+
} else if (data.action === "group.joinRequest.approve") {
|
|
1002
|
+
const params = data.payload.params ?? {};
|
|
1003
|
+
consume([await client.groupsApprovalJoinRequest(getGroupOpenId(), getMemberOpenId(), {
|
|
1004
|
+
op: params.op,
|
|
1005
|
+
join_request_id: params.joinRequestId,
|
|
1006
|
+
reject_reason: params.rejectReason,
|
|
1007
|
+
add_to_member_blacklist: params.addToMemberBlacklist
|
|
1008
|
+
}).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1009
|
+
} else if (data.action === "group.mute.setting") consume([await client.groupsRestrictChatSetting(getGroupOpenId()).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1010
|
+
else if (data.action === "group.mute.set") consume([await client.groupsRestrictChatSettingPost(getGroupOpenId(), { members: data.payload.params?.members }).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1011
|
+
else if (data.action === "group.strategy.list") {
|
|
1012
|
+
const params = data.payload.params ?? {};
|
|
1013
|
+
consume([await client.groupsJoinApprovalStrategies({
|
|
1014
|
+
cursor: params.cursor,
|
|
1015
|
+
limit: params.limit
|
|
1016
|
+
}).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1017
|
+
} else if (data.action === "group.strategy.create") {
|
|
1018
|
+
const params = data.payload.params ?? {};
|
|
1019
|
+
consume([await client.groupsJoinApprovalStrategyCreate({
|
|
1020
|
+
group_openids: params.groupOpenIds,
|
|
1021
|
+
group_ids: params.groupIds,
|
|
1022
|
+
is_enable: params.isEnable,
|
|
1023
|
+
expire_at: params.expireAt,
|
|
1024
|
+
remark: params.remark
|
|
1025
|
+
}).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1026
|
+
} else if (data.action === "group.strategy.update") {
|
|
1027
|
+
const params = data.payload.params ?? {};
|
|
1028
|
+
consume([await client.groupsJoinApprovalStrategyPatch(data.payload.StrategyId, {
|
|
1029
|
+
is_enable: params.isEnable,
|
|
1030
|
+
expire_at: params.expireAt,
|
|
1031
|
+
group_action: params.groupAction,
|
|
1032
|
+
remark: params.remark
|
|
1033
|
+
}).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1034
|
+
} else if (data.action === "group.strategy.delete") consume([await client.groupsJoinApprovalStrategyDelete(data.payload.StrategyId).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1035
|
+
else if (data.action === "group.strategy.execute") consume([await client.groupsJoinApprovalStrategyExecute(data.payload.StrategyId).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1036
|
+
else if (data.action === "group.strategy.whitelist") {
|
|
1037
|
+
const params = data.payload.params ?? {};
|
|
1038
|
+
consume([await client.groupsJoinApprovalStrategyWhitelistUsers(data.payload.StrategyId, {
|
|
1039
|
+
op: params.op,
|
|
1040
|
+
whitelist_users: params.whitelistUsers
|
|
1041
|
+
}).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1042
|
+
} else if (data.action === "channel.info") consume([await client.channels(getChannelId()).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1043
|
+
else if (data.action === "channel.list") consume([await client.guildsChannels(getGuildId()).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1044
|
+
else if (data.action === "channel.create") {
|
|
1045
|
+
const guildId = getGuildId();
|
|
1046
|
+
const params = data.payload.params;
|
|
1047
|
+
consume([await client.guildsChannelsCreate(guildId, {
|
|
1048
|
+
name: params.name,
|
|
1049
|
+
type: params.type ? Number(params.type) : 0,
|
|
1050
|
+
position: 0,
|
|
1051
|
+
parent_id: params.parentId ?? ""
|
|
1052
|
+
}).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1053
|
+
} else if (data.action === "channel.update") {
|
|
1054
|
+
const channelId = getChannelId();
|
|
1055
|
+
const params = data.payload.params;
|
|
1056
|
+
consume([await client.guildsChannelsUpdate(channelId, {
|
|
1057
|
+
name: params.name ?? "",
|
|
1058
|
+
position: params.position ?? 0
|
|
1059
|
+
}).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1060
|
+
} else if (data.action === "channel.delete") consume([await client.guildsChannelsdelete(getChannelId(), {}).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1061
|
+
else if (data.action === "role.list") consume([await client.guildsRoles(getGuildId()).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1062
|
+
else if (data.action === "role.create") {
|
|
1063
|
+
const params = data.payload.params;
|
|
1064
|
+
consume([await client.guildsRolesPost(getGuildId(), {
|
|
1065
|
+
name: params.name,
|
|
1066
|
+
color: params.color
|
|
1067
|
+
}).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1068
|
+
} else if (data.action === "role.update") {
|
|
1069
|
+
const params = data.payload.params;
|
|
1070
|
+
consume([await client.guildsRolesPatch(getGuildId(), data.payload.RoleId, {
|
|
1071
|
+
name: params.name,
|
|
1072
|
+
color: params.color
|
|
1073
|
+
}).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1074
|
+
} else if (data.action === "role.delete") consume([await client.guildsRolesDelete(getGuildId(), data.payload.RoleId).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1075
|
+
else if (data.action === "role.assign") consume([await client.guildsRolesMembersPut(getGuildId(), "", getUserId(), data.payload.RoleId).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1076
|
+
else if (data.action === "role.remove") consume([await client.guildsRolesMembersDelete(getGuildId(), "", getUserId(), data.payload.RoleId).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1077
|
+
else if (data.action === "file.send.channel") consume([await client.postRichMediaByGroup(getGroupOpenId(), {
|
|
1078
|
+
file_type: data.payload.params?.file_type ?? 1,
|
|
1079
|
+
url: data.payload.params?.url,
|
|
1080
|
+
file_data: data.payload.params?.file_data,
|
|
1081
|
+
srv_send_msg: data.payload.params?.srv_send_msg ?? false
|
|
1082
|
+
}).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1083
|
+
else if (data.action === "file.send.user") consume([await client.postRichMediaByUser(getUserId(), {
|
|
1084
|
+
file_type: data.payload.params?.file_type ?? 1,
|
|
1085
|
+
url: data.payload.params?.url,
|
|
1086
|
+
file_data: data.payload.params?.file_data,
|
|
1087
|
+
srv_send_msg: data.payload.params?.srv_send_msg ?? false
|
|
1088
|
+
}).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1089
|
+
else if (data.action === "me.guilds") consume([await client.usersMeGuilds({
|
|
1090
|
+
before: "",
|
|
1091
|
+
after: "",
|
|
1092
|
+
limit: 100
|
|
1093
|
+
}).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1094
|
+
else if (data.action === "media.send.channel") consume([createResult(ResultCode.Warn, "media.send.channel not directly supported, use message.send with format", null)]);
|
|
1095
|
+
else if (data.action === "media.send.user") {
|
|
1096
|
+
const userId = getUserId();
|
|
1097
|
+
const params = data.payload.params;
|
|
1098
|
+
const fileType = params?.type === "image" ? 1 : params?.type === "video" ? 2 : params?.type === "audio" ? 3 : 4;
|
|
1099
|
+
consume([await client.postRichMediaByUser(userId, {
|
|
1100
|
+
file_type: fileType,
|
|
1101
|
+
url: params?.url,
|
|
1102
|
+
file_data: params?.data
|
|
1103
|
+
}).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1104
|
+
} else if (data.action === "media.upload") {
|
|
1105
|
+
const target = normalizeTarget(data.payload.target);
|
|
1106
|
+
if (!target) {
|
|
1107
|
+
consume([createResult(ResultCode.Warn, "QQ media.upload requires target", null)]);
|
|
1108
|
+
return;
|
|
1109
|
+
}
|
|
1110
|
+
consume([await uploadMedia(target, data.payload.params || {}).then((value) => createResult(ResultCode.Ok, data.action, value)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1111
|
+
} else if (data.action === "media.send") {
|
|
1112
|
+
const target = normalizeTarget(data.payload.target);
|
|
1113
|
+
if (!target) {
|
|
1114
|
+
consume([createResult(ResultCode.FailParams, "media.send 缺少 target", null)]);
|
|
1115
|
+
return;
|
|
1116
|
+
}
|
|
1117
|
+
if (!validateTargetBot(target)) {
|
|
1118
|
+
consume([createResult(ResultCode.FailParams, `BotId ${target.BotId} is not active`, null)]);
|
|
1119
|
+
return;
|
|
1120
|
+
}
|
|
1121
|
+
const params = data.payload.params || {};
|
|
1122
|
+
if (params.fileId) {
|
|
1123
|
+
const send = target.scope === "group" ? client.groupOpenMessages(target.targetId, {
|
|
1124
|
+
msg_type: 7,
|
|
1125
|
+
content: params.content || "",
|
|
1126
|
+
media: { file_info: params.fileId }
|
|
1127
|
+
}) : target.scope === "c2c" ? client.usersOpenMessages(target.targetId, {
|
|
1128
|
+
msg_type: 7,
|
|
1129
|
+
content: params.content || "",
|
|
1130
|
+
media: { file_info: params.fileId }
|
|
1131
|
+
}) : null;
|
|
1132
|
+
if (!send) {
|
|
1133
|
+
consume([createResult(ResultCode.Warn, "QQ media.send only supports group and c2c targets", null)]);
|
|
1134
|
+
return;
|
|
1135
|
+
}
|
|
1136
|
+
consume([await send.then((value) => createResult(ResultCode.Ok, data.action, { id: value.id })).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1137
|
+
return;
|
|
1138
|
+
}
|
|
1139
|
+
const upload = await uploadMedia(target, params).then((value) => value.fileId).catch((error) => {
|
|
1140
|
+
consume([createResult(ResultCode.Fail, data.action, error)]);
|
|
1141
|
+
return null;
|
|
1142
|
+
});
|
|
1143
|
+
if (!upload) return;
|
|
1144
|
+
await onactions({
|
|
1145
|
+
action: "media.send",
|
|
1146
|
+
payload: {
|
|
1147
|
+
target,
|
|
1148
|
+
params: {
|
|
1149
|
+
...params,
|
|
1150
|
+
fileId: upload,
|
|
1151
|
+
url: void 0,
|
|
1152
|
+
data: void 0,
|
|
1153
|
+
filePath: void 0
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1156
|
+
}, consume);
|
|
1157
|
+
} else if (data.action === "connection.status") {
|
|
1158
|
+
const status = client.getConnectionStatus();
|
|
1159
|
+
consume([createResult(ResultCode.Ok, data.action, {
|
|
1160
|
+
Platform: platform,
|
|
1161
|
+
state: status.state,
|
|
1162
|
+
bots: [{
|
|
1163
|
+
BotId: botId,
|
|
1164
|
+
...status
|
|
1165
|
+
}]
|
|
1166
|
+
})]);
|
|
1167
|
+
} else if (data.action === "media.upload.prepare") {
|
|
1168
|
+
const userId = getUserId();
|
|
1169
|
+
const groupId = getGroupOpenId();
|
|
1170
|
+
consume([await (userId ? client.usersUploadPrepare(userId, data.payload.params) : client.groupUploadPrepare(groupId, data.payload.params)).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err?.response?.data ?? err?.message ?? err))]);
|
|
1171
|
+
} else if (data.action === "media.upload.part.finish") {
|
|
1172
|
+
const userId = getUserId();
|
|
1173
|
+
const groupId = getGroupOpenId();
|
|
1174
|
+
consume([await (userId ? client.usersUploadPartFinish(userId, data.payload.params) : client.groupUploadPartFinish(groupId, data.payload.params)).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err?.response?.data ?? err?.message ?? err))]);
|
|
1175
|
+
} else if (data.action === "media.upload.chunked") {
|
|
1176
|
+
const userId = getUserId();
|
|
1177
|
+
const groupId = getGroupOpenId();
|
|
1178
|
+
const params = data.payload.params ?? {};
|
|
1179
|
+
consume([await chunkedUpload(client, userId ? "user" : "group", userId || groupId, params.file ?? params.file_path, {
|
|
1180
|
+
file_type: params.file_type ?? 1,
|
|
1181
|
+
file_name: params.file_name,
|
|
1182
|
+
srv_send_msg: params.srv_send_msg
|
|
1183
|
+
}).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err?.response?.data ?? err?.message ?? err))]);
|
|
1184
|
+
} else if (data.action === "stream.message.send") consume([await client.streamMessages(getUserId(), data.payload.params ?? {}).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err?.response?.data ?? err?.message ?? err))]);
|
|
1185
|
+
else if (data.action === "message.input.notify") {
|
|
1186
|
+
const params = data.payload.params ?? {};
|
|
1187
|
+
consume([await client.usersOpenMessages(getUserId(), {
|
|
1188
|
+
msg_type: 6,
|
|
1189
|
+
input_notify: {
|
|
1190
|
+
input_type: params.input_type ?? 1,
|
|
1191
|
+
input_second: params.input_second ?? 60
|
|
1192
|
+
},
|
|
1193
|
+
msg_seq: params.msg_seq,
|
|
1194
|
+
msg_id: params.msg_id
|
|
1195
|
+
}).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err?.response?.data ?? err?.message ?? err))]);
|
|
1196
|
+
} else if (data.action === "permission.get") consume([await client.channelsPermissions(getChannelId(), getUserId()).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1197
|
+
else if (data.action === "permission.set") {
|
|
1198
|
+
const params = data.payload.params;
|
|
1199
|
+
consume([await client.channelsPermissionsPut(getChannelId(), getUserId(), params?.allow ?? "0", params?.deny ?? "0").then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1200
|
+
} else if (data.action === "reaction.list") consume([await client.channelsMessagesReactionsUsers(getChannelId(), data.payload.MessageId, 1, data.payload.EmojiId, { limit: data.payload.params?.limit ?? 20 }).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1201
|
+
else if (data.action === "channel.announce") {
|
|
1202
|
+
const guildId = getGuildId();
|
|
1203
|
+
const params = data.payload.params;
|
|
1204
|
+
if (params?.remove) consume([await client.guildsAnnouncesDelete(guildId, params?.messageId ?? "all").then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1205
|
+
else consume([await client.guildsAnnounces(guildId, {
|
|
1206
|
+
message_id: params?.messageId,
|
|
1207
|
+
channel_id: params?.channelId
|
|
1208
|
+
}).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1209
|
+
} else consume([createResult(ResultCode.Fail, "未知请求,请尝试升级版本", null)]);
|
|
1210
|
+
} catch (error) {
|
|
1211
|
+
consume([createResult(ResultCode.Fail, "请求失败", error)]);
|
|
1212
|
+
}
|
|
1213
|
+
};
|
|
1214
|
+
const onapis = async (data, consume) => {
|
|
1215
|
+
const key = data.payload?.key;
|
|
1216
|
+
const params = data.payload?.params;
|
|
1217
|
+
try {
|
|
1218
|
+
const keys = key.split(".");
|
|
1219
|
+
let parent = null;
|
|
1220
|
+
let target = client;
|
|
1221
|
+
for (const k of keys) {
|
|
1222
|
+
if (target === null || target === void 0 || !(k in target)) {
|
|
1223
|
+
consume([createResult(ResultCode.Fail, "未知请求,请尝试升级版本", null)]);
|
|
1224
|
+
return;
|
|
1225
|
+
}
|
|
1226
|
+
parent = target;
|
|
1227
|
+
target = target[k];
|
|
1228
|
+
}
|
|
1229
|
+
if (typeof target !== "function") {
|
|
1230
|
+
consume([createResult(ResultCode.Fail, "目标不是可调用方法", null)]);
|
|
1231
|
+
return;
|
|
1232
|
+
}
|
|
1233
|
+
const res = await target.call(parent, ...params);
|
|
1234
|
+
consume([createResult(ResultCode.Ok, "请求完成", res)]);
|
|
1235
|
+
} catch (error) {
|
|
1236
|
+
consume([createResult(ResultCode.Fail, "请求失败", error)]);
|
|
1237
|
+
}
|
|
1238
|
+
};
|
|
1239
|
+
if (options?.bindActions !== false) {
|
|
1240
|
+
cbp.onactions((data, consume) => void onactions(data, consume));
|
|
1241
|
+
cbp.onapis((data, consume) => void onapis(data, consume));
|
|
1242
|
+
}
|
|
1243
|
+
return {
|
|
1244
|
+
onAction: onactions,
|
|
1245
|
+
onApi: onapis
|
|
1246
|
+
};
|
|
1406
1247
|
};
|
|
1407
1248
|
|
|
1408
|
-
|
|
1249
|
+
//#endregion
|
|
1250
|
+
export { register };
|