@alemonjs/qq-bot 2.1.36 → 2.1.38
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 +68 -1979
- package/lib/config.d.ts +5 -0
- package/lib/framework-actions.d.ts +75 -0
- package/lib/framework-actions.js +620 -0
- package/lib/framework-events.d.ts +10 -0
- package/lib/framework-events.js +182 -0
- package/lib/hook.d.ts +16 -12
- package/lib/hook.js +5 -9
- package/lib/index.d.ts +6 -1
- package/lib/index.js +2 -1
- package/lib/index.websoket.js +6 -2
- package/lib/message/AUDIO_EVENT.d.ts +20 -0
- package/lib/message/AUDIO_EVENT.js +1 -0
- package/lib/message/FORUM_EVENT.d.ts +33 -0
- package/lib/message/FORUM_EVENT.js +1 -0
- package/lib/message/GUILD_AUDIT.d.ts +14 -0
- package/lib/message/GUILD_AUDIT.js +1 -0
- package/lib/message/INTERACTION_CREATE.d.ts +13 -20
- package/lib/message/MESSAGE_CREATE.d.ts +3 -9
- package/lib/message/MESSAGE_DELETE.d.ts +15 -1
- package/lib/message/group/C2C_MESSAGE_CREATE.d.ts +3 -13
- package/lib/message/group/C2C_MSG_RECEIVE.d.ts +1 -1
- package/lib/message/group/C2C_MSG_REJECT.d.ts +1 -1
- package/lib/message/group/FRIEND_ADD.d.ts +7 -1
- package/lib/message/group/FRIEND_DEL.d.ts +4 -1
- package/lib/message/group/GROUP_AT_MESSAGE_CREATE.d.ts +6 -27
- package/lib/message/group/GROUP_MEMBER_ADD.d.ts +4 -2
- package/lib/message/group/GROUP_MEMBER_REMOVE.d.ts +4 -2
- package/lib/message/group/GROUP_MESSAGE_CREATE.d.ts +6 -27
- package/lib/message/group/GROUP_MSG_RECEIVE.d.ts +1 -1
- package/lib/message/group/GROUP_MSG_REJECT.d.ts +1 -1
- package/lib/message/group/MESSAGE_AUDIT_PASS.d.ts +2 -0
- package/lib/message/group/MESSAGE_AUDIT_REJECT.d.ts +2 -0
- package/lib/message/group/SUBSCRIBE_MESSAGE_STATUS.d.ts +17 -0
- package/lib/message/group/SUBSCRIBE_MESSAGE_STATUS.js +1 -0
- package/lib/register.d.ts +1 -0
- package/lib/register.js +287 -115
- package/lib/sdk/api.d.ts +93 -14
- package/lib/sdk/api.js +241 -45
- package/lib/sdk/client.webhook.js +39 -19
- package/lib/sdk/client.websoket.js +2 -1
- package/lib/sdk/instance.d.ts +1 -6
- package/lib/sdk/instance.js +20 -66
- package/lib/sdk/intents.d.ts +1 -0
- package/lib/sdk/intents.js +1 -0
- package/lib/sdk/message.d.ts +1 -1
- package/lib/sdk/message.group.d.ts +4 -2
- package/lib/sdk/message.guild.d.ts +19 -0
- package/lib/sdk/non-channel-types.d.ts +138 -0
- package/lib/sdk/non-channel-types.js +1 -0
- package/lib/sdk/registry.js +2 -2
- package/lib/sdk/typing.d.ts +13 -1
- package/lib/sdk/webhook.secret.d.ts +1 -1
- package/lib/sdk/webhook.secret.js +10 -5
- package/lib/sends.d.ts +3 -3
- package/lib/sends.js +46 -10
- package/lib/text-sanitizer.d.ts +13 -0
- package/lib/text-sanitizer.js +26 -0
- package/lib/upload.js +13 -37
- package/package.json +8 -6
package/lib/register.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { getIdentity, getMaster, getQQBotConfig, platform } from "./config.js";
|
|
2
|
-
import {
|
|
2
|
+
import { sanitizeQQText } from "./text-sanitizer.js";
|
|
3
3
|
import { AT_MESSAGE_CREATE, C2C_MESSAGE_CREATE, DIRECT_MESSAGE_CREATE, GROUP_AT_MESSAGE_CREATE, MESSAGE_CREATE } from "./sends.js";
|
|
4
|
+
import { normalizeFrameworkEvent, normalizeMessageUser } from "./framework-events.js";
|
|
5
|
+
import { handleFrameworkAction } from "./framework-actions.js";
|
|
6
|
+
import { chunkedUpload } from "./upload.js";
|
|
4
7
|
import { FormatEvent, ResultCode, cbpPlatform, createResult, logger } from "alemonjs";
|
|
5
8
|
import { createHash } from "node:crypto";
|
|
6
9
|
import { basename } from "node:path";
|
|
@@ -40,11 +43,19 @@ const C2C_NOTICE_TAGS = /* @__PURE__ */ new Set([
|
|
|
40
43
|
"FRIEND_DEL"
|
|
41
44
|
]);
|
|
42
45
|
const register = (client, options) => {
|
|
43
|
-
const MAX_MEDIA_SIZE =
|
|
46
|
+
const MAX_MEDIA_SIZE = 209715200;
|
|
44
47
|
const config = getQQBotConfig();
|
|
45
48
|
const botId = String(options?.botId ?? config?.app_id ?? "");
|
|
46
49
|
const url = `ws://127.0.0.1:${process.env?.port || config?.port || 17117}`;
|
|
47
50
|
const cbp = options?.cbp ?? cbpPlatform(url);
|
|
51
|
+
const emit = (event, acknowledged = false) => {
|
|
52
|
+
const normalized = normalizeFrameworkEvent(event, acknowledged);
|
|
53
|
+
if (config.textSanitizer && (normalized.name === "message.create" || normalized.name === "private.message.create") && typeof normalized.value?.content === "string") {
|
|
54
|
+
normalized.RawMessageText = normalized.value.content;
|
|
55
|
+
normalized.MessageText = sanitizeQQText(normalized.value.content, botId, config.textSanitizer);
|
|
56
|
+
}
|
|
57
|
+
cbp.send(normalized);
|
|
58
|
+
};
|
|
48
59
|
/**
|
|
49
60
|
* group
|
|
50
61
|
*
|
|
@@ -56,9 +67,9 @@ const register = (client, options) => {
|
|
|
56
67
|
};
|
|
57
68
|
const getGroupMessageMeta = (event) => {
|
|
58
69
|
const author = event?.author;
|
|
59
|
-
const UserId = author?.id
|
|
70
|
+
const UserId = author?.member_openid || author?.id || "";
|
|
60
71
|
const memberOpenId = author?.member_openid ?? "";
|
|
61
|
-
const groupId = event?.
|
|
72
|
+
const groupId = event?.group_openid || event?.group_id || "";
|
|
62
73
|
const messageId = event?.id ?? "";
|
|
63
74
|
const [isMaster, UserKey] = UserId ? getMaster(UserId) : [false, ""];
|
|
64
75
|
return {
|
|
@@ -72,9 +83,10 @@ const register = (client, options) => {
|
|
|
72
83
|
openId: memberOpenId ? `C2C:${memberOpenId}` : ""
|
|
73
84
|
};
|
|
74
85
|
};
|
|
75
|
-
const
|
|
86
|
+
const getAuditMeta = (event) => {
|
|
76
87
|
return {
|
|
77
|
-
|
|
88
|
+
guildId: event?.guild_id ?? event?.group_openid ?? "",
|
|
89
|
+
channelId: event?.channel_id ?? event?.group_openid ?? "",
|
|
78
90
|
messageId: event?.message_id ?? event?.audit_id ?? "",
|
|
79
91
|
auditTime: event?.audit_time ?? ""
|
|
80
92
|
};
|
|
@@ -84,7 +96,7 @@ const register = (client, options) => {
|
|
|
84
96
|
if (!attachment?.url) return [];
|
|
85
97
|
const mimeType = attachment.content_type || "";
|
|
86
98
|
return [{
|
|
87
|
-
Type: mimeType.startsWith("image/") ? "image" : mimeType.startsWith("audio/") ? "audio" : mimeType.startsWith("video/") ? "video" : "file",
|
|
99
|
+
Type: mimeType.startsWith("image/") ? "image" : mimeType === "voice" || mimeType.startsWith("audio/") ? "audio" : mimeType.startsWith("video/") ? "video" : "file",
|
|
88
100
|
Url: attachment.url,
|
|
89
101
|
...attachment.filename && { FileName: attachment.filename },
|
|
90
102
|
...typeof attachment.size === "number" && { FileSize: attachment.size },
|
|
@@ -122,7 +134,7 @@ const register = (client, options) => {
|
|
|
122
134
|
if (params.filePath) {
|
|
123
135
|
const metadata = await stat(String(params.filePath));
|
|
124
136
|
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
|
|
137
|
+
if (metadata.size > MAX_MEDIA_SIZE) throw new Error("QQ media files must not exceed 200 MiB");
|
|
126
138
|
filePath = String(params.filePath);
|
|
127
139
|
fileSize = metadata.size;
|
|
128
140
|
hashes = await client.getMediaFileHashes(filePath);
|
|
@@ -136,22 +148,23 @@ const register = (client, options) => {
|
|
|
136
148
|
hashSource = data;
|
|
137
149
|
const value = data.replace(/^base64:\/\//, "");
|
|
138
150
|
buffer = Buffer.from(value, "base64");
|
|
139
|
-
if (buffer.length > MAX_MEDIA_SIZE) throw new Error("QQ media files must not exceed
|
|
151
|
+
if (buffer.length > MAX_MEDIA_SIZE) throw new Error("QQ media files must not exceed 200 MiB");
|
|
140
152
|
}
|
|
141
|
-
const key = [
|
|
153
|
+
const key = JSON.stringify([
|
|
142
154
|
botId,
|
|
143
155
|
target.scope,
|
|
144
156
|
target.targetId,
|
|
145
157
|
params.type,
|
|
158
|
+
name ?? "",
|
|
146
159
|
createHash("sha256").update(hashSource).digest("hex")
|
|
147
|
-
]
|
|
160
|
+
]);
|
|
148
161
|
const cached = mediaCache.get(key);
|
|
149
|
-
if (cached &&
|
|
150
|
-
|
|
151
|
-
expiresAt: cached.expiresAt,
|
|
162
|
+
if (!params.send && cached && cached.expiresAt && cached.expiresAt > Date.now()) return {
|
|
163
|
+
...cached,
|
|
152
164
|
reused: true
|
|
153
165
|
};
|
|
154
166
|
return {
|
|
167
|
+
fileId: void 0,
|
|
155
168
|
key,
|
|
156
169
|
url: params.url,
|
|
157
170
|
data,
|
|
@@ -167,7 +180,22 @@ const register = (client, options) => {
|
|
|
167
180
|
if (!validateTargetBot(target)) throw new Error(`BotId ${target.BotId} is not active`);
|
|
168
181
|
if (target.scope !== "group" && target.scope !== "c2c") throw new Error("QQ media upload only supports group and c2c targets");
|
|
169
182
|
const prepared = await prepareMedia(target, params);
|
|
170
|
-
if (prepared.fileId)
|
|
183
|
+
if (prepared.fileId) {
|
|
184
|
+
if (params.send) {
|
|
185
|
+
const sent = target.scope === "group" ? await client.groupOpenMessages(target.targetId, {
|
|
186
|
+
msg_type: 7,
|
|
187
|
+
media: { file_info: prepared.fileId }
|
|
188
|
+
}) : await client.usersOpenMessages(target.targetId, {
|
|
189
|
+
msg_type: 7,
|
|
190
|
+
media: { file_info: prepared.fileId }
|
|
191
|
+
});
|
|
192
|
+
return {
|
|
193
|
+
...prepared,
|
|
194
|
+
messageId: sent.id
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
return prepared;
|
|
198
|
+
}
|
|
171
199
|
const fileType = mediaType(params.type);
|
|
172
200
|
const value = prepared.filePath && prepared.fileSize && prepared.fileSize >= 5242880 ? await client.postChunkedRichMedia({
|
|
173
201
|
scope: target.scope,
|
|
@@ -187,20 +215,37 @@ const register = (client, options) => {
|
|
|
187
215
|
file_type: fileType,
|
|
188
216
|
url: prepared.url,
|
|
189
217
|
file_data: prepared.data,
|
|
190
|
-
|
|
218
|
+
file_name: prepared.name,
|
|
219
|
+
srv_send_msg: params.send ?? false
|
|
191
220
|
}) : await client.postRichMediaByUser(target.targetId, {
|
|
192
221
|
file_type: fileType,
|
|
193
222
|
url: prepared.url,
|
|
194
223
|
file_data: prepared.data,
|
|
195
|
-
|
|
224
|
+
file_name: prepared.name,
|
|
225
|
+
srv_send_msg: params.send ?? false
|
|
196
226
|
});
|
|
227
|
+
let messageId = "id" in value ? value.id : void 0;
|
|
228
|
+
if (params.send && !messageId && ((prepared.fileSize ?? 0) >= 5242880 || (prepared.buffer?.length ?? 0) >= 5242880)) messageId = (target.scope === "group" ? await client.groupOpenMessages(target.targetId, {
|
|
229
|
+
msg_type: 7,
|
|
230
|
+
media: { file_info: value.file_info }
|
|
231
|
+
}) : await client.usersOpenMessages(target.targetId, {
|
|
232
|
+
msg_type: 7,
|
|
233
|
+
media: { file_info: value.file_info }
|
|
234
|
+
})).id;
|
|
197
235
|
const expiresAt = value.ttl ? Date.now() + value.ttl * 1e3 : void 0;
|
|
198
|
-
if (prepared.key) mediaCache.set(prepared.key, {
|
|
236
|
+
if (prepared.key && expiresAt) mediaCache.set(prepared.key, {
|
|
199
237
|
fileId: value.file_info,
|
|
238
|
+
uuid: value.file_uuid,
|
|
239
|
+
ttl: value.ttl,
|
|
240
|
+
url: value.raw_url,
|
|
200
241
|
expiresAt
|
|
201
242
|
});
|
|
202
243
|
return {
|
|
203
244
|
fileId: value.file_info,
|
|
245
|
+
uuid: value.file_uuid,
|
|
246
|
+
ttl: value.ttl,
|
|
247
|
+
messageId,
|
|
248
|
+
url: "raw_url" in value ? value.raw_url : void 0,
|
|
204
249
|
expiresAt,
|
|
205
250
|
reused: false
|
|
206
251
|
};
|
|
@@ -216,7 +261,7 @@ const register = (client, options) => {
|
|
|
216
261
|
};
|
|
217
262
|
};
|
|
218
263
|
client.on("GROUP_ADD_ROBOT", (event) => {
|
|
219
|
-
|
|
264
|
+
emit(FormatEvent.create("guild.join").addPlatform({
|
|
220
265
|
Platform: platform,
|
|
221
266
|
value: event,
|
|
222
267
|
BotId: botId
|
|
@@ -226,7 +271,7 @@ const register = (client, options) => {
|
|
|
226
271
|
}).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
272
|
});
|
|
228
273
|
client.on("GROUP_DEL_ROBOT", (event) => {
|
|
229
|
-
|
|
274
|
+
emit(FormatEvent.create("guild.exit").addPlatform({
|
|
230
275
|
Platform: platform,
|
|
231
276
|
value: event,
|
|
232
277
|
BotId: botId
|
|
@@ -239,7 +284,7 @@ const register = (client, options) => {
|
|
|
239
284
|
if (event?.author?.bot) return;
|
|
240
285
|
const msg = getMessageContent(event);
|
|
241
286
|
const meta = getGroupMessageMeta(event);
|
|
242
|
-
|
|
287
|
+
emit(FormatEvent.create("message.create").addPlatform({
|
|
243
288
|
Platform: platform,
|
|
244
289
|
value: event,
|
|
245
290
|
BotId: botId,
|
|
@@ -258,9 +303,9 @@ const register = (client, options) => {
|
|
|
258
303
|
}).addMessage({ MessageId: meta.messageId }).addText({ MessageText: msg?.trim() }).addMedia({ MessageMedia: getMediaItems(event.attachments) }).addOpen({ OpenId: meta.openId }).add({ tag: "GROUP_MESSAGE_CREATE" }).value);
|
|
259
304
|
});
|
|
260
305
|
client.on("GROUP_MEMBER_ADD", (event) => {
|
|
261
|
-
const UserId = event.
|
|
306
|
+
const UserId = event.member_openid || event.op_member_openid || "";
|
|
262
307
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
263
|
-
|
|
308
|
+
emit(FormatEvent.create("member.add").addPlatform({
|
|
264
309
|
Platform: platform,
|
|
265
310
|
value: event,
|
|
266
311
|
BotId: botId
|
|
@@ -277,9 +322,9 @@ const register = (client, options) => {
|
|
|
277
322
|
}).add({ tag: "GROUP_MEMBER_ADD" }).value);
|
|
278
323
|
});
|
|
279
324
|
client.on("GROUP_MEMBER_REMOVE", (event) => {
|
|
280
|
-
const UserId = event.
|
|
325
|
+
const UserId = event.member_openid || event.op_member_openid || "";
|
|
281
326
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
282
|
-
|
|
327
|
+
emit(FormatEvent.create("member.remove").addPlatform({
|
|
283
328
|
Platform: platform,
|
|
284
329
|
value: event,
|
|
285
330
|
BotId: botId
|
|
@@ -298,7 +343,7 @@ const register = (client, options) => {
|
|
|
298
343
|
client.on("GROUP_JOIN_REQUEST", (event) => {
|
|
299
344
|
const UserId = event.member_openid ?? "";
|
|
300
345
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
301
|
-
|
|
346
|
+
emit(FormatEvent.create("notice.create").addPlatform({
|
|
302
347
|
Platform: platform,
|
|
303
348
|
value: event,
|
|
304
349
|
BotId: botId
|
|
@@ -318,7 +363,7 @@ const register = (client, options) => {
|
|
|
318
363
|
if (event?.author?.bot) return;
|
|
319
364
|
const msg = getMessageContent(event);
|
|
320
365
|
const meta = getGroupMessageMeta(event);
|
|
321
|
-
|
|
366
|
+
emit(FormatEvent.create("message.create").addPlatform({
|
|
322
367
|
Platform: platform,
|
|
323
368
|
value: event,
|
|
324
369
|
BotId: botId,
|
|
@@ -337,23 +382,23 @@ const register = (client, options) => {
|
|
|
337
382
|
}).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
383
|
});
|
|
339
384
|
client.on("C2C_MESSAGE_CREATE", (event) => {
|
|
340
|
-
const UserId = event.author.id;
|
|
385
|
+
const UserId = event.author.user_openid || event.author.id;
|
|
341
386
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
342
|
-
const UserAvatar = createUserAvatarURL(
|
|
343
|
-
|
|
387
|
+
const UserAvatar = createUserAvatarURL(UserId);
|
|
388
|
+
emit(FormatEvent.create("private.message.create").addPlatform({
|
|
344
389
|
Platform: platform,
|
|
345
390
|
value: event,
|
|
346
391
|
BotId: botId,
|
|
347
392
|
IsAtMe: false,
|
|
348
393
|
IsPrivate: true
|
|
349
394
|
}).addUser({
|
|
350
|
-
UserId
|
|
395
|
+
UserId,
|
|
351
396
|
UserKey,
|
|
352
397
|
UserAvatar,
|
|
353
398
|
UserName: event?.author?.username,
|
|
354
399
|
IsMaster: isMaster,
|
|
355
400
|
IsBot: false
|
|
356
|
-
}).addMessage({ MessageId: event.id }).addText({ MessageText: event.content?.trim() }).addMedia({ MessageMedia: getMediaItems(event.attachments) }).addOpen({ OpenId: `C2C:${
|
|
401
|
+
}).addMessage({ MessageId: event.id }).addText({ MessageText: event.content?.trim() }).addMedia({ MessageMedia: getMediaItems(event.attachments) }).addOpen({ OpenId: `C2C:${UserId}` }).add({ tag: "C2C_MESSAGE_CREATE" }).value);
|
|
357
402
|
});
|
|
358
403
|
/**
|
|
359
404
|
* guild
|
|
@@ -364,7 +409,7 @@ const register = (client, options) => {
|
|
|
364
409
|
const UserAvatar = event?.author?.avatar;
|
|
365
410
|
const UserId = event.author.id;
|
|
366
411
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
367
|
-
|
|
412
|
+
emit(FormatEvent.create("private.message.create").addPlatform({
|
|
368
413
|
Platform: platform,
|
|
369
414
|
value: event,
|
|
370
415
|
BotId: botId,
|
|
@@ -385,7 +430,7 @@ const register = (client, options) => {
|
|
|
385
430
|
const UserAvatar = event?.author?.avatar;
|
|
386
431
|
const UserId = event.author.id;
|
|
387
432
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
388
|
-
|
|
433
|
+
emit(FormatEvent.create("message.create").addPlatform({
|
|
389
434
|
Platform: platform,
|
|
390
435
|
value: event,
|
|
391
436
|
BotId: botId,
|
|
@@ -421,12 +466,11 @@ const register = (client, options) => {
|
|
|
421
466
|
};
|
|
422
467
|
client.on("MESSAGE_CREATE", (event) => {
|
|
423
468
|
if (event.author?.bot) return;
|
|
424
|
-
if ((/* @__PURE__ */ new RegExp(/DELETE$/)).test(event.eventType)) return;
|
|
425
469
|
const UserId = event.author.id;
|
|
426
470
|
const msg = getMessageContent(event);
|
|
427
471
|
const UserAvatar = event?.author?.avatar;
|
|
428
472
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
429
|
-
|
|
473
|
+
emit(FormatEvent.create("message.create").addPlatform({
|
|
430
474
|
Platform: platform,
|
|
431
475
|
value: event,
|
|
432
476
|
BotId: botId,
|
|
@@ -445,16 +489,18 @@ const register = (client, options) => {
|
|
|
445
489
|
}).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
490
|
});
|
|
447
491
|
client.on("INTERACTION_CREATE", async (event) => {
|
|
448
|
-
|
|
492
|
+
let acknowledged = false;
|
|
493
|
+
if ((options?.autoInteractionAck ?? config.autoInteractionAck ?? true) && (event.type === 11 || event.type === 12)) try {
|
|
449
494
|
await client.interactionResponse("group", event.id, 0);
|
|
495
|
+
acknowledged = true;
|
|
450
496
|
} catch (err) {
|
|
451
|
-
|
|
497
|
+
logger.warn("interactionResponse failed", err?.response?.data ?? err?.message ?? err);
|
|
452
498
|
}
|
|
453
499
|
if (event.scene === "group") {
|
|
454
500
|
const UserAvatar = createUserAvatarURL(event.group_member_openid);
|
|
455
501
|
const UserId = event.group_member_openid;
|
|
456
502
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
457
|
-
const MessageText = event.data
|
|
503
|
+
const MessageText = event.data?.resolved?.button_data?.trim() || "";
|
|
458
504
|
const e = FormatEvent.create("interaction.create").addPlatform({
|
|
459
505
|
Platform: platform,
|
|
460
506
|
value: event,
|
|
@@ -470,21 +516,21 @@ const register = (client, options) => {
|
|
|
470
516
|
UserAvatar,
|
|
471
517
|
IsMaster: isMaster,
|
|
472
518
|
IsBot: false
|
|
473
|
-
}).addMessage({ MessageId: event.id }).addText({ MessageText }).addInteraction({
|
|
519
|
+
}).addMessage({ MessageId: event.event_id || event.id }).addText({ MessageText }).addInteraction({
|
|
474
520
|
InteractionId: event.id,
|
|
475
|
-
InteractionData: JSON.stringify(event.data
|
|
521
|
+
InteractionData: JSON.stringify(event.data?.resolved ?? {}),
|
|
476
522
|
Target: {
|
|
477
523
|
scope: "group",
|
|
478
524
|
targetId: event.group_openid,
|
|
479
525
|
BotId: botId
|
|
480
526
|
}
|
|
481
527
|
}).addOpen({ OpenId: `C2C:${event.group_member_openid}` }).add({ tag: "INTERACTION_CREATE_GROUP" }).value;
|
|
482
|
-
|
|
528
|
+
emit(e, acknowledged);
|
|
483
529
|
} else if (event.scene === "c2c") {
|
|
484
530
|
const UserAvatar = createUserAvatarURL(event.user_openid);
|
|
485
531
|
const UserId = event.user_openid;
|
|
486
532
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
487
|
-
const MessageText = event.data
|
|
533
|
+
const MessageText = event.data?.resolved?.button_data?.trim() || "";
|
|
488
534
|
const e = FormatEvent.create("private.interaction.create").addPlatform({
|
|
489
535
|
Platform: platform,
|
|
490
536
|
value: event,
|
|
@@ -497,21 +543,21 @@ const register = (client, options) => {
|
|
|
497
543
|
UserAvatar,
|
|
498
544
|
IsMaster: isMaster,
|
|
499
545
|
IsBot: false
|
|
500
|
-
}).addMessage({ MessageId: event.id }).addText({ MessageText }).addInteraction({
|
|
546
|
+
}).addMessage({ MessageId: event.event_id || event.id }).addText({ MessageText }).addInteraction({
|
|
501
547
|
InteractionId: event.id,
|
|
502
|
-
InteractionData: JSON.stringify(event.data
|
|
548
|
+
InteractionData: JSON.stringify(event.data?.resolved ?? {}),
|
|
503
549
|
Target: {
|
|
504
550
|
scope: "c2c",
|
|
505
551
|
targetId: event.user_openid,
|
|
506
552
|
BotId: botId
|
|
507
553
|
}
|
|
508
554
|
}).addOpen({ OpenId: `C2C:${event.user_openid}` }).add({ tag: "INTERACTION_CREATE_C2C" }).value;
|
|
509
|
-
|
|
555
|
+
emit(e, acknowledged);
|
|
510
556
|
} else if (event.scene === "guild") {
|
|
511
557
|
const UserAvatar = createUserAvatarURL(event.data.resolved.user_id);
|
|
512
558
|
const UserId = event.data.resolved.user_id;
|
|
513
559
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
514
|
-
const MessageText = event.data
|
|
560
|
+
const MessageText = event.data?.resolved?.button_data?.trim() || "";
|
|
515
561
|
const e = FormatEvent.create("interaction.create").addPlatform({
|
|
516
562
|
Platform: platform,
|
|
517
563
|
value: event,
|
|
@@ -529,14 +575,14 @@ const register = (client, options) => {
|
|
|
529
575
|
IsBot: false
|
|
530
576
|
}).addMessage({ MessageId: event.data.resolved.message_id }).addText({ MessageText }).addInteraction({
|
|
531
577
|
InteractionId: event.id,
|
|
532
|
-
InteractionData: JSON.stringify(event.data
|
|
578
|
+
InteractionData: JSON.stringify(event.data?.resolved ?? {}),
|
|
533
579
|
Target: {
|
|
534
580
|
scope: "channel",
|
|
535
581
|
targetId: event.channel_id,
|
|
536
582
|
BotId: botId
|
|
537
583
|
}
|
|
538
584
|
}).addOpen({ OpenId: `DIRECT:${event.guild_id}` }).add({ tag: "INTERACTION_CREATE_GUILD" }).value;
|
|
539
|
-
|
|
585
|
+
emit(e, acknowledged);
|
|
540
586
|
} else logger.warn({
|
|
541
587
|
code: ResultCode.Fail,
|
|
542
588
|
message: "暂未更新支持此类型的交互事件",
|
|
@@ -544,8 +590,8 @@ const register = (client, options) => {
|
|
|
544
590
|
});
|
|
545
591
|
});
|
|
546
592
|
client.on("MESSAGE_DELETE", (event) => {
|
|
547
|
-
const msg = event
|
|
548
|
-
|
|
593
|
+
const msg = event.message;
|
|
594
|
+
emit(FormatEvent.create("message.delete").addPlatform({
|
|
549
595
|
Platform: platform,
|
|
550
596
|
value: event,
|
|
551
597
|
BotId: botId
|
|
@@ -556,7 +602,7 @@ const register = (client, options) => {
|
|
|
556
602
|
});
|
|
557
603
|
client.on("PUBLIC_MESSAGE_DELETE", (event) => {
|
|
558
604
|
const msg = event.message;
|
|
559
|
-
|
|
605
|
+
emit(FormatEvent.create("message.delete").addPlatform({
|
|
560
606
|
Platform: platform,
|
|
561
607
|
value: event,
|
|
562
608
|
BotId: botId
|
|
@@ -567,14 +613,14 @@ const register = (client, options) => {
|
|
|
567
613
|
});
|
|
568
614
|
client.on("DIRECT_MESSAGE_DELETE", (event) => {
|
|
569
615
|
const msg = event.message;
|
|
570
|
-
|
|
616
|
+
emit(FormatEvent.create("private.message.delete").addPlatform({
|
|
571
617
|
Platform: platform,
|
|
572
618
|
value: event,
|
|
573
619
|
BotId: botId
|
|
574
620
|
}).addMessage({ MessageId: msg.id ?? "" }).add({ tag: "DIRECT_MESSAGE_DELETE" }).value);
|
|
575
621
|
});
|
|
576
622
|
client.on("MESSAGE_REACTION_ADD", (event) => {
|
|
577
|
-
|
|
623
|
+
emit(FormatEvent.create("message.reaction.add").addPlatform({
|
|
578
624
|
Platform: platform,
|
|
579
625
|
value: event,
|
|
580
626
|
BotId: botId
|
|
@@ -584,7 +630,7 @@ const register = (client, options) => {
|
|
|
584
630
|
}).addChannel({ ChannelId: event.channel_id ?? "" }).addMessage({ MessageId: event.target?.id ?? "" }).add({ tag: "MESSAGE_REACTION_ADD" }).value);
|
|
585
631
|
});
|
|
586
632
|
client.on("MESSAGE_REACTION_REMOVE", (event) => {
|
|
587
|
-
|
|
633
|
+
emit(FormatEvent.create("message.reaction.remove").addPlatform({
|
|
588
634
|
Platform: platform,
|
|
589
635
|
value: event,
|
|
590
636
|
BotId: botId
|
|
@@ -594,7 +640,7 @@ const register = (client, options) => {
|
|
|
594
640
|
}).addChannel({ ChannelId: event.channel_id ?? "" }).addMessage({ MessageId: event.target?.id ?? "" }).add({ tag: "MESSAGE_REACTION_REMOVE" }).value);
|
|
595
641
|
});
|
|
596
642
|
client.on("CHANNEL_CREATE", (event) => {
|
|
597
|
-
|
|
643
|
+
emit(FormatEvent.create("channel.create").addPlatform({
|
|
598
644
|
Platform: platform,
|
|
599
645
|
value: event,
|
|
600
646
|
BotId: botId
|
|
@@ -604,7 +650,7 @@ const register = (client, options) => {
|
|
|
604
650
|
}).addChannel({ ChannelId: event.id ?? "" }).add({ tag: "CHANNEL_CREATE" }).value);
|
|
605
651
|
});
|
|
606
652
|
client.on("CHANNEL_DELETE", (event) => {
|
|
607
|
-
|
|
653
|
+
emit(FormatEvent.create("channel.delete").addPlatform({
|
|
608
654
|
Platform: platform,
|
|
609
655
|
value: event,
|
|
610
656
|
BotId: botId
|
|
@@ -614,7 +660,7 @@ const register = (client, options) => {
|
|
|
614
660
|
}).addChannel({ ChannelId: event.id ?? "" }).add({ tag: "CHANNEL_DELETE" }).value);
|
|
615
661
|
});
|
|
616
662
|
client.on("GUILD_CREATE", (event) => {
|
|
617
|
-
|
|
663
|
+
emit(FormatEvent.create("guild.join").addPlatform({
|
|
618
664
|
Platform: platform,
|
|
619
665
|
value: event,
|
|
620
666
|
BotId: botId
|
|
@@ -629,7 +675,7 @@ const register = (client, options) => {
|
|
|
629
675
|
}).add({ tag: "GUILD_CREATE" }).value);
|
|
630
676
|
});
|
|
631
677
|
client.on("GUILD_DELETE", (event) => {
|
|
632
|
-
|
|
678
|
+
emit(FormatEvent.create("guild.exit").addPlatform({
|
|
633
679
|
Platform: platform,
|
|
634
680
|
value: event,
|
|
635
681
|
BotId: botId
|
|
@@ -646,7 +692,7 @@ const register = (client, options) => {
|
|
|
646
692
|
client.on("GUILD_MEMBER_ADD", (event) => {
|
|
647
693
|
const UserId = event.user?.id ?? "";
|
|
648
694
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
649
|
-
|
|
695
|
+
emit(FormatEvent.create("member.add").addPlatform({
|
|
650
696
|
Platform: platform,
|
|
651
697
|
value: event,
|
|
652
698
|
BotId: botId
|
|
@@ -665,7 +711,7 @@ const register = (client, options) => {
|
|
|
665
711
|
client.on("GUILD_MEMBER_REMOVE", (event) => {
|
|
666
712
|
const UserId = event.user?.id ?? "";
|
|
667
713
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
668
|
-
|
|
714
|
+
emit(FormatEvent.create("member.remove").addPlatform({
|
|
669
715
|
Platform: platform,
|
|
670
716
|
value: event,
|
|
671
717
|
BotId: botId
|
|
@@ -684,7 +730,7 @@ const register = (client, options) => {
|
|
|
684
730
|
client.on("GUILD_MEMBER_UPDATE", (event) => {
|
|
685
731
|
const UserId = event.user?.id ?? "";
|
|
686
732
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
687
|
-
|
|
733
|
+
emit(FormatEvent.create("member.update").addPlatform({
|
|
688
734
|
Platform: platform,
|
|
689
735
|
value: event,
|
|
690
736
|
BotId: botId
|
|
@@ -701,21 +747,21 @@ const register = (client, options) => {
|
|
|
701
747
|
}).add({ tag: "GUILD_MEMBER_UPDATE" }).value);
|
|
702
748
|
});
|
|
703
749
|
client.on("FRIEND_ADD", (event) => {
|
|
704
|
-
|
|
750
|
+
emit(FormatEvent.create("private.friend.add").addPlatform({
|
|
705
751
|
Platform: platform,
|
|
706
752
|
value: event,
|
|
707
753
|
BotId: botId
|
|
708
754
|
}).addUser(createUserMeta(event.openid ?? "")).addMessage({ MessageId: event.id }).add({ tag: "FRIEND_ADD" }).value);
|
|
709
755
|
});
|
|
710
756
|
client.on("FRIEND_DEL", (event) => {
|
|
711
|
-
|
|
757
|
+
emit(FormatEvent.create("private.friend.remove").addPlatform({
|
|
712
758
|
Platform: platform,
|
|
713
759
|
value: event,
|
|
714
760
|
BotId: botId
|
|
715
761
|
}).addUser(createUserMeta(event.openid ?? "")).add({ tag: "FRIEND_DEL" }).value);
|
|
716
762
|
});
|
|
717
763
|
client.on("CHANNEL_UPDATE", (event) => {
|
|
718
|
-
|
|
764
|
+
emit(FormatEvent.create("channel.update").addPlatform({
|
|
719
765
|
Platform: platform,
|
|
720
766
|
value: event,
|
|
721
767
|
BotId: botId
|
|
@@ -725,7 +771,7 @@ const register = (client, options) => {
|
|
|
725
771
|
}).addChannel({ ChannelId: event.id ?? "" }).add({ tag: "CHANNEL_UPDATE" }).value);
|
|
726
772
|
});
|
|
727
773
|
client.on("GUILD_UPDATE", (event) => {
|
|
728
|
-
|
|
774
|
+
emit(FormatEvent.create("guild.update").addPlatform({
|
|
729
775
|
Platform: platform,
|
|
730
776
|
value: event,
|
|
731
777
|
BotId: botId
|
|
@@ -735,7 +781,7 @@ const register = (client, options) => {
|
|
|
735
781
|
}).add({ tag: "GUILD_UPDATE" }).value);
|
|
736
782
|
});
|
|
737
783
|
client.on("GROUP_MSG_RECEIVE", (event) => {
|
|
738
|
-
|
|
784
|
+
emit(FormatEvent.create("notice.create").addPlatform({
|
|
739
785
|
Platform: platform,
|
|
740
786
|
value: event,
|
|
741
787
|
BotId: botId
|
|
@@ -745,7 +791,7 @@ const register = (client, options) => {
|
|
|
745
791
|
}).addChannel({ ChannelId: event.group_openid }).addUser(createUserMeta(event.op_member_openid)).addMessage({ MessageId: event.id }).add({ tag: "GROUP_MSG_RECEIVE" }).value);
|
|
746
792
|
});
|
|
747
793
|
client.on("GROUP_MSG_REJECT", (event) => {
|
|
748
|
-
|
|
794
|
+
emit(FormatEvent.create("notice.create").addPlatform({
|
|
749
795
|
Platform: platform,
|
|
750
796
|
value: event,
|
|
751
797
|
BotId: botId
|
|
@@ -755,41 +801,99 @@ const register = (client, options) => {
|
|
|
755
801
|
}).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
802
|
});
|
|
757
803
|
client.on("MESSAGE_AUDIT_PASS", (event) => {
|
|
758
|
-
const meta =
|
|
759
|
-
|
|
804
|
+
const meta = getAuditMeta(event);
|
|
805
|
+
emit(FormatEvent.create("notice.create").addPlatform({
|
|
760
806
|
Platform: platform,
|
|
761
807
|
value: event,
|
|
762
808
|
BotId: botId
|
|
763
809
|
}).addGuild({
|
|
764
|
-
GuildId: meta.
|
|
765
|
-
SpaceId:
|
|
766
|
-
}).addChannel({ ChannelId: meta.
|
|
810
|
+
GuildId: meta.guildId,
|
|
811
|
+
SpaceId: `${event.guild_id ? "GUILD" : "GROUP"}:${meta.channelId}`
|
|
812
|
+
}).addChannel({ ChannelId: meta.channelId }).addMessage({ MessageId: meta.messageId }).add({ tag: "MESSAGE_AUDIT_PASS" }).value);
|
|
767
813
|
});
|
|
768
814
|
client.on("MESSAGE_AUDIT_REJECT", (event) => {
|
|
769
|
-
const meta =
|
|
770
|
-
|
|
815
|
+
const meta = getAuditMeta(event);
|
|
816
|
+
emit(FormatEvent.create("notice.create").addPlatform({
|
|
771
817
|
Platform: platform,
|
|
772
818
|
value: event,
|
|
773
819
|
BotId: botId
|
|
774
820
|
}).addGuild({
|
|
775
|
-
GuildId: meta.
|
|
776
|
-
SpaceId:
|
|
777
|
-
}).addChannel({ ChannelId: meta.
|
|
821
|
+
GuildId: meta.guildId,
|
|
822
|
+
SpaceId: `${event.guild_id ? "GUILD" : "GROUP"}:${meta.channelId}`
|
|
823
|
+
}).addChannel({ ChannelId: meta.channelId }).addMessage({ MessageId: meta.messageId }).add({ tag: "MESSAGE_AUDIT_REJECT" }).value);
|
|
824
|
+
});
|
|
825
|
+
client.on("READY", (event) => {
|
|
826
|
+
emit(FormatEvent.create("notice.create").addPlatform({
|
|
827
|
+
Platform: platform,
|
|
828
|
+
value: event,
|
|
829
|
+
BotId: botId
|
|
830
|
+
}).addUser({
|
|
831
|
+
UserId: event.user?.id ?? "",
|
|
832
|
+
UserName: event.user?.name ?? "",
|
|
833
|
+
UserKey: "",
|
|
834
|
+
IsMaster: false,
|
|
835
|
+
IsBot: true
|
|
836
|
+
}).add({ tag: "READY" }).value);
|
|
778
837
|
});
|
|
838
|
+
const emitGuildNotice = (tag, event, authorId) => {
|
|
839
|
+
const guildId = event.guild_id ?? "";
|
|
840
|
+
const channelId = event.channel_id ?? "";
|
|
841
|
+
emit(FormatEvent.create("notice.create").addPlatform({
|
|
842
|
+
Platform: platform,
|
|
843
|
+
value: event,
|
|
844
|
+
BotId: botId
|
|
845
|
+
}).addGuild({
|
|
846
|
+
GuildId: guildId,
|
|
847
|
+
SpaceId: `GUILD:${channelId}`
|
|
848
|
+
}).addChannel({ ChannelId: channelId }).addUser(createUserMeta(authorId ?? event.author_id ?? "")).add({ tag }).value);
|
|
849
|
+
};
|
|
850
|
+
for (const tag of [
|
|
851
|
+
"FORUM_THREAD_CREATE",
|
|
852
|
+
"FORUM_THREAD_UPDATE",
|
|
853
|
+
"FORUM_THREAD_DELETE",
|
|
854
|
+
"FORUM_POST_CREATE",
|
|
855
|
+
"FORUM_POST_DELETE",
|
|
856
|
+
"FORUM_REPLY_CREATE",
|
|
857
|
+
"FORUM_REPLY_DELETE",
|
|
858
|
+
"FORUM_PUBLISH_AUDIT_RESULT",
|
|
859
|
+
"AUDIO_START",
|
|
860
|
+
"AUDIO_FINISH",
|
|
861
|
+
"AUDIO_ON_MIC",
|
|
862
|
+
"AUDIO_OFF_MIC",
|
|
863
|
+
"AUDIO_OR_LIVE_CHANNEL_MEMBER_ENTER",
|
|
864
|
+
"AUDIO_OR_LIVE_CHANNEL_MEMBER_EXIT"
|
|
865
|
+
]) client.on(tag, (event) => emitGuildNotice(tag, event, ("author_id" in event ? event.author_id : void 0) ?? ("user_id" in event ? event.user_id : void 0)));
|
|
779
866
|
client.on("C2C_MSG_RECEIVE", (event) => {
|
|
780
|
-
|
|
867
|
+
emit(FormatEvent.create("private.notice.create").addPlatform({
|
|
781
868
|
Platform: platform,
|
|
782
869
|
value: event,
|
|
783
870
|
BotId: botId
|
|
784
871
|
}).addUser(createUserMeta(event.openid ?? "")).addMessage({ MessageId: event.id }).add({ tag: "C2C_MSG_RECEIVE" }).value);
|
|
785
872
|
});
|
|
786
873
|
client.on("C2C_MSG_REJECT", (event) => {
|
|
787
|
-
|
|
874
|
+
emit(FormatEvent.create("private.notice.create").addPlatform({
|
|
788
875
|
Platform: platform,
|
|
789
876
|
value: event,
|
|
790
877
|
BotId: botId
|
|
791
878
|
}).addUser(createUserMeta(event.openid ?? "")).addMessage({ MessageId: `c2c_msg_reject_${event.openid}_${event.timestamp}` }).add({ tag: "C2C_MSG_REJECT" }).value);
|
|
792
879
|
});
|
|
880
|
+
client.on("SUBSCRIBE_MESSAGE_STATUS", (event) => {
|
|
881
|
+
if (event.group_openid) emit(FormatEvent.create("notice.create").addPlatform({
|
|
882
|
+
Platform: platform,
|
|
883
|
+
value: event,
|
|
884
|
+
BotId: botId,
|
|
885
|
+
IsPrivate: false
|
|
886
|
+
}).addGuild({
|
|
887
|
+
GuildId: event.group_openid,
|
|
888
|
+
SpaceId: `GROUP:${event.group_openid}`
|
|
889
|
+
}).addChannel({ ChannelId: event.group_openid }).add({ tag: "SUBSCRIBE_MESSAGE_STATUS" }).value);
|
|
890
|
+
else emit(FormatEvent.create("private.notice.create").addPlatform({
|
|
891
|
+
Platform: platform,
|
|
892
|
+
value: event,
|
|
893
|
+
BotId: botId,
|
|
894
|
+
IsPrivate: true
|
|
895
|
+
}).addUser(createUserMeta(event.openid || "")).add({ tag: "SUBSCRIBE_MESSAGE_STATUS" }).value);
|
|
896
|
+
});
|
|
793
897
|
client.on("ERROR", console.error);
|
|
794
898
|
const api = {
|
|
795
899
|
active: { send: {
|
|
@@ -861,17 +965,9 @@ const register = (client, options) => {
|
|
|
861
965
|
const value = event.value || {};
|
|
862
966
|
const Metions = [];
|
|
863
967
|
if (value.mentions) {
|
|
864
|
-
const
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
return {
|
|
868
|
-
UserId: item.id,
|
|
869
|
-
IsMaster: isMaster,
|
|
870
|
-
UserName: item.username,
|
|
871
|
-
IsBot: item.bot ?? false,
|
|
872
|
-
UserKey
|
|
873
|
-
};
|
|
874
|
-
});
|
|
968
|
+
const mentions = event.value["mentions"] || [];
|
|
969
|
+
const scope = event.SpaceId?.startsWith("GROUP:") ? "group" : event.IsPrivate ? "c2c" : "channel";
|
|
970
|
+
const MessageMention = mentions.map((item) => normalizeMessageUser(item, scope));
|
|
875
971
|
return new Promise((resolve) => resolve(MessageMention));
|
|
876
972
|
} else return new Promise((resolve) => resolve(Metions));
|
|
877
973
|
}
|
|
@@ -879,12 +975,39 @@ const register = (client, options) => {
|
|
|
879
975
|
};
|
|
880
976
|
const onactions = async (data, consume) => {
|
|
881
977
|
const event = data.payload.event ?? {};
|
|
978
|
+
const requestedBot = data.payload.params?.target?.BotId ?? data.payload.target?.BotId ?? data.payload.BotId ?? event.BotId;
|
|
979
|
+
if (requestedBot && requestedBot !== botId) {
|
|
980
|
+
consume([createResult(ResultCode.FailParams, "BotId does not match this adapter", null)]);
|
|
981
|
+
return;
|
|
982
|
+
}
|
|
882
983
|
const getGroupOpenId = () => data.payload.ChannelId ?? data.payload.params?.groupOpenId ?? data.payload.GuildId ?? event.ChannelId ?? event.GuildId ?? "";
|
|
883
984
|
const getMemberOpenId = () => data.payload.params?.memberOpenId ?? data.payload.UserId ?? event.UserId ?? "";
|
|
884
985
|
const getGuildId = () => data.payload.GuildId ?? event.GuildId ?? "";
|
|
885
986
|
const getUserId = () => data.payload.UserId ?? event.UserId ?? "";
|
|
886
987
|
const getChannelId = () => data.payload.ChannelId ?? event.ChannelId ?? "";
|
|
887
988
|
try {
|
|
989
|
+
if (data.action === "media.send.user" || data.action === "media.send.channel") {
|
|
990
|
+
const scope = data.payload.target?.scope;
|
|
991
|
+
if (data.action === "media.send.user" && (!scope || scope === "group" || scope === "c2c") || data.action === "media.send.channel" && scope === "group") {
|
|
992
|
+
await onactions({
|
|
993
|
+
action: "media.send",
|
|
994
|
+
payload: {
|
|
995
|
+
...data.payload,
|
|
996
|
+
target: {
|
|
997
|
+
scope: data.action === "media.send.user" ? "c2c" : "group",
|
|
998
|
+
targetId: data.action === "media.send.user" ? getUserId() : getChannelId(),
|
|
999
|
+
BotId: data.payload.BotId ?? data.payload.target?.BotId ?? event.BotId
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
}, consume);
|
|
1003
|
+
return;
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
const handled = await handleFrameworkAction(client, data, botId);
|
|
1007
|
+
if (handled) {
|
|
1008
|
+
consume(handled);
|
|
1009
|
+
return;
|
|
1010
|
+
}
|
|
888
1011
|
if (data.action === "me.info") {
|
|
889
1012
|
const res = await client.usersMe();
|
|
890
1013
|
const UserId = res.id;
|
|
@@ -892,7 +1015,11 @@ const register = (client, options) => {
|
|
|
892
1015
|
const botInfo = {
|
|
893
1016
|
UserId: res?.id,
|
|
894
1017
|
UserName: res?.username,
|
|
895
|
-
UserAvatar: createUserAvatarURL(res?.id),
|
|
1018
|
+
UserAvatar: res?.avatar || createUserAvatarURL(res?.id),
|
|
1019
|
+
UnionId: res?.union_openid,
|
|
1020
|
+
AccountId: res?.union_user_account,
|
|
1021
|
+
ShareUrl: res?.share_url,
|
|
1022
|
+
WelcomeMessage: res?.welcome_msg,
|
|
896
1023
|
IsBot: true,
|
|
897
1024
|
IsMaster: isMaster,
|
|
898
1025
|
UserKey
|
|
@@ -940,11 +1067,34 @@ const register = (client, options) => {
|
|
|
940
1067
|
consume([createResult(ResultCode.Fail, "interaction.ack 缺少 InteractionId", null)]);
|
|
941
1068
|
return;
|
|
942
1069
|
}
|
|
943
|
-
|
|
944
|
-
consume([res]);
|
|
945
|
-
consume([res]);
|
|
1070
|
+
consume([await client.interactionResponse(mode, interactionId, params.code).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err?.response?.data ?? err?.message ?? err))]);
|
|
946
1071
|
} 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
1072
|
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))]);
|
|
1073
|
+
else if (data.action === "schedule.list") consume([await client.channelsSchedules(getChannelId(), data.payload.params).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1074
|
+
else if (data.action === "schedule.get") consume([await client.channelsSchedulesSchedule(getChannelId(), data.payload.ScheduleId).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1075
|
+
else if (data.action === "schedule.create") consume([await client.channelsSchedulesPost(getChannelId(), { schedule: data.payload.params.schedule }).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1076
|
+
else if (data.action === "schedule.update") consume([await client.channelsSchedulesSchedulePatch(getChannelId(), data.payload.ScheduleId, { schedule: data.payload.params.schedule }).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1077
|
+
else if (data.action === "schedule.delete") consume([await client.channelsSchedulesScheduleDelete(getChannelId(), data.payload.ScheduleId).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1078
|
+
else if (data.action === "forum.list") consume([await client.channelsThreads(getChannelId()).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1079
|
+
else if (data.action === "forum.get") consume([await client.channelsThreadsThread(getChannelId(), data.payload.ThreadId).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1080
|
+
else if (data.action === "forum.create") {
|
|
1081
|
+
const params = data.payload.params;
|
|
1082
|
+
consume([await client.channelsThreadsPut(getChannelId(), {
|
|
1083
|
+
title: params.title,
|
|
1084
|
+
content: params.content,
|
|
1085
|
+
format: params.format
|
|
1086
|
+
}).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1087
|
+
} else if (data.action === "forum.delete") consume([await client.channelsThreadsDelete(getChannelId(), data.payload.ThreadId).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1088
|
+
else if (data.action === "audio.control") {
|
|
1089
|
+
const params = data.payload.params;
|
|
1090
|
+
consume([await client.channelsAudioPost(getChannelId(), {
|
|
1091
|
+
status: params.status,
|
|
1092
|
+
audio_url: params.audioUrl,
|
|
1093
|
+
text: params.text
|
|
1094
|
+
}).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1095
|
+
} else if (data.action === "audio.join") consume([await client.channelsMicPut(getChannelId()).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1096
|
+
else if (data.action === "audio.leave") consume([await client.channelsMicDelete(getChannelId()).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1097
|
+
else if (data.action === "audio.online") consume([await client.channelsChannelOnlineNums(getChannelId()).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
948
1098
|
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
1099
|
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
1100
|
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))]);
|
|
@@ -1072,8 +1222,8 @@ const register = (client, options) => {
|
|
|
1072
1222
|
color: params.color
|
|
1073
1223
|
}).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1074
1224
|
} 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(),
|
|
1076
|
-
else if (data.action === "role.remove") consume([await client.guildsRolesMembersDelete(getGuildId(),
|
|
1225
|
+
else if (data.action === "role.assign") consume([await client.guildsRolesMembersPut(getGuildId(), getChannelId(), getUserId(), data.payload.RoleId).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1226
|
+
else if (data.action === "role.remove") consume([await client.guildsRolesMembersDelete(getGuildId(), getChannelId(), getUserId(), data.payload.RoleId).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1077
1227
|
else if (data.action === "file.send.channel") consume([await client.postRichMediaByGroup(getGroupOpenId(), {
|
|
1078
1228
|
file_type: data.payload.params?.file_type ?? 1,
|
|
1079
1229
|
url: data.payload.params?.url,
|
|
@@ -1120,23 +1270,25 @@ const register = (client, options) => {
|
|
|
1120
1270
|
}
|
|
1121
1271
|
const params = data.payload.params || {};
|
|
1122
1272
|
if (params.fileId) {
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
}
|
|
1136
|
-
consume([await send.then((value) => createResult(ResultCode.Ok, data.action, { id: value.id })).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1273
|
+
consume(await handleFrameworkAction(client, {
|
|
1274
|
+
action: "message.send",
|
|
1275
|
+
payload: {
|
|
1276
|
+
...data.payload,
|
|
1277
|
+
params: {
|
|
1278
|
+
...params,
|
|
1279
|
+
content: {
|
|
1280
|
+
text: params.content,
|
|
1281
|
+
media: { fileId: params.fileId }
|
|
1282
|
+
}
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
}, botId) ?? [createResult(ResultCode.FailParams, "Unsupported media target", null)]);
|
|
1137
1286
|
return;
|
|
1138
1287
|
}
|
|
1139
|
-
const upload = await uploadMedia(target,
|
|
1288
|
+
const upload = await uploadMedia(target, {
|
|
1289
|
+
...params,
|
|
1290
|
+
send: false
|
|
1291
|
+
}).then((value) => value.fileId).catch((error) => {
|
|
1140
1292
|
consume([createResult(ResultCode.Fail, data.action, error)]);
|
|
1141
1293
|
return null;
|
|
1142
1294
|
});
|
|
@@ -1144,6 +1296,7 @@ const register = (client, options) => {
|
|
|
1144
1296
|
await onactions({
|
|
1145
1297
|
action: "media.send",
|
|
1146
1298
|
payload: {
|
|
1299
|
+
...data.payload,
|
|
1147
1300
|
target,
|
|
1148
1301
|
params: {
|
|
1149
1302
|
...params,
|
|
@@ -1197,6 +1350,10 @@ const register = (client, options) => {
|
|
|
1197
1350
|
else if (data.action === "permission.set") {
|
|
1198
1351
|
const params = data.payload.params;
|
|
1199
1352
|
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))]);
|
|
1353
|
+
} else if (data.action === "permission.role.get") consume([await client.channelsRolePermissions(getChannelId(), data.payload.RoleId).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1354
|
+
else if (data.action === "permission.role.set") {
|
|
1355
|
+
const params = data.payload.params ?? {};
|
|
1356
|
+
consume([await client.channelsRolePermissionsPut(getChannelId(), data.payload.RoleId, params.allow ?? "0", params.deny ?? "0").then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1200
1357
|
} 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
1358
|
else if (data.action === "channel.announce") {
|
|
1202
1359
|
const guildId = getGuildId();
|
|
@@ -1206,9 +1363,24 @@ const register = (client, options) => {
|
|
|
1206
1363
|
message_id: params?.messageId,
|
|
1207
1364
|
channel_id: params?.channelId
|
|
1208
1365
|
}).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1209
|
-
} else consume([createResult(ResultCode.Fail,
|
|
1366
|
+
} else if (data.action === "channel.message-rate.get") consume([await client.guildsMessageSetting(getGuildId()).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1367
|
+
else if (data.action === "channel.api-permission.list") consume([await client.guildApiPermission(getGuildId()).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1368
|
+
else if (data.action === "channel.api-permission.request") {
|
|
1369
|
+
const params = data.payload.params;
|
|
1370
|
+
consume([await client.guildsApiPermissionDemand(getGuildId(), {
|
|
1371
|
+
channel_id: getChannelId(),
|
|
1372
|
+
api_identify: {
|
|
1373
|
+
path: params.path,
|
|
1374
|
+
method: params.method
|
|
1375
|
+
},
|
|
1376
|
+
desc: params.description
|
|
1377
|
+
}).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1378
|
+
} else if (data.action === "channel.direct-session.open") consume([await client.usersMeDms(data.payload.UserId, getGuildId()).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1379
|
+
else if (data.action === "channel.legacy-announcement.set") consume([await client.channelsAnnounces(getChannelId(), data.payload.MessageId).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1380
|
+
else if (data.action === "channel.legacy-announcement.remove") consume([await client.channelsAnnouncesDelete(getChannelId(), data.payload.MessageId).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1381
|
+
else consume([createResult(ResultCode.Fail, "未知请求,请尝试升级版本", null)]);
|
|
1210
1382
|
} catch (error) {
|
|
1211
|
-
consume([createResult(ResultCode.Fail, "请求失败", error)]);
|
|
1383
|
+
consume([createResult(ResultCode.Fail, "请求失败", error?.response?.data ?? error?.message ?? error)]);
|
|
1212
1384
|
}
|
|
1213
1385
|
};
|
|
1214
1386
|
const onapis = async (data, consume) => {
|
|
@@ -1233,7 +1405,7 @@ const register = (client, options) => {
|
|
|
1233
1405
|
const res = await target.call(parent, ...params);
|
|
1234
1406
|
consume([createResult(ResultCode.Ok, "请求完成", res)]);
|
|
1235
1407
|
} catch (error) {
|
|
1236
|
-
consume([createResult(ResultCode.Fail, "请求失败", error)]);
|
|
1408
|
+
consume([createResult(ResultCode.Fail, "请求失败", error?.response?.data ?? error?.message ?? error)]);
|
|
1237
1409
|
}
|
|
1238
1410
|
};
|
|
1239
1411
|
if (options?.bindActions !== false) {
|