@alemonjs/qq-bot 2.1.35 → 2.1.37
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/LICENSE +21 -0
- package/README.md +66 -1981
- package/lib/config.d.ts +2 -0
- package/lib/format.d.ts +4 -1
- package/lib/format.js +68 -4
- 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 +5 -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 +279 -115
- package/lib/sdk/api.d.ts +93 -14
- package/lib/sdk/api.js +241 -45
- package/lib/sdk/client.webhook.js +2 -1
- package/lib/sdk/client.websoket.js +2 -1
- 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/sends.d.ts +3 -3
- package/lib/sends.js +57 -71
- package/lib/upload.js +13 -37
- package/package.json +8 -5
package/lib/register.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { getIdentity, getMaster, getQQBotConfig, platform } from "./config.js";
|
|
2
|
-
import { chunkedUpload } from "./upload.js";
|
|
3
2
|
import { AT_MESSAGE_CREATE, C2C_MESSAGE_CREATE, DIRECT_MESSAGE_CREATE, GROUP_AT_MESSAGE_CREATE, MESSAGE_CREATE } from "./sends.js";
|
|
3
|
+
import { normalizeFrameworkEvent, normalizeMessageUser } from "./framework-events.js";
|
|
4
|
+
import { handleFrameworkAction } from "./framework-actions.js";
|
|
5
|
+
import { chunkedUpload } from "./upload.js";
|
|
4
6
|
import { FormatEvent, ResultCode, cbpPlatform, createResult, logger } from "alemonjs";
|
|
5
7
|
import { createHash } from "node:crypto";
|
|
6
8
|
import { basename } from "node:path";
|
|
@@ -40,11 +42,12 @@ const C2C_NOTICE_TAGS = /* @__PURE__ */ new Set([
|
|
|
40
42
|
"FRIEND_DEL"
|
|
41
43
|
]);
|
|
42
44
|
const register = (client, options) => {
|
|
43
|
-
const MAX_MEDIA_SIZE =
|
|
45
|
+
const MAX_MEDIA_SIZE = 209715200;
|
|
44
46
|
const config = getQQBotConfig();
|
|
45
47
|
const botId = String(options?.botId ?? config?.app_id ?? "");
|
|
46
48
|
const url = `ws://127.0.0.1:${process.env?.port || config?.port || 17117}`;
|
|
47
49
|
const cbp = options?.cbp ?? cbpPlatform(url);
|
|
50
|
+
const emit = (event, acknowledged = false) => cbp.send(normalizeFrameworkEvent(event, acknowledged));
|
|
48
51
|
/**
|
|
49
52
|
* group
|
|
50
53
|
*
|
|
@@ -56,9 +59,9 @@ const register = (client, options) => {
|
|
|
56
59
|
};
|
|
57
60
|
const getGroupMessageMeta = (event) => {
|
|
58
61
|
const author = event?.author;
|
|
59
|
-
const UserId = author?.id
|
|
62
|
+
const UserId = author?.member_openid || author?.id || "";
|
|
60
63
|
const memberOpenId = author?.member_openid ?? "";
|
|
61
|
-
const groupId = event?.
|
|
64
|
+
const groupId = event?.group_openid || event?.group_id || "";
|
|
62
65
|
const messageId = event?.id ?? "";
|
|
63
66
|
const [isMaster, UserKey] = UserId ? getMaster(UserId) : [false, ""];
|
|
64
67
|
return {
|
|
@@ -72,9 +75,10 @@ const register = (client, options) => {
|
|
|
72
75
|
openId: memberOpenId ? `C2C:${memberOpenId}` : ""
|
|
73
76
|
};
|
|
74
77
|
};
|
|
75
|
-
const
|
|
78
|
+
const getAuditMeta = (event) => {
|
|
76
79
|
return {
|
|
77
|
-
|
|
80
|
+
guildId: event?.guild_id ?? event?.group_openid ?? "",
|
|
81
|
+
channelId: event?.channel_id ?? event?.group_openid ?? "",
|
|
78
82
|
messageId: event?.message_id ?? event?.audit_id ?? "",
|
|
79
83
|
auditTime: event?.audit_time ?? ""
|
|
80
84
|
};
|
|
@@ -84,7 +88,7 @@ const register = (client, options) => {
|
|
|
84
88
|
if (!attachment?.url) return [];
|
|
85
89
|
const mimeType = attachment.content_type || "";
|
|
86
90
|
return [{
|
|
87
|
-
Type: mimeType.startsWith("image/") ? "image" : mimeType.startsWith("audio/") ? "audio" : mimeType.startsWith("video/") ? "video" : "file",
|
|
91
|
+
Type: mimeType.startsWith("image/") ? "image" : mimeType === "voice" || mimeType.startsWith("audio/") ? "audio" : mimeType.startsWith("video/") ? "video" : "file",
|
|
88
92
|
Url: attachment.url,
|
|
89
93
|
...attachment.filename && { FileName: attachment.filename },
|
|
90
94
|
...typeof attachment.size === "number" && { FileSize: attachment.size },
|
|
@@ -122,7 +126,7 @@ const register = (client, options) => {
|
|
|
122
126
|
if (params.filePath) {
|
|
123
127
|
const metadata = await stat(String(params.filePath));
|
|
124
128
|
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
|
|
129
|
+
if (metadata.size > MAX_MEDIA_SIZE) throw new Error("QQ media files must not exceed 200 MiB");
|
|
126
130
|
filePath = String(params.filePath);
|
|
127
131
|
fileSize = metadata.size;
|
|
128
132
|
hashes = await client.getMediaFileHashes(filePath);
|
|
@@ -136,22 +140,23 @@ const register = (client, options) => {
|
|
|
136
140
|
hashSource = data;
|
|
137
141
|
const value = data.replace(/^base64:\/\//, "");
|
|
138
142
|
buffer = Buffer.from(value, "base64");
|
|
139
|
-
if (buffer.length > MAX_MEDIA_SIZE) throw new Error("QQ media files must not exceed
|
|
143
|
+
if (buffer.length > MAX_MEDIA_SIZE) throw new Error("QQ media files must not exceed 200 MiB");
|
|
140
144
|
}
|
|
141
|
-
const key = [
|
|
145
|
+
const key = JSON.stringify([
|
|
142
146
|
botId,
|
|
143
147
|
target.scope,
|
|
144
148
|
target.targetId,
|
|
145
149
|
params.type,
|
|
150
|
+
name ?? "",
|
|
146
151
|
createHash("sha256").update(hashSource).digest("hex")
|
|
147
|
-
]
|
|
152
|
+
]);
|
|
148
153
|
const cached = mediaCache.get(key);
|
|
149
|
-
if (cached &&
|
|
150
|
-
|
|
151
|
-
expiresAt: cached.expiresAt,
|
|
154
|
+
if (!params.send && cached && cached.expiresAt && cached.expiresAt > Date.now()) return {
|
|
155
|
+
...cached,
|
|
152
156
|
reused: true
|
|
153
157
|
};
|
|
154
158
|
return {
|
|
159
|
+
fileId: void 0,
|
|
155
160
|
key,
|
|
156
161
|
url: params.url,
|
|
157
162
|
data,
|
|
@@ -167,7 +172,22 @@ const register = (client, options) => {
|
|
|
167
172
|
if (!validateTargetBot(target)) throw new Error(`BotId ${target.BotId} is not active`);
|
|
168
173
|
if (target.scope !== "group" && target.scope !== "c2c") throw new Error("QQ media upload only supports group and c2c targets");
|
|
169
174
|
const prepared = await prepareMedia(target, params);
|
|
170
|
-
if (prepared.fileId)
|
|
175
|
+
if (prepared.fileId) {
|
|
176
|
+
if (params.send) {
|
|
177
|
+
const sent = target.scope === "group" ? await client.groupOpenMessages(target.targetId, {
|
|
178
|
+
msg_type: 7,
|
|
179
|
+
media: { file_info: prepared.fileId }
|
|
180
|
+
}) : await client.usersOpenMessages(target.targetId, {
|
|
181
|
+
msg_type: 7,
|
|
182
|
+
media: { file_info: prepared.fileId }
|
|
183
|
+
});
|
|
184
|
+
return {
|
|
185
|
+
...prepared,
|
|
186
|
+
messageId: sent.id
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
return prepared;
|
|
190
|
+
}
|
|
171
191
|
const fileType = mediaType(params.type);
|
|
172
192
|
const value = prepared.filePath && prepared.fileSize && prepared.fileSize >= 5242880 ? await client.postChunkedRichMedia({
|
|
173
193
|
scope: target.scope,
|
|
@@ -187,20 +207,37 @@ const register = (client, options) => {
|
|
|
187
207
|
file_type: fileType,
|
|
188
208
|
url: prepared.url,
|
|
189
209
|
file_data: prepared.data,
|
|
190
|
-
|
|
210
|
+
file_name: prepared.name,
|
|
211
|
+
srv_send_msg: params.send ?? false
|
|
191
212
|
}) : await client.postRichMediaByUser(target.targetId, {
|
|
192
213
|
file_type: fileType,
|
|
193
214
|
url: prepared.url,
|
|
194
215
|
file_data: prepared.data,
|
|
195
|
-
|
|
216
|
+
file_name: prepared.name,
|
|
217
|
+
srv_send_msg: params.send ?? false
|
|
196
218
|
});
|
|
219
|
+
let messageId = "id" in value ? value.id : void 0;
|
|
220
|
+
if (params.send && !messageId && ((prepared.fileSize ?? 0) >= 5242880 || (prepared.buffer?.length ?? 0) >= 5242880)) messageId = (target.scope === "group" ? await client.groupOpenMessages(target.targetId, {
|
|
221
|
+
msg_type: 7,
|
|
222
|
+
media: { file_info: value.file_info }
|
|
223
|
+
}) : await client.usersOpenMessages(target.targetId, {
|
|
224
|
+
msg_type: 7,
|
|
225
|
+
media: { file_info: value.file_info }
|
|
226
|
+
})).id;
|
|
197
227
|
const expiresAt = value.ttl ? Date.now() + value.ttl * 1e3 : void 0;
|
|
198
|
-
if (prepared.key) mediaCache.set(prepared.key, {
|
|
228
|
+
if (prepared.key && expiresAt) mediaCache.set(prepared.key, {
|
|
199
229
|
fileId: value.file_info,
|
|
230
|
+
uuid: value.file_uuid,
|
|
231
|
+
ttl: value.ttl,
|
|
232
|
+
url: value.raw_url,
|
|
200
233
|
expiresAt
|
|
201
234
|
});
|
|
202
235
|
return {
|
|
203
236
|
fileId: value.file_info,
|
|
237
|
+
uuid: value.file_uuid,
|
|
238
|
+
ttl: value.ttl,
|
|
239
|
+
messageId,
|
|
240
|
+
url: "raw_url" in value ? value.raw_url : void 0,
|
|
204
241
|
expiresAt,
|
|
205
242
|
reused: false
|
|
206
243
|
};
|
|
@@ -216,7 +253,7 @@ const register = (client, options) => {
|
|
|
216
253
|
};
|
|
217
254
|
};
|
|
218
255
|
client.on("GROUP_ADD_ROBOT", (event) => {
|
|
219
|
-
|
|
256
|
+
emit(FormatEvent.create("guild.join").addPlatform({
|
|
220
257
|
Platform: platform,
|
|
221
258
|
value: event,
|
|
222
259
|
BotId: botId
|
|
@@ -226,7 +263,7 @@ const register = (client, options) => {
|
|
|
226
263
|
}).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
264
|
});
|
|
228
265
|
client.on("GROUP_DEL_ROBOT", (event) => {
|
|
229
|
-
|
|
266
|
+
emit(FormatEvent.create("guild.exit").addPlatform({
|
|
230
267
|
Platform: platform,
|
|
231
268
|
value: event,
|
|
232
269
|
BotId: botId
|
|
@@ -239,7 +276,7 @@ const register = (client, options) => {
|
|
|
239
276
|
if (event?.author?.bot) return;
|
|
240
277
|
const msg = getMessageContent(event);
|
|
241
278
|
const meta = getGroupMessageMeta(event);
|
|
242
|
-
|
|
279
|
+
emit(FormatEvent.create("message.create").addPlatform({
|
|
243
280
|
Platform: platform,
|
|
244
281
|
value: event,
|
|
245
282
|
BotId: botId,
|
|
@@ -258,9 +295,9 @@ const register = (client, options) => {
|
|
|
258
295
|
}).addMessage({ MessageId: meta.messageId }).addText({ MessageText: msg?.trim() }).addMedia({ MessageMedia: getMediaItems(event.attachments) }).addOpen({ OpenId: meta.openId }).add({ tag: "GROUP_MESSAGE_CREATE" }).value);
|
|
259
296
|
});
|
|
260
297
|
client.on("GROUP_MEMBER_ADD", (event) => {
|
|
261
|
-
const UserId = event.
|
|
298
|
+
const UserId = event.member_openid || event.op_member_openid || "";
|
|
262
299
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
263
|
-
|
|
300
|
+
emit(FormatEvent.create("member.add").addPlatform({
|
|
264
301
|
Platform: platform,
|
|
265
302
|
value: event,
|
|
266
303
|
BotId: botId
|
|
@@ -277,9 +314,9 @@ const register = (client, options) => {
|
|
|
277
314
|
}).add({ tag: "GROUP_MEMBER_ADD" }).value);
|
|
278
315
|
});
|
|
279
316
|
client.on("GROUP_MEMBER_REMOVE", (event) => {
|
|
280
|
-
const UserId = event.
|
|
317
|
+
const UserId = event.member_openid || event.op_member_openid || "";
|
|
281
318
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
282
|
-
|
|
319
|
+
emit(FormatEvent.create("member.remove").addPlatform({
|
|
283
320
|
Platform: platform,
|
|
284
321
|
value: event,
|
|
285
322
|
BotId: botId
|
|
@@ -298,7 +335,7 @@ const register = (client, options) => {
|
|
|
298
335
|
client.on("GROUP_JOIN_REQUEST", (event) => {
|
|
299
336
|
const UserId = event.member_openid ?? "";
|
|
300
337
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
301
|
-
|
|
338
|
+
emit(FormatEvent.create("notice.create").addPlatform({
|
|
302
339
|
Platform: platform,
|
|
303
340
|
value: event,
|
|
304
341
|
BotId: botId
|
|
@@ -318,7 +355,7 @@ const register = (client, options) => {
|
|
|
318
355
|
if (event?.author?.bot) return;
|
|
319
356
|
const msg = getMessageContent(event);
|
|
320
357
|
const meta = getGroupMessageMeta(event);
|
|
321
|
-
|
|
358
|
+
emit(FormatEvent.create("message.create").addPlatform({
|
|
322
359
|
Platform: platform,
|
|
323
360
|
value: event,
|
|
324
361
|
BotId: botId,
|
|
@@ -337,23 +374,23 @@ const register = (client, options) => {
|
|
|
337
374
|
}).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
375
|
});
|
|
339
376
|
client.on("C2C_MESSAGE_CREATE", (event) => {
|
|
340
|
-
const UserId = event.author.id;
|
|
377
|
+
const UserId = event.author.user_openid || event.author.id;
|
|
341
378
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
342
|
-
const UserAvatar = createUserAvatarURL(
|
|
343
|
-
|
|
379
|
+
const UserAvatar = createUserAvatarURL(UserId);
|
|
380
|
+
emit(FormatEvent.create("private.message.create").addPlatform({
|
|
344
381
|
Platform: platform,
|
|
345
382
|
value: event,
|
|
346
383
|
BotId: botId,
|
|
347
384
|
IsAtMe: false,
|
|
348
385
|
IsPrivate: true
|
|
349
386
|
}).addUser({
|
|
350
|
-
UserId
|
|
387
|
+
UserId,
|
|
351
388
|
UserKey,
|
|
352
389
|
UserAvatar,
|
|
353
390
|
UserName: event?.author?.username,
|
|
354
391
|
IsMaster: isMaster,
|
|
355
392
|
IsBot: false
|
|
356
|
-
}).addMessage({ MessageId: event.id }).addText({ MessageText: event.content?.trim() }).addMedia({ MessageMedia: getMediaItems(event.attachments) }).addOpen({ OpenId: `C2C:${
|
|
393
|
+
}).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
394
|
});
|
|
358
395
|
/**
|
|
359
396
|
* guild
|
|
@@ -364,7 +401,7 @@ const register = (client, options) => {
|
|
|
364
401
|
const UserAvatar = event?.author?.avatar;
|
|
365
402
|
const UserId = event.author.id;
|
|
366
403
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
367
|
-
|
|
404
|
+
emit(FormatEvent.create("private.message.create").addPlatform({
|
|
368
405
|
Platform: platform,
|
|
369
406
|
value: event,
|
|
370
407
|
BotId: botId,
|
|
@@ -385,7 +422,7 @@ const register = (client, options) => {
|
|
|
385
422
|
const UserAvatar = event?.author?.avatar;
|
|
386
423
|
const UserId = event.author.id;
|
|
387
424
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
388
|
-
|
|
425
|
+
emit(FormatEvent.create("message.create").addPlatform({
|
|
389
426
|
Platform: platform,
|
|
390
427
|
value: event,
|
|
391
428
|
BotId: botId,
|
|
@@ -421,12 +458,11 @@ const register = (client, options) => {
|
|
|
421
458
|
};
|
|
422
459
|
client.on("MESSAGE_CREATE", (event) => {
|
|
423
460
|
if (event.author?.bot) return;
|
|
424
|
-
if ((/* @__PURE__ */ new RegExp(/DELETE$/)).test(event.eventType)) return;
|
|
425
461
|
const UserId = event.author.id;
|
|
426
462
|
const msg = getMessageContent(event);
|
|
427
463
|
const UserAvatar = event?.author?.avatar;
|
|
428
464
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
429
|
-
|
|
465
|
+
emit(FormatEvent.create("message.create").addPlatform({
|
|
430
466
|
Platform: platform,
|
|
431
467
|
value: event,
|
|
432
468
|
BotId: botId,
|
|
@@ -445,16 +481,18 @@ const register = (client, options) => {
|
|
|
445
481
|
}).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
482
|
});
|
|
447
483
|
client.on("INTERACTION_CREATE", async (event) => {
|
|
448
|
-
|
|
484
|
+
let acknowledged = false;
|
|
485
|
+
if ((options?.autoInteractionAck ?? config.autoInteractionAck ?? true) && (event.type === 11 || event.type === 12)) try {
|
|
449
486
|
await client.interactionResponse("group", event.id, 0);
|
|
487
|
+
acknowledged = true;
|
|
450
488
|
} catch (err) {
|
|
451
|
-
|
|
489
|
+
logger.warn("interactionResponse failed", err?.response?.data ?? err?.message ?? err);
|
|
452
490
|
}
|
|
453
491
|
if (event.scene === "group") {
|
|
454
492
|
const UserAvatar = createUserAvatarURL(event.group_member_openid);
|
|
455
493
|
const UserId = event.group_member_openid;
|
|
456
494
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
457
|
-
const MessageText = event.data
|
|
495
|
+
const MessageText = event.data?.resolved?.button_data?.trim() || "";
|
|
458
496
|
const e = FormatEvent.create("interaction.create").addPlatform({
|
|
459
497
|
Platform: platform,
|
|
460
498
|
value: event,
|
|
@@ -470,21 +508,21 @@ const register = (client, options) => {
|
|
|
470
508
|
UserAvatar,
|
|
471
509
|
IsMaster: isMaster,
|
|
472
510
|
IsBot: false
|
|
473
|
-
}).addMessage({ MessageId: event.id }).addText({ MessageText }).addInteraction({
|
|
511
|
+
}).addMessage({ MessageId: event.event_id || event.id }).addText({ MessageText }).addInteraction({
|
|
474
512
|
InteractionId: event.id,
|
|
475
|
-
InteractionData: JSON.stringify(event.data
|
|
513
|
+
InteractionData: JSON.stringify(event.data?.resolved ?? {}),
|
|
476
514
|
Target: {
|
|
477
515
|
scope: "group",
|
|
478
516
|
targetId: event.group_openid,
|
|
479
517
|
BotId: botId
|
|
480
518
|
}
|
|
481
519
|
}).addOpen({ OpenId: `C2C:${event.group_member_openid}` }).add({ tag: "INTERACTION_CREATE_GROUP" }).value;
|
|
482
|
-
|
|
520
|
+
emit(e, acknowledged);
|
|
483
521
|
} else if (event.scene === "c2c") {
|
|
484
522
|
const UserAvatar = createUserAvatarURL(event.user_openid);
|
|
485
523
|
const UserId = event.user_openid;
|
|
486
524
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
487
|
-
const MessageText = event.data
|
|
525
|
+
const MessageText = event.data?.resolved?.button_data?.trim() || "";
|
|
488
526
|
const e = FormatEvent.create("private.interaction.create").addPlatform({
|
|
489
527
|
Platform: platform,
|
|
490
528
|
value: event,
|
|
@@ -497,21 +535,21 @@ const register = (client, options) => {
|
|
|
497
535
|
UserAvatar,
|
|
498
536
|
IsMaster: isMaster,
|
|
499
537
|
IsBot: false
|
|
500
|
-
}).addMessage({ MessageId: event.id }).addText({ MessageText }).addInteraction({
|
|
538
|
+
}).addMessage({ MessageId: event.event_id || event.id }).addText({ MessageText }).addInteraction({
|
|
501
539
|
InteractionId: event.id,
|
|
502
|
-
InteractionData: JSON.stringify(event.data
|
|
540
|
+
InteractionData: JSON.stringify(event.data?.resolved ?? {}),
|
|
503
541
|
Target: {
|
|
504
542
|
scope: "c2c",
|
|
505
543
|
targetId: event.user_openid,
|
|
506
544
|
BotId: botId
|
|
507
545
|
}
|
|
508
546
|
}).addOpen({ OpenId: `C2C:${event.user_openid}` }).add({ tag: "INTERACTION_CREATE_C2C" }).value;
|
|
509
|
-
|
|
547
|
+
emit(e, acknowledged);
|
|
510
548
|
} else if (event.scene === "guild") {
|
|
511
549
|
const UserAvatar = createUserAvatarURL(event.data.resolved.user_id);
|
|
512
550
|
const UserId = event.data.resolved.user_id;
|
|
513
551
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
514
|
-
const MessageText = event.data
|
|
552
|
+
const MessageText = event.data?.resolved?.button_data?.trim() || "";
|
|
515
553
|
const e = FormatEvent.create("interaction.create").addPlatform({
|
|
516
554
|
Platform: platform,
|
|
517
555
|
value: event,
|
|
@@ -529,14 +567,14 @@ const register = (client, options) => {
|
|
|
529
567
|
IsBot: false
|
|
530
568
|
}).addMessage({ MessageId: event.data.resolved.message_id }).addText({ MessageText }).addInteraction({
|
|
531
569
|
InteractionId: event.id,
|
|
532
|
-
InteractionData: JSON.stringify(event.data
|
|
570
|
+
InteractionData: JSON.stringify(event.data?.resolved ?? {}),
|
|
533
571
|
Target: {
|
|
534
572
|
scope: "channel",
|
|
535
573
|
targetId: event.channel_id,
|
|
536
574
|
BotId: botId
|
|
537
575
|
}
|
|
538
576
|
}).addOpen({ OpenId: `DIRECT:${event.guild_id}` }).add({ tag: "INTERACTION_CREATE_GUILD" }).value;
|
|
539
|
-
|
|
577
|
+
emit(e, acknowledged);
|
|
540
578
|
} else logger.warn({
|
|
541
579
|
code: ResultCode.Fail,
|
|
542
580
|
message: "暂未更新支持此类型的交互事件",
|
|
@@ -544,8 +582,8 @@ const register = (client, options) => {
|
|
|
544
582
|
});
|
|
545
583
|
});
|
|
546
584
|
client.on("MESSAGE_DELETE", (event) => {
|
|
547
|
-
const msg = event
|
|
548
|
-
|
|
585
|
+
const msg = event.message;
|
|
586
|
+
emit(FormatEvent.create("message.delete").addPlatform({
|
|
549
587
|
Platform: platform,
|
|
550
588
|
value: event,
|
|
551
589
|
BotId: botId
|
|
@@ -556,7 +594,7 @@ const register = (client, options) => {
|
|
|
556
594
|
});
|
|
557
595
|
client.on("PUBLIC_MESSAGE_DELETE", (event) => {
|
|
558
596
|
const msg = event.message;
|
|
559
|
-
|
|
597
|
+
emit(FormatEvent.create("message.delete").addPlatform({
|
|
560
598
|
Platform: platform,
|
|
561
599
|
value: event,
|
|
562
600
|
BotId: botId
|
|
@@ -567,14 +605,14 @@ const register = (client, options) => {
|
|
|
567
605
|
});
|
|
568
606
|
client.on("DIRECT_MESSAGE_DELETE", (event) => {
|
|
569
607
|
const msg = event.message;
|
|
570
|
-
|
|
608
|
+
emit(FormatEvent.create("private.message.delete").addPlatform({
|
|
571
609
|
Platform: platform,
|
|
572
610
|
value: event,
|
|
573
611
|
BotId: botId
|
|
574
612
|
}).addMessage({ MessageId: msg.id ?? "" }).add({ tag: "DIRECT_MESSAGE_DELETE" }).value);
|
|
575
613
|
});
|
|
576
614
|
client.on("MESSAGE_REACTION_ADD", (event) => {
|
|
577
|
-
|
|
615
|
+
emit(FormatEvent.create("message.reaction.add").addPlatform({
|
|
578
616
|
Platform: platform,
|
|
579
617
|
value: event,
|
|
580
618
|
BotId: botId
|
|
@@ -584,7 +622,7 @@ const register = (client, options) => {
|
|
|
584
622
|
}).addChannel({ ChannelId: event.channel_id ?? "" }).addMessage({ MessageId: event.target?.id ?? "" }).add({ tag: "MESSAGE_REACTION_ADD" }).value);
|
|
585
623
|
});
|
|
586
624
|
client.on("MESSAGE_REACTION_REMOVE", (event) => {
|
|
587
|
-
|
|
625
|
+
emit(FormatEvent.create("message.reaction.remove").addPlatform({
|
|
588
626
|
Platform: platform,
|
|
589
627
|
value: event,
|
|
590
628
|
BotId: botId
|
|
@@ -594,7 +632,7 @@ const register = (client, options) => {
|
|
|
594
632
|
}).addChannel({ ChannelId: event.channel_id ?? "" }).addMessage({ MessageId: event.target?.id ?? "" }).add({ tag: "MESSAGE_REACTION_REMOVE" }).value);
|
|
595
633
|
});
|
|
596
634
|
client.on("CHANNEL_CREATE", (event) => {
|
|
597
|
-
|
|
635
|
+
emit(FormatEvent.create("channel.create").addPlatform({
|
|
598
636
|
Platform: platform,
|
|
599
637
|
value: event,
|
|
600
638
|
BotId: botId
|
|
@@ -604,7 +642,7 @@ const register = (client, options) => {
|
|
|
604
642
|
}).addChannel({ ChannelId: event.id ?? "" }).add({ tag: "CHANNEL_CREATE" }).value);
|
|
605
643
|
});
|
|
606
644
|
client.on("CHANNEL_DELETE", (event) => {
|
|
607
|
-
|
|
645
|
+
emit(FormatEvent.create("channel.delete").addPlatform({
|
|
608
646
|
Platform: platform,
|
|
609
647
|
value: event,
|
|
610
648
|
BotId: botId
|
|
@@ -614,7 +652,7 @@ const register = (client, options) => {
|
|
|
614
652
|
}).addChannel({ ChannelId: event.id ?? "" }).add({ tag: "CHANNEL_DELETE" }).value);
|
|
615
653
|
});
|
|
616
654
|
client.on("GUILD_CREATE", (event) => {
|
|
617
|
-
|
|
655
|
+
emit(FormatEvent.create("guild.join").addPlatform({
|
|
618
656
|
Platform: platform,
|
|
619
657
|
value: event,
|
|
620
658
|
BotId: botId
|
|
@@ -629,7 +667,7 @@ const register = (client, options) => {
|
|
|
629
667
|
}).add({ tag: "GUILD_CREATE" }).value);
|
|
630
668
|
});
|
|
631
669
|
client.on("GUILD_DELETE", (event) => {
|
|
632
|
-
|
|
670
|
+
emit(FormatEvent.create("guild.exit").addPlatform({
|
|
633
671
|
Platform: platform,
|
|
634
672
|
value: event,
|
|
635
673
|
BotId: botId
|
|
@@ -646,7 +684,7 @@ const register = (client, options) => {
|
|
|
646
684
|
client.on("GUILD_MEMBER_ADD", (event) => {
|
|
647
685
|
const UserId = event.user?.id ?? "";
|
|
648
686
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
649
|
-
|
|
687
|
+
emit(FormatEvent.create("member.add").addPlatform({
|
|
650
688
|
Platform: platform,
|
|
651
689
|
value: event,
|
|
652
690
|
BotId: botId
|
|
@@ -665,7 +703,7 @@ const register = (client, options) => {
|
|
|
665
703
|
client.on("GUILD_MEMBER_REMOVE", (event) => {
|
|
666
704
|
const UserId = event.user?.id ?? "";
|
|
667
705
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
668
|
-
|
|
706
|
+
emit(FormatEvent.create("member.remove").addPlatform({
|
|
669
707
|
Platform: platform,
|
|
670
708
|
value: event,
|
|
671
709
|
BotId: botId
|
|
@@ -684,7 +722,7 @@ const register = (client, options) => {
|
|
|
684
722
|
client.on("GUILD_MEMBER_UPDATE", (event) => {
|
|
685
723
|
const UserId = event.user?.id ?? "";
|
|
686
724
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
687
|
-
|
|
725
|
+
emit(FormatEvent.create("member.update").addPlatform({
|
|
688
726
|
Platform: platform,
|
|
689
727
|
value: event,
|
|
690
728
|
BotId: botId
|
|
@@ -701,21 +739,21 @@ const register = (client, options) => {
|
|
|
701
739
|
}).add({ tag: "GUILD_MEMBER_UPDATE" }).value);
|
|
702
740
|
});
|
|
703
741
|
client.on("FRIEND_ADD", (event) => {
|
|
704
|
-
|
|
742
|
+
emit(FormatEvent.create("private.friend.add").addPlatform({
|
|
705
743
|
Platform: platform,
|
|
706
744
|
value: event,
|
|
707
745
|
BotId: botId
|
|
708
746
|
}).addUser(createUserMeta(event.openid ?? "")).addMessage({ MessageId: event.id }).add({ tag: "FRIEND_ADD" }).value);
|
|
709
747
|
});
|
|
710
748
|
client.on("FRIEND_DEL", (event) => {
|
|
711
|
-
|
|
749
|
+
emit(FormatEvent.create("private.friend.remove").addPlatform({
|
|
712
750
|
Platform: platform,
|
|
713
751
|
value: event,
|
|
714
752
|
BotId: botId
|
|
715
753
|
}).addUser(createUserMeta(event.openid ?? "")).add({ tag: "FRIEND_DEL" }).value);
|
|
716
754
|
});
|
|
717
755
|
client.on("CHANNEL_UPDATE", (event) => {
|
|
718
|
-
|
|
756
|
+
emit(FormatEvent.create("channel.update").addPlatform({
|
|
719
757
|
Platform: platform,
|
|
720
758
|
value: event,
|
|
721
759
|
BotId: botId
|
|
@@ -725,7 +763,7 @@ const register = (client, options) => {
|
|
|
725
763
|
}).addChannel({ ChannelId: event.id ?? "" }).add({ tag: "CHANNEL_UPDATE" }).value);
|
|
726
764
|
});
|
|
727
765
|
client.on("GUILD_UPDATE", (event) => {
|
|
728
|
-
|
|
766
|
+
emit(FormatEvent.create("guild.update").addPlatform({
|
|
729
767
|
Platform: platform,
|
|
730
768
|
value: event,
|
|
731
769
|
BotId: botId
|
|
@@ -735,7 +773,7 @@ const register = (client, options) => {
|
|
|
735
773
|
}).add({ tag: "GUILD_UPDATE" }).value);
|
|
736
774
|
});
|
|
737
775
|
client.on("GROUP_MSG_RECEIVE", (event) => {
|
|
738
|
-
|
|
776
|
+
emit(FormatEvent.create("notice.create").addPlatform({
|
|
739
777
|
Platform: platform,
|
|
740
778
|
value: event,
|
|
741
779
|
BotId: botId
|
|
@@ -745,7 +783,7 @@ const register = (client, options) => {
|
|
|
745
783
|
}).addChannel({ ChannelId: event.group_openid }).addUser(createUserMeta(event.op_member_openid)).addMessage({ MessageId: event.id }).add({ tag: "GROUP_MSG_RECEIVE" }).value);
|
|
746
784
|
});
|
|
747
785
|
client.on("GROUP_MSG_REJECT", (event) => {
|
|
748
|
-
|
|
786
|
+
emit(FormatEvent.create("notice.create").addPlatform({
|
|
749
787
|
Platform: platform,
|
|
750
788
|
value: event,
|
|
751
789
|
BotId: botId
|
|
@@ -755,41 +793,99 @@ const register = (client, options) => {
|
|
|
755
793
|
}).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
794
|
});
|
|
757
795
|
client.on("MESSAGE_AUDIT_PASS", (event) => {
|
|
758
|
-
const meta =
|
|
759
|
-
|
|
796
|
+
const meta = getAuditMeta(event);
|
|
797
|
+
emit(FormatEvent.create("notice.create").addPlatform({
|
|
760
798
|
Platform: platform,
|
|
761
799
|
value: event,
|
|
762
800
|
BotId: botId
|
|
763
801
|
}).addGuild({
|
|
764
|
-
GuildId: meta.
|
|
765
|
-
SpaceId:
|
|
766
|
-
}).addChannel({ ChannelId: meta.
|
|
802
|
+
GuildId: meta.guildId,
|
|
803
|
+
SpaceId: `${event.guild_id ? "GUILD" : "GROUP"}:${meta.channelId}`
|
|
804
|
+
}).addChannel({ ChannelId: meta.channelId }).addMessage({ MessageId: meta.messageId }).add({ tag: "MESSAGE_AUDIT_PASS" }).value);
|
|
767
805
|
});
|
|
768
806
|
client.on("MESSAGE_AUDIT_REJECT", (event) => {
|
|
769
|
-
const meta =
|
|
770
|
-
|
|
807
|
+
const meta = getAuditMeta(event);
|
|
808
|
+
emit(FormatEvent.create("notice.create").addPlatform({
|
|
771
809
|
Platform: platform,
|
|
772
810
|
value: event,
|
|
773
811
|
BotId: botId
|
|
774
812
|
}).addGuild({
|
|
775
|
-
GuildId: meta.
|
|
776
|
-
SpaceId:
|
|
777
|
-
}).addChannel({ ChannelId: meta.
|
|
813
|
+
GuildId: meta.guildId,
|
|
814
|
+
SpaceId: `${event.guild_id ? "GUILD" : "GROUP"}:${meta.channelId}`
|
|
815
|
+
}).addChannel({ ChannelId: meta.channelId }).addMessage({ MessageId: meta.messageId }).add({ tag: "MESSAGE_AUDIT_REJECT" }).value);
|
|
816
|
+
});
|
|
817
|
+
client.on("READY", (event) => {
|
|
818
|
+
emit(FormatEvent.create("notice.create").addPlatform({
|
|
819
|
+
Platform: platform,
|
|
820
|
+
value: event,
|
|
821
|
+
BotId: botId
|
|
822
|
+
}).addUser({
|
|
823
|
+
UserId: event.user?.id ?? "",
|
|
824
|
+
UserName: event.user?.name ?? "",
|
|
825
|
+
UserKey: "",
|
|
826
|
+
IsMaster: false,
|
|
827
|
+
IsBot: true
|
|
828
|
+
}).add({ tag: "READY" }).value);
|
|
778
829
|
});
|
|
830
|
+
const emitGuildNotice = (tag, event, authorId) => {
|
|
831
|
+
const guildId = event.guild_id ?? "";
|
|
832
|
+
const channelId = event.channel_id ?? "";
|
|
833
|
+
emit(FormatEvent.create("notice.create").addPlatform({
|
|
834
|
+
Platform: platform,
|
|
835
|
+
value: event,
|
|
836
|
+
BotId: botId
|
|
837
|
+
}).addGuild({
|
|
838
|
+
GuildId: guildId,
|
|
839
|
+
SpaceId: `GUILD:${channelId}`
|
|
840
|
+
}).addChannel({ ChannelId: channelId }).addUser(createUserMeta(authorId ?? event.author_id ?? "")).add({ tag }).value);
|
|
841
|
+
};
|
|
842
|
+
for (const tag of [
|
|
843
|
+
"FORUM_THREAD_CREATE",
|
|
844
|
+
"FORUM_THREAD_UPDATE",
|
|
845
|
+
"FORUM_THREAD_DELETE",
|
|
846
|
+
"FORUM_POST_CREATE",
|
|
847
|
+
"FORUM_POST_DELETE",
|
|
848
|
+
"FORUM_REPLY_CREATE",
|
|
849
|
+
"FORUM_REPLY_DELETE",
|
|
850
|
+
"FORUM_PUBLISH_AUDIT_RESULT",
|
|
851
|
+
"AUDIO_START",
|
|
852
|
+
"AUDIO_FINISH",
|
|
853
|
+
"AUDIO_ON_MIC",
|
|
854
|
+
"AUDIO_OFF_MIC",
|
|
855
|
+
"AUDIO_OR_LIVE_CHANNEL_MEMBER_ENTER",
|
|
856
|
+
"AUDIO_OR_LIVE_CHANNEL_MEMBER_EXIT"
|
|
857
|
+
]) 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
858
|
client.on("C2C_MSG_RECEIVE", (event) => {
|
|
780
|
-
|
|
859
|
+
emit(FormatEvent.create("private.notice.create").addPlatform({
|
|
781
860
|
Platform: platform,
|
|
782
861
|
value: event,
|
|
783
862
|
BotId: botId
|
|
784
863
|
}).addUser(createUserMeta(event.openid ?? "")).addMessage({ MessageId: event.id }).add({ tag: "C2C_MSG_RECEIVE" }).value);
|
|
785
864
|
});
|
|
786
865
|
client.on("C2C_MSG_REJECT", (event) => {
|
|
787
|
-
|
|
866
|
+
emit(FormatEvent.create("private.notice.create").addPlatform({
|
|
788
867
|
Platform: platform,
|
|
789
868
|
value: event,
|
|
790
869
|
BotId: botId
|
|
791
870
|
}).addUser(createUserMeta(event.openid ?? "")).addMessage({ MessageId: `c2c_msg_reject_${event.openid}_${event.timestamp}` }).add({ tag: "C2C_MSG_REJECT" }).value);
|
|
792
871
|
});
|
|
872
|
+
client.on("SUBSCRIBE_MESSAGE_STATUS", (event) => {
|
|
873
|
+
if (event.group_openid) emit(FormatEvent.create("notice.create").addPlatform({
|
|
874
|
+
Platform: platform,
|
|
875
|
+
value: event,
|
|
876
|
+
BotId: botId,
|
|
877
|
+
IsPrivate: false
|
|
878
|
+
}).addGuild({
|
|
879
|
+
GuildId: event.group_openid,
|
|
880
|
+
SpaceId: `GROUP:${event.group_openid}`
|
|
881
|
+
}).addChannel({ ChannelId: event.group_openid }).add({ tag: "SUBSCRIBE_MESSAGE_STATUS" }).value);
|
|
882
|
+
else emit(FormatEvent.create("private.notice.create").addPlatform({
|
|
883
|
+
Platform: platform,
|
|
884
|
+
value: event,
|
|
885
|
+
BotId: botId,
|
|
886
|
+
IsPrivate: true
|
|
887
|
+
}).addUser(createUserMeta(event.openid || "")).add({ tag: "SUBSCRIBE_MESSAGE_STATUS" }).value);
|
|
888
|
+
});
|
|
793
889
|
client.on("ERROR", console.error);
|
|
794
890
|
const api = {
|
|
795
891
|
active: { send: {
|
|
@@ -861,17 +957,9 @@ const register = (client, options) => {
|
|
|
861
957
|
const value = event.value || {};
|
|
862
958
|
const Metions = [];
|
|
863
959
|
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
|
-
});
|
|
960
|
+
const mentions = event.value["mentions"] || [];
|
|
961
|
+
const scope = event.SpaceId?.startsWith("GROUP:") ? "group" : event.IsPrivate ? "c2c" : "channel";
|
|
962
|
+
const MessageMention = mentions.map((item) => normalizeMessageUser(item, scope));
|
|
875
963
|
return new Promise((resolve) => resolve(MessageMention));
|
|
876
964
|
} else return new Promise((resolve) => resolve(Metions));
|
|
877
965
|
}
|
|
@@ -879,12 +967,39 @@ const register = (client, options) => {
|
|
|
879
967
|
};
|
|
880
968
|
const onactions = async (data, consume) => {
|
|
881
969
|
const event = data.payload.event ?? {};
|
|
970
|
+
const requestedBot = data.payload.params?.target?.BotId ?? data.payload.target?.BotId ?? data.payload.BotId ?? event.BotId;
|
|
971
|
+
if (requestedBot && requestedBot !== botId) {
|
|
972
|
+
consume([createResult(ResultCode.FailParams, "BotId does not match this adapter", null)]);
|
|
973
|
+
return;
|
|
974
|
+
}
|
|
882
975
|
const getGroupOpenId = () => data.payload.ChannelId ?? data.payload.params?.groupOpenId ?? data.payload.GuildId ?? event.ChannelId ?? event.GuildId ?? "";
|
|
883
976
|
const getMemberOpenId = () => data.payload.params?.memberOpenId ?? data.payload.UserId ?? event.UserId ?? "";
|
|
884
977
|
const getGuildId = () => data.payload.GuildId ?? event.GuildId ?? "";
|
|
885
978
|
const getUserId = () => data.payload.UserId ?? event.UserId ?? "";
|
|
886
979
|
const getChannelId = () => data.payload.ChannelId ?? event.ChannelId ?? "";
|
|
887
980
|
try {
|
|
981
|
+
if (data.action === "media.send.user" || data.action === "media.send.channel") {
|
|
982
|
+
const scope = data.payload.target?.scope;
|
|
983
|
+
if (data.action === "media.send.user" && (!scope || scope === "group" || scope === "c2c") || data.action === "media.send.channel" && scope === "group") {
|
|
984
|
+
await onactions({
|
|
985
|
+
action: "media.send",
|
|
986
|
+
payload: {
|
|
987
|
+
...data.payload,
|
|
988
|
+
target: {
|
|
989
|
+
scope: data.action === "media.send.user" ? "c2c" : "group",
|
|
990
|
+
targetId: data.action === "media.send.user" ? getUserId() : getChannelId(),
|
|
991
|
+
BotId: data.payload.BotId ?? data.payload.target?.BotId ?? event.BotId
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
}, consume);
|
|
995
|
+
return;
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
const handled = await handleFrameworkAction(client, data, botId);
|
|
999
|
+
if (handled) {
|
|
1000
|
+
consume(handled);
|
|
1001
|
+
return;
|
|
1002
|
+
}
|
|
888
1003
|
if (data.action === "me.info") {
|
|
889
1004
|
const res = await client.usersMe();
|
|
890
1005
|
const UserId = res.id;
|
|
@@ -892,7 +1007,11 @@ const register = (client, options) => {
|
|
|
892
1007
|
const botInfo = {
|
|
893
1008
|
UserId: res?.id,
|
|
894
1009
|
UserName: res?.username,
|
|
895
|
-
UserAvatar: createUserAvatarURL(res?.id),
|
|
1010
|
+
UserAvatar: res?.avatar || createUserAvatarURL(res?.id),
|
|
1011
|
+
UnionId: res?.union_openid,
|
|
1012
|
+
AccountId: res?.union_user_account,
|
|
1013
|
+
ShareUrl: res?.share_url,
|
|
1014
|
+
WelcomeMessage: res?.welcome_msg,
|
|
896
1015
|
IsBot: true,
|
|
897
1016
|
IsMaster: isMaster,
|
|
898
1017
|
UserKey
|
|
@@ -940,11 +1059,34 @@ const register = (client, options) => {
|
|
|
940
1059
|
consume([createResult(ResultCode.Fail, "interaction.ack 缺少 InteractionId", null)]);
|
|
941
1060
|
return;
|
|
942
1061
|
}
|
|
943
|
-
|
|
944
|
-
consume([res]);
|
|
945
|
-
consume([res]);
|
|
1062
|
+
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
1063
|
} 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
1064
|
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))]);
|
|
1065
|
+
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))]);
|
|
1066
|
+
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))]);
|
|
1067
|
+
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))]);
|
|
1068
|
+
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))]);
|
|
1069
|
+
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))]);
|
|
1070
|
+
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))]);
|
|
1071
|
+
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))]);
|
|
1072
|
+
else if (data.action === "forum.create") {
|
|
1073
|
+
const params = data.payload.params;
|
|
1074
|
+
consume([await client.channelsThreadsPut(getChannelId(), {
|
|
1075
|
+
title: params.title,
|
|
1076
|
+
content: params.content,
|
|
1077
|
+
format: params.format
|
|
1078
|
+
}).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1079
|
+
} 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))]);
|
|
1080
|
+
else if (data.action === "audio.control") {
|
|
1081
|
+
const params = data.payload.params;
|
|
1082
|
+
consume([await client.channelsAudioPost(getChannelId(), {
|
|
1083
|
+
status: params.status,
|
|
1084
|
+
audio_url: params.audioUrl,
|
|
1085
|
+
text: params.text
|
|
1086
|
+
}).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1087
|
+
} 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))]);
|
|
1088
|
+
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))]);
|
|
1089
|
+
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
1090
|
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
1091
|
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
1092
|
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 +1214,8 @@ const register = (client, options) => {
|
|
|
1072
1214
|
color: params.color
|
|
1073
1215
|
}).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1074
1216
|
} 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(),
|
|
1217
|
+
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))]);
|
|
1218
|
+
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
1219
|
else if (data.action === "file.send.channel") consume([await client.postRichMediaByGroup(getGroupOpenId(), {
|
|
1078
1220
|
file_type: data.payload.params?.file_type ?? 1,
|
|
1079
1221
|
url: data.payload.params?.url,
|
|
@@ -1120,23 +1262,25 @@ const register = (client, options) => {
|
|
|
1120
1262
|
}
|
|
1121
1263
|
const params = data.payload.params || {};
|
|
1122
1264
|
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))]);
|
|
1265
|
+
consume(await handleFrameworkAction(client, {
|
|
1266
|
+
action: "message.send",
|
|
1267
|
+
payload: {
|
|
1268
|
+
...data.payload,
|
|
1269
|
+
params: {
|
|
1270
|
+
...params,
|
|
1271
|
+
content: {
|
|
1272
|
+
text: params.content,
|
|
1273
|
+
media: { fileId: params.fileId }
|
|
1274
|
+
}
|
|
1275
|
+
}
|
|
1276
|
+
}
|
|
1277
|
+
}, botId) ?? [createResult(ResultCode.FailParams, "Unsupported media target", null)]);
|
|
1137
1278
|
return;
|
|
1138
1279
|
}
|
|
1139
|
-
const upload = await uploadMedia(target,
|
|
1280
|
+
const upload = await uploadMedia(target, {
|
|
1281
|
+
...params,
|
|
1282
|
+
send: false
|
|
1283
|
+
}).then((value) => value.fileId).catch((error) => {
|
|
1140
1284
|
consume([createResult(ResultCode.Fail, data.action, error)]);
|
|
1141
1285
|
return null;
|
|
1142
1286
|
});
|
|
@@ -1144,6 +1288,7 @@ const register = (client, options) => {
|
|
|
1144
1288
|
await onactions({
|
|
1145
1289
|
action: "media.send",
|
|
1146
1290
|
payload: {
|
|
1291
|
+
...data.payload,
|
|
1147
1292
|
target,
|
|
1148
1293
|
params: {
|
|
1149
1294
|
...params,
|
|
@@ -1197,6 +1342,10 @@ const register = (client, options) => {
|
|
|
1197
1342
|
else if (data.action === "permission.set") {
|
|
1198
1343
|
const params = data.payload.params;
|
|
1199
1344
|
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))]);
|
|
1345
|
+
} 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))]);
|
|
1346
|
+
else if (data.action === "permission.role.set") {
|
|
1347
|
+
const params = data.payload.params ?? {};
|
|
1348
|
+
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
1349
|
} 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
1350
|
else if (data.action === "channel.announce") {
|
|
1202
1351
|
const guildId = getGuildId();
|
|
@@ -1206,9 +1355,24 @@ const register = (client, options) => {
|
|
|
1206
1355
|
message_id: params?.messageId,
|
|
1207
1356
|
channel_id: params?.channelId
|
|
1208
1357
|
}).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1209
|
-
} else consume([createResult(ResultCode.Fail,
|
|
1358
|
+
} 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))]);
|
|
1359
|
+
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))]);
|
|
1360
|
+
else if (data.action === "channel.api-permission.request") {
|
|
1361
|
+
const params = data.payload.params;
|
|
1362
|
+
consume([await client.guildsApiPermissionDemand(getGuildId(), {
|
|
1363
|
+
channel_id: getChannelId(),
|
|
1364
|
+
api_identify: {
|
|
1365
|
+
path: params.path,
|
|
1366
|
+
method: params.method
|
|
1367
|
+
},
|
|
1368
|
+
desc: params.description
|
|
1369
|
+
}).then((r) => createResult(ResultCode.Ok, data.action, r)).catch((err) => createResult(ResultCode.Fail, data.action, err))]);
|
|
1370
|
+
} 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))]);
|
|
1371
|
+
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))]);
|
|
1372
|
+
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))]);
|
|
1373
|
+
else consume([createResult(ResultCode.Fail, "未知请求,请尝试升级版本", null)]);
|
|
1210
1374
|
} catch (error) {
|
|
1211
|
-
consume([createResult(ResultCode.Fail, "请求失败", error)]);
|
|
1375
|
+
consume([createResult(ResultCode.Fail, "请求失败", error?.response?.data ?? error?.message ?? error)]);
|
|
1212
1376
|
}
|
|
1213
1377
|
};
|
|
1214
1378
|
const onapis = async (data, consume) => {
|
|
@@ -1233,7 +1397,7 @@ const register = (client, options) => {
|
|
|
1233
1397
|
const res = await target.call(parent, ...params);
|
|
1234
1398
|
consume([createResult(ResultCode.Ok, "请求完成", res)]);
|
|
1235
1399
|
} catch (error) {
|
|
1236
|
-
consume([createResult(ResultCode.Fail, "请求失败", error)]);
|
|
1400
|
+
consume([createResult(ResultCode.Fail, "请求失败", error?.response?.data ?? error?.message ?? error)]);
|
|
1237
1401
|
}
|
|
1238
1402
|
};
|
|
1239
1403
|
if (options?.bindActions !== false) {
|