@napuketto/adapter 0.16.2 → 0.16.4
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/dist/core/index.d.mts +2 -2
- package/dist/core/index.mjs +1 -1
- package/dist/{core-D5c78lFV.mjs → core-l7TM-aKF.mjs} +23 -2
- package/dist/core-l7TM-aKF.mjs.map +1 -0
- package/dist/{essence-Gnvq6YWT.mjs → essence-CU3kvItK.mjs} +12 -3
- package/dist/{essence-Gnvq6YWT.mjs.map → essence-CU3kvItK.mjs.map} +1 -1
- package/dist/gray-tip-DNo_Mi4E.d.mts.map +1 -1
- package/dist/{index-Dhd-kaUF.d.mts → index-jdSniAj1.d.mts} +13 -3
- package/dist/index-jdSniAj1.d.mts.map +1 -0
- package/dist/kurobot/index.d.mts +12 -5
- package/dist/kurobot/index.d.mts.map +1 -1
- package/dist/kurobot/index.mjs +9 -9
- package/dist/kurobot/index.mjs.map +1 -1
- package/dist/log-AtQxAmbQ.mjs +214 -0
- package/dist/log-AtQxAmbQ.mjs.map +1 -0
- package/dist/milky/index.d.mts +15 -15
- package/dist/milky/index.d.mts.map +1 -1
- package/dist/milky/index.mjs +212 -254
- package/dist/milky/index.mjs.map +1 -1
- package/dist/onebot11/index.d.mts +1 -1
- package/dist/onebot11/index.d.mts.map +1 -1
- package/dist/onebot11/index.mjs +238 -268
- package/dist/onebot11/index.mjs.map +1 -1
- package/dist/{raw-message-Cz0UOrND.mjs → raw-message-D5nMIebz.mjs} +3 -3
- package/dist/raw-message-D5nMIebz.mjs.map +1 -0
- package/dist/satori/index.d.mts +115 -115
- package/dist/satori/index.d.mts.map +1 -1
- package/dist/satori/index.mjs +15 -19
- package/dist/satori/index.mjs.map +1 -1
- package/package.json +4 -4
- package/dist/core-D5c78lFV.mjs.map +0 -1
- package/dist/index-Dhd-kaUF.d.mts.map +0 -1
- package/dist/log-BznNQnpx.mjs +0 -80
- package/dist/log-BznNQnpx.mjs.map +0 -1
- package/dist/media-DMMn74TC.mjs +0 -126
- package/dist/media-DMMn74TC.mjs.map +0 -1
- package/dist/raw-message-Cz0UOrND.mjs.map +0 -1
package/dist/milky/index.mjs
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { a as
|
|
4
|
-
import { a as
|
|
5
|
-
import { ChatType, GrayTipSubType, GroupApi, GroupNotifyMsgStatus, GroupNotifyMsgType, NTGroupRequestOperateTypes, TicketApi, TipGroupElementType, kernelError, toCanonicalElements } from "@napuketto/kernel";
|
|
1
|
+
import { a as runAction, i as ActionRegistry, r as BaseProtocolAdapter } from "../core-l7TM-aKF.mjs";
|
|
2
|
+
import { c as collectGrayTipUids, d as hasGrayTip, l as findRevokeElement, n as sliceRaw, o as fileUriToPath, t as logEventFailure, u as firstUntranslatedGrayTip } from "../log-AtQxAmbQ.mjs";
|
|
3
|
+
import { a as firstNonEmptyString, c as MS_TO_SEC, d as resolveUin, f as toUin, i as toUnixSeconds, l as NUMERIC_RE, o as stringOrUndefined, r as subscribeRawMessages, s as startupBaselineSec, t as forEachRawMessage, u as numericUin } from "../raw-message-D5nMIebz.mjs";
|
|
4
|
+
import { a as narrowSysMsgBlobs, c as recognizeSysMsg, d as varintOf, f as BuddyReqDedup, h as narrowBuddyReqs, i as OBSERVED_UNNAMED_SYSMSG_KEYS, l as textOf, m as filterBuddyReqs, n as extractEssenceSetSysMsg, o as nodeAt, p as batchUnreadNums, r as narrowEssenceGroupArg, s as processSysMsgBlob, t as EssenceListSync, u as varintAt } from "../essence-CU3kvItK.mjs";
|
|
5
|
+
import { ChatType, GrayTipSubType, GroupApi, GroupNotifyMsgStatus, GroupNotifyMsgType, NTGroupMemberRole, NTGroupRequestOperateTypes, TicketApi, TipGroupElementType, errorMessage, kernelError, toCanonicalElements } from "@napuketto/kernel";
|
|
6
6
|
import { z } from "zod";
|
|
7
7
|
import { randomUUID } from "node:crypto";
|
|
8
|
+
import { mkdir, rename, writeFile } from "node:fs/promises";
|
|
8
9
|
import { join } from "node:path";
|
|
9
10
|
import { detectFileType, downloadUrl, inferExtension } from "@napuketto/media";
|
|
10
|
-
import { mkdir, rename, writeFile } from "node:fs/promises";
|
|
11
|
-
import { fileURLToPath } from "node:url";
|
|
12
11
|
import { HttpClient, HttpServer, createSseResponse, isWsOpen } from "@napuketto/network";
|
|
13
12
|
// src/milky/action/base-action.ts
|
|
14
13
|
/** KernelErrorCode → Milky retcode 映射表(-400/-403 规范语义,其余取常见 HTTP 语义近似负数)。 */
|
|
@@ -119,7 +118,8 @@ function toFriendEntity(friend, uin, nick) {
|
|
|
119
118
|
/** 群域共入参(群号 / 成员 uin / 可选布尔;群管理 / 通知 / 精华 / 文件域复用)。 */
|
|
120
119
|
const groupIdField = { group_id: z.number().int().min(10001) };
|
|
121
120
|
const userIdField = { user_id: z.number().int().min(10001) };
|
|
122
|
-
const optBool
|
|
121
|
+
const optBool = z.boolean().nullable().optional();
|
|
122
|
+
const optStr = z.string().nullable().optional();
|
|
123
123
|
/** 群查询域动作工厂(群信息 / 成员列表 / 成员单查 / 公告列表)。 */
|
|
124
124
|
function createGroupQueryActions(api) {
|
|
125
125
|
return [
|
|
@@ -127,7 +127,7 @@ function createGroupQueryActions(api) {
|
|
|
127
127
|
name: "get_group_info",
|
|
128
128
|
schema: z.object({
|
|
129
129
|
...groupIdField,
|
|
130
|
-
no_cache: optBool
|
|
130
|
+
no_cache: optBool
|
|
131
131
|
}),
|
|
132
132
|
handle: async (payload) => {
|
|
133
133
|
const groupCode = String(payload.group_id);
|
|
@@ -138,7 +138,7 @@ function createGroupQueryActions(api) {
|
|
|
138
138
|
name: "get_group_member_list",
|
|
139
139
|
schema: z.object({
|
|
140
140
|
...groupIdField,
|
|
141
|
-
no_cache: optBool
|
|
141
|
+
no_cache: optBool
|
|
142
142
|
}),
|
|
143
143
|
handle: async (payload) => {
|
|
144
144
|
return { members: (await membersOf(api, String(payload.group_id))).map((m) => toGroupMemberEntity(m, String(payload.group_id), m.uin)) };
|
|
@@ -149,7 +149,7 @@ function createGroupQueryActions(api) {
|
|
|
149
149
|
schema: z.object({
|
|
150
150
|
...groupIdField,
|
|
151
151
|
...userIdField,
|
|
152
|
-
no_cache: optBool
|
|
152
|
+
no_cache: optBool
|
|
153
153
|
}),
|
|
154
154
|
handle: async (payload) => {
|
|
155
155
|
return { member: toGroupMemberEntity(await memberOf(api, payload.group_id, payload.user_id), String(payload.group_id), String(payload.user_id)) };
|
|
@@ -181,7 +181,7 @@ async function memberOf(api, groupId, userId) {
|
|
|
181
181
|
api.logger?.debug({
|
|
182
182
|
group: groupCode,
|
|
183
183
|
uin,
|
|
184
|
-
error:
|
|
184
|
+
error: errorMessage(err)
|
|
185
185
|
}, "milky: 成员 uin→uid 失败,退用 uin 查缓存");
|
|
186
186
|
return uin;
|
|
187
187
|
});
|
|
@@ -211,7 +211,7 @@ async function senderUinOf(b, api) {
|
|
|
211
211
|
const uins = await api.uidToUin([uid]).catch((err) => {
|
|
212
212
|
api.logger?.debug({
|
|
213
213
|
uid,
|
|
214
|
-
error:
|
|
214
|
+
error: errorMessage(err)
|
|
215
215
|
}, "milky: 公告发送者 uid→uin 失败,兜底 0");
|
|
216
216
|
});
|
|
217
217
|
return Number(uins?.get(uid)) || 0;
|
|
@@ -247,7 +247,7 @@ function createGroupEssenceActions(api) {
|
|
|
247
247
|
schema: z.object({
|
|
248
248
|
...groupIdField,
|
|
249
249
|
message_seq: z.number().int().min(0),
|
|
250
|
-
is_set: optBool
|
|
250
|
+
is_set: optBool
|
|
251
251
|
}),
|
|
252
252
|
handle: async (payload) => {
|
|
253
253
|
const groupCode = String(payload.group_id);
|
|
@@ -328,8 +328,6 @@ function essenceToEntity(item, groupId) {
|
|
|
328
328
|
* - http(s):// → @napuketto/media downloadUrl 落盘 cacheDir/milky/
|
|
329
329
|
* 未配置 mediaDir 时远程 URI 报错(不发静默空消息)。
|
|
330
330
|
*/
|
|
331
|
-
/** file:// 前缀(fileURLToPath 失败时的裸剥离兜底)。 */
|
|
332
|
-
const FILE_URI_PREFIX_RE$1 = /^file:\/\//;
|
|
333
331
|
/** 解析远程媒体 URI 为本地绝对路径(base64:// / http(s)://;file:// 走同步面)。 */
|
|
334
332
|
async function resolveMediaUri(uri, mediaDir) {
|
|
335
333
|
if (mediaDir === void 0 || mediaDir === "") throw kernelError("远程媒体发送需要配置 [accounts.milky] cacheDir(下载缓存目录)", "INVALID_PARAM");
|
|
@@ -344,11 +342,7 @@ async function resolveMediaUri(uri, mediaDir) {
|
|
|
344
342
|
* resolveMediaUri 落盘;裸路径(go-cqhttp 惯例)原样。
|
|
345
343
|
*/
|
|
346
344
|
async function resolveUriToPath(uri, mediaDir) {
|
|
347
|
-
if (uri.startsWith("file://"))
|
|
348
|
-
return fileURLToPath(uri);
|
|
349
|
-
} catch {
|
|
350
|
-
return uri.replace(FILE_URI_PREFIX_RE$1, "");
|
|
351
|
-
}
|
|
345
|
+
if (uri.startsWith("file://")) return fileUriToPath(uri);
|
|
352
346
|
if (uri.startsWith("http://") || uri.startsWith("https://") || uri.startsWith("base64://")) return await resolveMediaUri(uri, mediaDir);
|
|
353
347
|
return uri;
|
|
354
348
|
}
|
|
@@ -375,7 +369,6 @@ async function writeBase64(payload, mediaDir) {
|
|
|
375
369
|
}
|
|
376
370
|
// src/milky/action/group-file.ts
|
|
377
371
|
const fileIdField = { file_id: z.string().min(1) };
|
|
378
|
-
const optStr$2 = z.string().nullable().optional();
|
|
379
372
|
/** 群文件域动作工厂(列表 / 移动 / 重命名 / 删除 / 转存 / 文件夹 / 闪传上传 / 下载链接)。 */
|
|
380
373
|
function createGroupFileActions(api) {
|
|
381
374
|
return [
|
|
@@ -383,7 +376,7 @@ function createGroupFileActions(api) {
|
|
|
383
376
|
name: "get_group_files",
|
|
384
377
|
schema: z.object({
|
|
385
378
|
...groupIdField,
|
|
386
|
-
parent_folder_id: optStr
|
|
379
|
+
parent_folder_id: optStr
|
|
387
380
|
}),
|
|
388
381
|
handle: async (payload) => {
|
|
389
382
|
const groupCode = String(payload.group_id);
|
|
@@ -404,8 +397,8 @@ function createGroupFileActions(api) {
|
|
|
404
397
|
schema: z.object({
|
|
405
398
|
...groupIdField,
|
|
406
399
|
...fileIdField,
|
|
407
|
-
parent_folder_id: optStr
|
|
408
|
-
target_folder_id: optStr
|
|
400
|
+
parent_folder_id: optStr,
|
|
401
|
+
target_folder_id: optStr
|
|
409
402
|
}),
|
|
410
403
|
handle: async (payload) => {
|
|
411
404
|
await api.richMediaApi.moveGroupFile(String(payload.group_id), [payload.file_id], payload.target_folder_id ?? "");
|
|
@@ -417,7 +410,7 @@ function createGroupFileActions(api) {
|
|
|
417
410
|
schema: z.object({
|
|
418
411
|
...groupIdField,
|
|
419
412
|
...fileIdField,
|
|
420
|
-
parent_folder_id: optStr
|
|
413
|
+
parent_folder_id: optStr,
|
|
421
414
|
new_file_name: z.string().min(1)
|
|
422
415
|
}),
|
|
423
416
|
handle: async (payload) => {
|
|
@@ -472,7 +465,7 @@ function createGroupFileActions(api) {
|
|
|
472
465
|
name: "upload_group_file",
|
|
473
466
|
schema: z.object({
|
|
474
467
|
...groupIdField,
|
|
475
|
-
parent_folder_id: optStr
|
|
468
|
+
parent_folder_id: optStr,
|
|
476
469
|
file_uri: z.string().min(1),
|
|
477
470
|
file_name: z.string().min(1)
|
|
478
471
|
}),
|
|
@@ -541,6 +534,152 @@ function folderToEntity(info, groupId) {
|
|
|
541
534
|
file_count: num("totalFileCount")
|
|
542
535
|
};
|
|
543
536
|
}
|
|
537
|
+
// src/milky/api.ts
|
|
538
|
+
var MilkyApi = class {
|
|
539
|
+
msgApi;
|
|
540
|
+
groupApi;
|
|
541
|
+
friendApi;
|
|
542
|
+
profileApi;
|
|
543
|
+
profileLikeApi;
|
|
544
|
+
ticketApi;
|
|
545
|
+
webApi;
|
|
546
|
+
groupNotifyApi;
|
|
547
|
+
richMediaApi;
|
|
548
|
+
/** kernel 闪传 API(文件投递:分享卡片,见 flash-transfer.ts 语义说明)。 */
|
|
549
|
+
flashTransferApi;
|
|
550
|
+
recentContactApi;
|
|
551
|
+
self;
|
|
552
|
+
groupCache;
|
|
553
|
+
qqVersion;
|
|
554
|
+
implVersion;
|
|
555
|
+
mediaDir;
|
|
556
|
+
/** 动作层可观测出口(缺省静默)。 */
|
|
557
|
+
logger;
|
|
558
|
+
/** message_seq ↔ msgId 双向映射(接收链路 record,动作侧反查)。 */
|
|
559
|
+
seqIndex;
|
|
560
|
+
constructor(opts, seqIndex) {
|
|
561
|
+
this.msgApi = opts.msgApi;
|
|
562
|
+
this.groupApi = opts.groupApi;
|
|
563
|
+
this.friendApi = opts.friendApi;
|
|
564
|
+
this.profileApi = opts.profileApi;
|
|
565
|
+
this.profileLikeApi = opts.profileLikeApi;
|
|
566
|
+
this.ticketApi = opts.ticketApi;
|
|
567
|
+
this.webApi = opts.webApi;
|
|
568
|
+
this.groupNotifyApi = opts.groupNotifyApi;
|
|
569
|
+
this.richMediaApi = opts.richMediaApi;
|
|
570
|
+
this.flashTransferApi = opts.flashTransferApi;
|
|
571
|
+
this.recentContactApi = opts.recentContactApi;
|
|
572
|
+
this.self = opts.self;
|
|
573
|
+
this.groupCache = opts.groupCache;
|
|
574
|
+
this.qqVersion = opts.qqVersion;
|
|
575
|
+
this.implVersion = opts.implVersion;
|
|
576
|
+
this.mediaDir = opts.mediaDir;
|
|
577
|
+
this.logger = opts.logger;
|
|
578
|
+
this.seqIndex = seqIndex;
|
|
579
|
+
}
|
|
580
|
+
/** uin → uid(私聊目标 / at 段发送转换 / 群管动作的 uid 入参)。 */
|
|
581
|
+
uinToUid(uins) {
|
|
582
|
+
return this.groupApi.uinToUid(uins);
|
|
583
|
+
}
|
|
584
|
+
/** uid → uin(事件路径 mention 转换)。 */
|
|
585
|
+
uidToUin(uids) {
|
|
586
|
+
return this.groupApi.uidToUin(uids);
|
|
587
|
+
}
|
|
588
|
+
/**
|
|
589
|
+
* uin(数字)→ uid(群管动作入参转换);转换失败抛 INVALID_PARAM
|
|
590
|
+
* (Milky 入参 user_id 都是 uin,kernel 群管 API 要 uid)。
|
|
591
|
+
*/
|
|
592
|
+
async resolveUidFromUin(uin) {
|
|
593
|
+
const uinStr = String(uin);
|
|
594
|
+
let cause;
|
|
595
|
+
try {
|
|
596
|
+
const uid = (await this.uinToUid([uinStr])).get(uinStr);
|
|
597
|
+
if (uid !== void 0 && uid !== "") return uid;
|
|
598
|
+
} catch (err) {
|
|
599
|
+
cause = err;
|
|
600
|
+
}
|
|
601
|
+
throw kernelError(`用户 ${uinStr} 不存在或 uin→uid 转换失败`, "INVALID_PARAM", cause === void 0 ? void 0 : { cause });
|
|
602
|
+
}
|
|
603
|
+
/**
|
|
604
|
+
* message_scene + 数字 ID → NT Peer。
|
|
605
|
+
* group = 群号直作 peerUid;friend/temp = uin → uid(失败退 uin 原样,交 QQ 端判断)。
|
|
606
|
+
*/
|
|
607
|
+
async resolvePeer(scene, id) {
|
|
608
|
+
if (scene === "group") return {
|
|
609
|
+
chatType: ChatType.GROUP,
|
|
610
|
+
peerUid: String(id)
|
|
611
|
+
};
|
|
612
|
+
const uin = String(id);
|
|
613
|
+
let uid;
|
|
614
|
+
try {
|
|
615
|
+
uid = (await this.uinToUid([uin])).get(uin);
|
|
616
|
+
} catch (err) {
|
|
617
|
+
this.logger?.warn({
|
|
618
|
+
uin,
|
|
619
|
+
error: errorMessage(err)
|
|
620
|
+
}, "milky: uin→uid 转换失败,peer 退用 uin 原样");
|
|
621
|
+
}
|
|
622
|
+
return {
|
|
623
|
+
chatType: scene === "friend" ? ChatType.C2C : ChatType.C2C_TEMP,
|
|
624
|
+
peerUid: uid ?? uin
|
|
625
|
+
};
|
|
626
|
+
}
|
|
627
|
+
/**
|
|
628
|
+
* seq → msgId(索引优先,未登记扫描近段历史兜底)。
|
|
629
|
+
* 两层都未命中返回 undefined(调用方抛 NOT_FOUND)。
|
|
630
|
+
*/
|
|
631
|
+
async resolveMsgIdBySeq(peer, seq, chatType) {
|
|
632
|
+
const indexed = this.seqIndex.resolveMsgId(chatType, peer.peerUid, seq);
|
|
633
|
+
if (indexed !== void 0) return indexed;
|
|
634
|
+
const hit = (await this.msgApi.fetchMessages(peer, { count: 60 }).catch((err) => {
|
|
635
|
+
this.logger?.debug({
|
|
636
|
+
peer: peer.peerUid,
|
|
637
|
+
seq,
|
|
638
|
+
error: errorMessage(err)
|
|
639
|
+
}, "milky: msgSeq 反查近段历史失败");
|
|
640
|
+
return [];
|
|
641
|
+
})).find((m) => Number(m.msgSeq) === seq);
|
|
642
|
+
if (hit === void 0) return;
|
|
643
|
+
this.seqIndex.record(hit);
|
|
644
|
+
return hit.msgId;
|
|
645
|
+
}
|
|
646
|
+
/** 发送结果回查:msgId → {message_seq, time}(sendMessage 只回 msgId)。 */
|
|
647
|
+
async resolveSentOutput(peer, msgId) {
|
|
648
|
+
const [sent] = await this.msgApi.fetchMsgsByMsgId(peer, [msgId]);
|
|
649
|
+
if (sent === void 0) throw kernelError("发送结果回查失败(msgId 未命中)", "UNKNOWN");
|
|
650
|
+
this.seqIndex.record(sent);
|
|
651
|
+
return {
|
|
652
|
+
message_seq: Number(sent.msgSeq),
|
|
653
|
+
time: toUnixSeconds(sent.msgTime)
|
|
654
|
+
};
|
|
655
|
+
}
|
|
656
|
+
};
|
|
657
|
+
/** self.uid 必备(nudge 发送的 callerUid;缺配置报 INVALID_PARAM)。 */
|
|
658
|
+
function requireSelfUid(api) {
|
|
659
|
+
const uid = api.self.uid;
|
|
660
|
+
if (uid === void 0 || uid === "") throw kernelError("登录身份缺 uid(无法发起戳一戳)", "INVALID_PARAM");
|
|
661
|
+
return uid;
|
|
662
|
+
}
|
|
663
|
+
/**
|
|
664
|
+
* 按通知 seq 查找群通知(先非可疑后可疑两屏依序,OB11 set_group_add_request
|
|
665
|
+
* 同路径)。屏序惰性拉取:前一屏命中则不拉后续屏(群通知规范序)。
|
|
666
|
+
* 未找到抛 NOT_FOUND(应答动作的 seq 无效或已过期)。
|
|
667
|
+
* 模块级函数(非类成员):应答动作的公共入口,OB11 同路径。
|
|
668
|
+
*/
|
|
669
|
+
async function findGroupNotify(api, seq) {
|
|
670
|
+
const screens = [() => api.groupNotifyApi.getSingleScreenNotifies(false, 100), () => api.groupNotifyApi.getSingleScreenNotifies(true, 100)];
|
|
671
|
+
for (const fetchScreen of screens) {
|
|
672
|
+
const hit = (await fetchScreen()).find((item) => item.seq === seq);
|
|
673
|
+
if (hit !== void 0) return hit;
|
|
674
|
+
}
|
|
675
|
+
throw kernelError(`未找到通知 ${seq}(无效或已过期)`, "NOT_FOUND");
|
|
676
|
+
}
|
|
677
|
+
/** 按发起者 uid 查找好友申请(getBuddyReqList 匹配 friendUid);未找到抛 NOT_FOUND。 */
|
|
678
|
+
async function findBuddyReq(api, initiatorUid) {
|
|
679
|
+
const hit = (await api.friendApi.getBuddyReqList()).find((req) => req.friendUid === initiatorUid);
|
|
680
|
+
if (hit === void 0) throw kernelError(`未找到来自 ${initiatorUid} 的好友申请`, "NOT_FOUND");
|
|
681
|
+
return hit;
|
|
682
|
+
}
|
|
544
683
|
// src/milky/action/group-manage.ts
|
|
545
684
|
/**
|
|
546
685
|
* Milky 群管理域动作:send_group_nudge / set_group_name / set_group_member_card /
|
|
@@ -550,10 +689,6 @@ function folderToEntity(info, groupId) {
|
|
|
550
689
|
* 写操作合:成员类操作 user_id(uin) → uid 转换后进 kernel(resolveUidFromUin);
|
|
551
690
|
* 公告 image_uri / 头像 image_uri 落盘后进 kernel。
|
|
552
691
|
*/
|
|
553
|
-
const optStr$1 = z.string().nullable().optional();
|
|
554
|
-
/** NTGroupMemberRole 数值(ADMIN=3 / MEMBER=2,setMemberRole 入参)。 */
|
|
555
|
-
const NTGroupMemberRoleAdmin = 3;
|
|
556
|
-
const NTGroupMemberRoleMember = 2;
|
|
557
692
|
/** 群管理域动作工厂(群设置 / 成员管理 / 公告 / 戳一戳)。 */
|
|
558
693
|
function createGroupManageActions(api) {
|
|
559
694
|
return [
|
|
@@ -568,7 +703,7 @@ function createGroupManageActions(api) {
|
|
|
568
703
|
const peer = await api.resolvePeer("group", payload.group_id);
|
|
569
704
|
await api.msgApi.sendNudge(peer, {
|
|
570
705
|
receiverUid,
|
|
571
|
-
callerUid: requireSelfUid
|
|
706
|
+
callerUid: requireSelfUid(api)
|
|
572
707
|
});
|
|
573
708
|
return {};
|
|
574
709
|
}
|
|
@@ -602,11 +737,11 @@ function createGroupManageActions(api) {
|
|
|
602
737
|
schema: z.object({
|
|
603
738
|
...groupIdField,
|
|
604
739
|
...userIdField,
|
|
605
|
-
is_set: optBool
|
|
740
|
+
is_set: optBool
|
|
606
741
|
}),
|
|
607
742
|
handle: async (payload) => {
|
|
608
743
|
const uid = await api.resolveUidFromUin(payload.user_id);
|
|
609
|
-
api.groupApi.setMemberRole(String(payload.group_id), uid, payload.is_set === false ?
|
|
744
|
+
api.groupApi.setMemberRole(String(payload.group_id), uid, payload.is_set === false ? NTGroupMemberRole.MEMBER : NTGroupMemberRole.ADMIN);
|
|
610
745
|
return {};
|
|
611
746
|
}
|
|
612
747
|
}),
|
|
@@ -630,7 +765,7 @@ function createGroupManageActions(api) {
|
|
|
630
765
|
name: "set_group_whole_mute",
|
|
631
766
|
schema: z.object({
|
|
632
767
|
...groupIdField,
|
|
633
|
-
is_mute: optBool
|
|
768
|
+
is_mute: optBool
|
|
634
769
|
}),
|
|
635
770
|
handle: async (payload) => {
|
|
636
771
|
await api.groupApi.setGroupShutUp(String(payload.group_id), payload.is_mute !== false);
|
|
@@ -642,7 +777,7 @@ function createGroupManageActions(api) {
|
|
|
642
777
|
schema: z.object({
|
|
643
778
|
...groupIdField,
|
|
644
779
|
...userIdField,
|
|
645
|
-
reject_add_request: optBool
|
|
780
|
+
reject_add_request: optBool
|
|
646
781
|
}),
|
|
647
782
|
handle: async (payload) => {
|
|
648
783
|
const uid = await api.resolveUidFromUin(payload.user_id);
|
|
@@ -688,7 +823,7 @@ function createGroupManageActions(api) {
|
|
|
688
823
|
schema: z.object({
|
|
689
824
|
...groupIdField,
|
|
690
825
|
content: z.string().min(1),
|
|
691
|
-
image_uri: optStr
|
|
826
|
+
image_uri: optStr
|
|
692
827
|
}),
|
|
693
828
|
handle: async (payload) => {
|
|
694
829
|
const groupCode = String(payload.group_id);
|
|
@@ -711,154 +846,6 @@ function createGroupManageActions(api) {
|
|
|
711
846
|
})
|
|
712
847
|
];
|
|
713
848
|
}
|
|
714
|
-
/** self.uid 必备(nudge 发送的 callerUid;缺配置报 INVALID_PARAM)。 */
|
|
715
|
-
function requireSelfUid$1(api) {
|
|
716
|
-
const uid = api.self.uid;
|
|
717
|
-
if (uid === void 0 || uid === "") throw kernelError("登录身份缺 uid(无法发起戳一戳)", "INVALID_PARAM");
|
|
718
|
-
return uid;
|
|
719
|
-
}
|
|
720
|
-
// src/milky/api.ts
|
|
721
|
-
var MilkyApi = class {
|
|
722
|
-
msgApi;
|
|
723
|
-
groupApi;
|
|
724
|
-
friendApi;
|
|
725
|
-
profileApi;
|
|
726
|
-
profileLikeApi;
|
|
727
|
-
ticketApi;
|
|
728
|
-
webApi;
|
|
729
|
-
groupNotifyApi;
|
|
730
|
-
richMediaApi;
|
|
731
|
-
/** kernel 闪传 API(文件投递:分享卡片,见 flash-transfer.ts 语义说明)。 */
|
|
732
|
-
flashTransferApi;
|
|
733
|
-
recentContactApi;
|
|
734
|
-
self;
|
|
735
|
-
groupCache;
|
|
736
|
-
qqVersion;
|
|
737
|
-
implVersion;
|
|
738
|
-
mediaDir;
|
|
739
|
-
/** 动作层可观测出口(缺省静默)。 */
|
|
740
|
-
logger;
|
|
741
|
-
/** message_seq ↔ msgId 双向映射(接收链路 record,动作侧反查)。 */
|
|
742
|
-
seqIndex;
|
|
743
|
-
constructor(opts, seqIndex) {
|
|
744
|
-
this.msgApi = opts.msgApi;
|
|
745
|
-
this.groupApi = opts.groupApi;
|
|
746
|
-
this.friendApi = opts.friendApi;
|
|
747
|
-
this.profileApi = opts.profileApi;
|
|
748
|
-
this.profileLikeApi = opts.profileLikeApi;
|
|
749
|
-
this.ticketApi = opts.ticketApi;
|
|
750
|
-
this.webApi = opts.webApi;
|
|
751
|
-
this.groupNotifyApi = opts.groupNotifyApi;
|
|
752
|
-
this.richMediaApi = opts.richMediaApi;
|
|
753
|
-
this.flashTransferApi = opts.flashTransferApi;
|
|
754
|
-
this.recentContactApi = opts.recentContactApi;
|
|
755
|
-
this.self = opts.self;
|
|
756
|
-
this.groupCache = opts.groupCache;
|
|
757
|
-
this.qqVersion = opts.qqVersion;
|
|
758
|
-
this.implVersion = opts.implVersion;
|
|
759
|
-
this.mediaDir = opts.mediaDir;
|
|
760
|
-
this.logger = opts.logger;
|
|
761
|
-
this.seqIndex = seqIndex;
|
|
762
|
-
}
|
|
763
|
-
/** uin → uid(私聊目标 / at 段发送转换 / 群管动作的 uid 入参)。 */
|
|
764
|
-
uinToUid(uins) {
|
|
765
|
-
return this.groupApi.uinToUid(uins);
|
|
766
|
-
}
|
|
767
|
-
/** uid → uin(事件路径 mention 转换)。 */
|
|
768
|
-
uidToUin(uids) {
|
|
769
|
-
return this.groupApi.uidToUin(uids);
|
|
770
|
-
}
|
|
771
|
-
/**
|
|
772
|
-
* uin(数字)→ uid(群管动作入参转换);转换失败抛 INVALID_PARAM
|
|
773
|
-
* (Milky 入参 user_id 都是 uin,kernel 群管 API 要 uid)。
|
|
774
|
-
*/
|
|
775
|
-
async resolveUidFromUin(uin) {
|
|
776
|
-
const uinStr = String(uin);
|
|
777
|
-
let cause;
|
|
778
|
-
try {
|
|
779
|
-
const uid = (await this.uinToUid([uinStr])).get(uinStr);
|
|
780
|
-
if (uid !== void 0 && uid !== "") return uid;
|
|
781
|
-
} catch (err) {
|
|
782
|
-
cause = err;
|
|
783
|
-
}
|
|
784
|
-
throw kernelError(`用户 ${uinStr} 不存在或 uin→uid 转换失败`, "INVALID_PARAM", cause === void 0 ? void 0 : { cause });
|
|
785
|
-
}
|
|
786
|
-
/**
|
|
787
|
-
* message_scene + 数字 ID → NT Peer。
|
|
788
|
-
* group = 群号直作 peerUid;friend/temp = uin → uid(失败退 uin 原样,交 QQ 端判断)。
|
|
789
|
-
*/
|
|
790
|
-
async resolvePeer(scene, id) {
|
|
791
|
-
if (scene === "group") return {
|
|
792
|
-
chatType: ChatType.GROUP,
|
|
793
|
-
peerUid: String(id)
|
|
794
|
-
};
|
|
795
|
-
const uin = String(id);
|
|
796
|
-
let uid;
|
|
797
|
-
try {
|
|
798
|
-
uid = (await this.uinToUid([uin])).get(uin);
|
|
799
|
-
} catch (err) {
|
|
800
|
-
this.logger?.warn({
|
|
801
|
-
uin,
|
|
802
|
-
error: err instanceof Error ? err.message : String(err)
|
|
803
|
-
}, "milky: uin→uid 转换失败,peer 退用 uin 原样");
|
|
804
|
-
}
|
|
805
|
-
return {
|
|
806
|
-
chatType: scene === "friend" ? ChatType.C2C : ChatType.C2C_TEMP,
|
|
807
|
-
peerUid: uid ?? uin
|
|
808
|
-
};
|
|
809
|
-
}
|
|
810
|
-
/**
|
|
811
|
-
* seq → msgId(索引优先,未登记扫描近段历史兜底)。
|
|
812
|
-
* 两层都未命中返回 undefined(调用方抛 NOT_FOUND)。
|
|
813
|
-
*/
|
|
814
|
-
async resolveMsgIdBySeq(peer, seq, chatType) {
|
|
815
|
-
const indexed = this.seqIndex.resolveMsgId(chatType, peer.peerUid, seq);
|
|
816
|
-
if (indexed !== void 0) return indexed;
|
|
817
|
-
const hit = (await this.msgApi.fetchMessages(peer, { count: 60 }).catch((err) => {
|
|
818
|
-
this.logger?.debug({
|
|
819
|
-
peer: peer.peerUid,
|
|
820
|
-
seq,
|
|
821
|
-
error: err instanceof Error ? err.message : String(err)
|
|
822
|
-
}, "milky: msgSeq 反查近段历史失败");
|
|
823
|
-
return [];
|
|
824
|
-
})).find((m) => Number(m.msgSeq) === seq);
|
|
825
|
-
if (hit === void 0) return;
|
|
826
|
-
this.seqIndex.record(hit);
|
|
827
|
-
return hit.msgId;
|
|
828
|
-
}
|
|
829
|
-
/** 发送结果回查:msgId → {message_seq, time}(sendMessage 只回 msgId)。 */
|
|
830
|
-
async resolveSentOutput(peer, msgId) {
|
|
831
|
-
const [sent] = await this.msgApi.fetchMsgsByMsgId(peer, [msgId]);
|
|
832
|
-
if (sent === void 0) throw kernelError("发送结果回查失败(msgId 未命中)", "UNKNOWN");
|
|
833
|
-
this.seqIndex.record(sent);
|
|
834
|
-
return {
|
|
835
|
-
message_seq: Number(sent.msgSeq),
|
|
836
|
-
time: toUnixSeconds(sent.msgTime)
|
|
837
|
-
};
|
|
838
|
-
}
|
|
839
|
-
};
|
|
840
|
-
/** 通知查找默认搜索数量(单屏全量,OB11 DEFAULT_COUNT 同值)。 */
|
|
841
|
-
const NOTIFY_SEARCH_COUNT$1 = 100;
|
|
842
|
-
/**
|
|
843
|
-
* 按通知 seq 查找群通知(先非可疑后可疑两屏依序,OB11 set_group_add_request
|
|
844
|
-
* 同路径)。屏序惰性拉取:前一屏命中则不拉后续屏(群通知规范序)。
|
|
845
|
-
* 未找到抛 NOT_FOUND(应答动作的 seq 无效或已过期)。
|
|
846
|
-
* 模块级函数(非类成员):应答动作的公共入口,OB11 同路径。
|
|
847
|
-
*/
|
|
848
|
-
async function findGroupNotify(api, seq) {
|
|
849
|
-
const screens = [() => api.groupNotifyApi.getSingleScreenNotifies(false, NOTIFY_SEARCH_COUNT$1), () => api.groupNotifyApi.getSingleScreenNotifies(true, NOTIFY_SEARCH_COUNT$1)];
|
|
850
|
-
for (const fetchScreen of screens) {
|
|
851
|
-
const hit = (await fetchScreen()).find((item) => item.seq === seq);
|
|
852
|
-
if (hit !== void 0) return hit;
|
|
853
|
-
}
|
|
854
|
-
throw kernelError(`未找到通知 ${seq}(无效或已过期)`, "NOT_FOUND");
|
|
855
|
-
}
|
|
856
|
-
/** 按发起者 uid 查找好友申请(getBuddyReqList 匹配 friendUid);未找到抛 NOT_FOUND。 */
|
|
857
|
-
async function findBuddyReq(api, initiatorUid) {
|
|
858
|
-
const hit = (await api.friendApi.getBuddyReqList()).find((req) => req.friendUid === initiatorUid);
|
|
859
|
-
if (hit === void 0) throw kernelError(`未找到来自 ${initiatorUid} 的好友申请`, "NOT_FOUND");
|
|
860
|
-
return hit;
|
|
861
|
-
}
|
|
862
849
|
// src/milky/helper/event/request.ts
|
|
863
850
|
/**
|
|
864
851
|
* BuddyReq → friend_request 事件。
|
|
@@ -934,9 +921,6 @@ function collectNotifyUids(notifies) {
|
|
|
934
921
|
return [...uids];
|
|
935
922
|
}
|
|
936
923
|
// src/milky/action/group-notice.ts
|
|
937
|
-
const optStr = z.string().nullable().optional();
|
|
938
|
-
/** 通知查找数量(单屏全量,OB11 DEFAULT_COUNT 同值)。 */
|
|
939
|
-
const NOTIFY_SEARCH_COUNT = 100;
|
|
940
924
|
/** get_group_notifications 默认 limit(规范 default 20)。 */
|
|
941
925
|
const NOTIFICATIONS_DEFAULT_LIMIT = 20;
|
|
942
926
|
/** 群通知域动作工厂(通知列表 + 应答四动作)。 */
|
|
@@ -946,14 +930,14 @@ function createGroupNoticeActions(api) {
|
|
|
946
930
|
name: "get_group_notifications",
|
|
947
931
|
schema: z.object({
|
|
948
932
|
start_notification_seq: z.number().int().min(0).nullable().optional(),
|
|
949
|
-
is_filtered: optBool
|
|
933
|
+
is_filtered: optBool,
|
|
950
934
|
limit: z.number().int().min(0).nullable().optional()
|
|
951
935
|
}),
|
|
952
936
|
handle: async (payload) => {
|
|
953
|
-
const notifies = await api.groupNotifyApi.getSingleScreenNotifies(payload.is_filtered === true,
|
|
937
|
+
const notifies = await api.groupNotifyApi.getSingleScreenNotifies(payload.is_filtered === true, 100);
|
|
954
938
|
const start = payload.start_notification_seq;
|
|
955
939
|
const filtered = notifies.filter((n) => start === void 0 || start === null || Number(n.seq) < start);
|
|
956
|
-
const uidToUin = await
|
|
940
|
+
const uidToUin = await collectNotifyUidToUin(api, filtered);
|
|
957
941
|
const entities = filtered.map((n) => notifyToEntity(n, payload.is_filtered === true, uidToUin)).filter((e) => e !== null);
|
|
958
942
|
const limit = payload.limit ?? NOTIFICATIONS_DEFAULT_LIMIT;
|
|
959
943
|
const page = entities.slice(0, limit);
|
|
@@ -991,14 +975,14 @@ const respondRequestSchema = z.object({
|
|
|
991
975
|
notification_seq: z.number().int().min(0),
|
|
992
976
|
notification_type: z.enum(["join_request", "invited_join_request"]),
|
|
993
977
|
...groupIdField,
|
|
994
|
-
is_filtered: optBool
|
|
978
|
+
is_filtered: optBool
|
|
995
979
|
});
|
|
996
980
|
/** reject_group_request 入参(reason 无源)。 */
|
|
997
981
|
const rejectRequestSchema = z.object({
|
|
998
982
|
notification_seq: z.number().int().min(0),
|
|
999
983
|
notification_type: z.enum(["join_request", "invited_join_request"]),
|
|
1000
984
|
...groupIdField,
|
|
1001
|
-
is_filtered: optBool
|
|
985
|
+
is_filtered: optBool,
|
|
1002
986
|
reason: optStr
|
|
1003
987
|
});
|
|
1004
988
|
/** accept/reject_group_invitation 入参。 */
|
|
@@ -1013,13 +997,13 @@ async function respondGroupNotify(api, seq, doubt, approve) {
|
|
|
1013
997
|
return {};
|
|
1014
998
|
}
|
|
1015
999
|
/** 通知 user1/user2 uid → uin 批量转换(失败退空 Map,实体 id 兜底 0)。 */
|
|
1016
|
-
async function
|
|
1000
|
+
async function collectNotifyUidToUin(api, notifies) {
|
|
1017
1001
|
const uids = collectNotifyUids(notifies);
|
|
1018
1002
|
if (uids.length === 0) return /* @__PURE__ */ new Map();
|
|
1019
1003
|
return await api.uidToUin(uids).catch((err) => {
|
|
1020
1004
|
api.logger?.warn({
|
|
1021
1005
|
count: uids.length,
|
|
1022
|
-
error:
|
|
1006
|
+
error: errorMessage(err)
|
|
1023
1007
|
}, "milky: 通知 uid→uin 失败,实体 id 兜底 0");
|
|
1024
1008
|
return /* @__PURE__ */ new Map();
|
|
1025
1009
|
});
|
|
@@ -1092,17 +1076,6 @@ function notifyToEntity(notify, isFiltered, uidToUin) {
|
|
|
1092
1076
|
return entity;
|
|
1093
1077
|
}
|
|
1094
1078
|
// src/milky/helper/message/segments.ts
|
|
1095
|
-
/**
|
|
1096
|
-
* Milky 消息段 ↔ canonical 元素转换(纯函数)
|
|
1097
|
-
*
|
|
1098
|
-
* 接收方向:canonical → IncomingSegment(规范 14 种中映射 12 种;market_face /
|
|
1099
|
-
* markdown 无 canonical 对应(MFACE/MARKDOWN 原始元素形状未探测),unknown 一律
|
|
1100
|
-
* 跳过——规范兼容性要求「数组中未知项跳过」)。forward 接收段不经 canonical:
|
|
1101
|
-
* kernel 无 MULTI_FORWARD 分支,adapter 从 RawMessage 提取 resId 后经
|
|
1102
|
-
* incomingForwardSegment + ctx 注入。
|
|
1103
|
-
* 发送方向:OutgoingSegment → canonical(10 种全映射;forward 顶层段不走本转换器,
|
|
1104
|
-
* 由 sendMilkyMessage 分流到组装链——本转换器内 forward 报错只拦截混发/嵌套)。
|
|
1105
|
-
*/
|
|
1106
1079
|
/** uin 字符串 → Milky user_id(非有限正数 = 转换失败)。 */
|
|
1107
1080
|
function toUserId(uin) {
|
|
1108
1081
|
const n = Number(uin);
|
|
@@ -1360,16 +1333,6 @@ function resolveUriToPathPlaceholder(uri) {
|
|
|
1360
1333
|
if (uri.startsWith("http://") || uri.startsWith("https://") || uri.startsWith("base64://")) return uri;
|
|
1361
1334
|
return uri;
|
|
1362
1335
|
}
|
|
1363
|
-
/** file:// 前缀(fileURLToPath 失败时的裸剥离兜底)。 */
|
|
1364
|
-
const FILE_URI_PREFIX_RE = /^file:\/\//;
|
|
1365
|
-
/** file:// URI → 平台路径(Windows 盘符兼容)。 */
|
|
1366
|
-
function fileUriToPath(uri) {
|
|
1367
|
-
try {
|
|
1368
|
-
return fileURLToPath(uri);
|
|
1369
|
-
} catch {
|
|
1370
|
-
return uri.replace(FILE_URI_PREFIX_RE, "");
|
|
1371
|
-
}
|
|
1372
|
-
}
|
|
1373
1336
|
// src/milky/helper/event/translate.ts
|
|
1374
1337
|
/**
|
|
1375
1338
|
* Milky 事件翻译(RawMessage → Milky 事件,纯函数)
|
|
@@ -1545,7 +1508,7 @@ function createMessageQueryActions(api) {
|
|
|
1545
1508
|
};
|
|
1546
1509
|
const msgs = await api.msgApi.fetchForwardMessage(peer, entry.msgId);
|
|
1547
1510
|
for (const m of msgs) api.seqIndex.record(m);
|
|
1548
|
-
const uidToUin = await
|
|
1511
|
+
const uidToUin = await collectAtUidToUin(api, msgs);
|
|
1549
1512
|
const messages = [];
|
|
1550
1513
|
for (const m of msgs) messages.push({
|
|
1551
1514
|
message_seq: Number(m.msgSeq),
|
|
@@ -1567,13 +1530,13 @@ async function translateWithEntities(api, scene, peer, msg) {
|
|
|
1567
1530
|
const [detail, member] = await Promise.all([api.groupCache?.getGroupDetail(peer.peerUid).catch((err) => {
|
|
1568
1531
|
api.logger?.warn({
|
|
1569
1532
|
group: peer.peerUid,
|
|
1570
|
-
error:
|
|
1533
|
+
error: errorMessage(err)
|
|
1571
1534
|
}, "milky: 群详情缓存读取失败,实体回填退化");
|
|
1572
1535
|
}), api.groupCache?.getMember(peer.peerUid, msg.senderUid).catch((err) => {
|
|
1573
1536
|
api.logger?.debug({
|
|
1574
1537
|
group: peer.peerUid,
|
|
1575
1538
|
member: msg.senderUid,
|
|
1576
|
-
error:
|
|
1539
|
+
error: errorMessage(err)
|
|
1577
1540
|
}, "milky: 群成员缓存读取失败,实体回填退化");
|
|
1578
1541
|
})]);
|
|
1579
1542
|
ctx.groupEntity = toGroupEntity(detail, peer.peerUid);
|
|
@@ -1597,12 +1560,12 @@ async function loadGroupData(api, groupCode) {
|
|
|
1597
1560
|
const [detail, members] = await Promise.all([api.groupCache.getGroupDetail(groupCode).catch((err) => {
|
|
1598
1561
|
api.logger?.warn({
|
|
1599
1562
|
group: groupCode,
|
|
1600
|
-
error:
|
|
1563
|
+
error: errorMessage(err)
|
|
1601
1564
|
}, "milky: 群详情缓存读取失败,历史翻译退化");
|
|
1602
1565
|
}), api.groupCache.getMembers(groupCode).catch((err) => {
|
|
1603
1566
|
api.logger?.warn({
|
|
1604
1567
|
group: groupCode,
|
|
1605
|
-
error:
|
|
1568
|
+
error: errorMessage(err)
|
|
1606
1569
|
}, "milky: 群成员表缓存读取失败,历史翻译退化");
|
|
1607
1570
|
return [];
|
|
1608
1571
|
})]);
|
|
@@ -1624,14 +1587,14 @@ function translateHistoryMessage(api, msg, peerUid, groupData) {
|
|
|
1624
1587
|
return toMessageReceiveEvent(msg, ctx).data;
|
|
1625
1588
|
}
|
|
1626
1589
|
/** at 段 uid → uin 批量转换(mention 翻译;失败退空 Map)。 */
|
|
1627
|
-
async function
|
|
1590
|
+
async function collectAtUidToUin(api, msgs) {
|
|
1628
1591
|
const uids = /* @__PURE__ */ new Set();
|
|
1629
1592
|
for (const m of msgs) for (const el of toCanonicalElements(m)) if (el.type === "at" && el.target !== "all") uids.add(el.target);
|
|
1630
1593
|
if (uids.size === 0) return /* @__PURE__ */ new Map();
|
|
1631
1594
|
return await api.uidToUin([...uids]).catch((err) => {
|
|
1632
1595
|
api.logger?.warn({
|
|
1633
1596
|
count: uids.size,
|
|
1634
|
-
error:
|
|
1597
|
+
error: errorMessage(err)
|
|
1635
1598
|
}, "milky: 历史 at uid→uin 失败,mention 段跳过");
|
|
1636
1599
|
return /* @__PURE__ */ new Map();
|
|
1637
1600
|
});
|
|
@@ -1643,7 +1606,7 @@ async function senderNameOf(api, msg) {
|
|
|
1643
1606
|
api.logger?.debug({
|
|
1644
1607
|
group: msg.peerUid,
|
|
1645
1608
|
member: msg.senderUid,
|
|
1646
|
-
error:
|
|
1609
|
+
error: errorMessage(err)
|
|
1647
1610
|
}, "milky: 发送者成员缓存读取失败,退 uin 字符串");
|
|
1648
1611
|
});
|
|
1649
1612
|
const name = member?.cardName !== void 0 && member.cardName !== "" ? member.cardName : member?.nick;
|
|
@@ -1826,7 +1789,7 @@ async function recallTempMessages(peer, msgIds, api) {
|
|
|
1826
1789
|
api.logger?.warn({
|
|
1827
1790
|
peer: peer.peerUid,
|
|
1828
1791
|
count: msgIds.length,
|
|
1829
|
-
error:
|
|
1792
|
+
error: errorMessage(e)
|
|
1830
1793
|
}, "milky: forward 临时消息撤回失败(转发已发出)");
|
|
1831
1794
|
}
|
|
1832
1795
|
}
|
|
@@ -1846,7 +1809,7 @@ async function resolveAtUins(atUins, api) {
|
|
|
1846
1809
|
} catch (err) {
|
|
1847
1810
|
api.logger?.warn({
|
|
1848
1811
|
count: atUins.length,
|
|
1849
|
-
error:
|
|
1812
|
+
error: errorMessage(err)
|
|
1850
1813
|
}, "milky: at uin→uid 失败,at 段原样发送");
|
|
1851
1814
|
return;
|
|
1852
1815
|
}
|
|
@@ -1960,8 +1923,6 @@ function createProfileActions(api) {
|
|
|
1960
1923
|
];
|
|
1961
1924
|
}
|
|
1962
1925
|
// src/milky/action/social.ts
|
|
1963
|
-
/** 可选布尔(nudge / pin 入参共用口径)。 */
|
|
1964
|
-
const optBool = z.boolean().nullable().optional();
|
|
1965
1926
|
/** 社交类动作工厂(好友/群列表、赞、删好友、申请处理、戳一戳、会话置顶)。 */
|
|
1966
1927
|
function createSocialActions(api) {
|
|
1967
1928
|
return [
|
|
@@ -2012,7 +1973,7 @@ function createSocialActions(api) {
|
|
|
2012
1973
|
if (reqs.length > 0) uidToUin = await api.uidToUin(reqs.map((req) => req.friendUid)).catch((err) => {
|
|
2013
1974
|
api.logger?.warn({
|
|
2014
1975
|
count: reqs.length,
|
|
2015
|
-
error:
|
|
1976
|
+
error: errorMessage(err)
|
|
2016
1977
|
}, "milky: 好友申请 uid→uin 失败,initiator_id 兜底 0");
|
|
2017
1978
|
return /* @__PURE__ */ new Map();
|
|
2018
1979
|
});
|
|
@@ -2124,12 +2085,6 @@ async function pinnedGroupEntities(api, groupCodes) {
|
|
|
2124
2085
|
return g !== void 0 ? [groupListToEntity(g)] : [];
|
|
2125
2086
|
});
|
|
2126
2087
|
}
|
|
2127
|
-
/** self.uid 必备(nudge 发送的 callerUid)。 */
|
|
2128
|
-
function requireSelfUid(api) {
|
|
2129
|
-
const uid = api.self.uid;
|
|
2130
|
-
if (uid === void 0 || uid === "") throw kernelError("登录身份缺 uid(无法发起戳一戳)", "INVALID_PARAM");
|
|
2131
|
-
return uid;
|
|
2132
|
-
}
|
|
2133
2088
|
// src/milky/action/system.ts
|
|
2134
2089
|
/**
|
|
2135
2090
|
* Milky 系统类动作:get_login_info / get_impl_info
|
|
@@ -2209,7 +2164,7 @@ var MilkyEnrichment = class {
|
|
|
2209
2164
|
const map = await this.api.uidToUin(unique).catch((err) => {
|
|
2210
2165
|
this.api.logger?.warn({
|
|
2211
2166
|
count: unique.length,
|
|
2212
|
-
error:
|
|
2167
|
+
error: errorMessage(err)
|
|
2213
2168
|
}, "milky: uid→uin 批量转换失败,事件退用 uid");
|
|
2214
2169
|
return /* @__PURE__ */ new Map();
|
|
2215
2170
|
});
|
|
@@ -2227,7 +2182,7 @@ var MilkyEnrichment = class {
|
|
|
2227
2182
|
const uin = await this.api.profileApi.getUinByUid(uid);
|
|
2228
2183
|
if (uin !== null) map.set(uid, uin);
|
|
2229
2184
|
} catch (err) {
|
|
2230
|
-
this.api.logger?.debug({ error:
|
|
2185
|
+
this.api.logger?.debug({ error: errorMessage(err) }, "milky: uid→uin 资料兜底失败(该 uid 退 0)");
|
|
2231
2186
|
}
|
|
2232
2187
|
if (missing.length > MAX_PROFILE_LOOKUPS) this.api.logger?.debug({
|
|
2233
2188
|
missing: missing.length,
|
|
@@ -2243,7 +2198,7 @@ var MilkyEnrichment = class {
|
|
|
2243
2198
|
} catch (err) {
|
|
2244
2199
|
this.api.logger?.warn({
|
|
2245
2200
|
count: atUids.length,
|
|
2246
|
-
error:
|
|
2201
|
+
error: errorMessage(err)
|
|
2247
2202
|
}, "milky: at uid→uin 失败,mention 段跳过");
|
|
2248
2203
|
}
|
|
2249
2204
|
}
|
|
@@ -2253,13 +2208,13 @@ var MilkyEnrichment = class {
|
|
|
2253
2208
|
const [detail, member] = await Promise.all([this.api.groupCache.getGroupDetail(msg.peerUid).catch((err) => {
|
|
2254
2209
|
this.api.logger?.warn({
|
|
2255
2210
|
group: msg.peerUid,
|
|
2256
|
-
error:
|
|
2211
|
+
error: errorMessage(err)
|
|
2257
2212
|
}, "milky: 群详情缓存读取失败,实体回填退化");
|
|
2258
2213
|
}), this.api.groupCache.getMember(msg.peerUid, msg.senderUid).catch((err) => {
|
|
2259
2214
|
this.api.logger?.debug({
|
|
2260
2215
|
group: msg.peerUid,
|
|
2261
2216
|
member: msg.senderUid,
|
|
2262
|
-
error:
|
|
2217
|
+
error: errorMessage(err)
|
|
2263
2218
|
}, "milky: 群成员缓存读取失败,实体回填退化");
|
|
2264
2219
|
})]);
|
|
2265
2220
|
ctx.groupEntity = toGroupEntity(detail, msg.peerUid);
|
|
@@ -2765,8 +2720,6 @@ var MilkyInboundMessage = class {
|
|
|
2765
2720
|
* {chatType, peerUin, topFlag(1/0), topFlagTime(秒级 unix 字符串)},与操作
|
|
2766
2721
|
* 一一对应(milky.md §0.8.6)。
|
|
2767
2722
|
*/
|
|
2768
|
-
/** uin 形判别(peer_id 必须是数字串)。 */
|
|
2769
|
-
const NUMERIC_RE$1 = /^\d+$/;
|
|
2770
2723
|
/** 置顶翻转检测(每适配器实例一份,键 = chatType:peerUin——群号与 uin 数值空间可重叠)。 */
|
|
2771
2724
|
var PinWatch = class {
|
|
2772
2725
|
states = /* @__PURE__ */ new Map();
|
|
@@ -2800,7 +2753,7 @@ function toPeerPinChangeData(entry) {
|
|
|
2800
2753
|
const scene = pinScene(entry.chatType);
|
|
2801
2754
|
if (scene === null || entry.topFlag === void 0) return null;
|
|
2802
2755
|
const peerUin = typeof entry.peerUin === "string" && entry.peerUin !== "" ? entry.peerUin : scene === "group" ? entry.peerUid : "";
|
|
2803
|
-
if (peerUin === "" || !NUMERIC_RE
|
|
2756
|
+
if (peerUin === "" || !NUMERIC_RE.test(peerUin)) return null;
|
|
2804
2757
|
return {
|
|
2805
2758
|
data: {
|
|
2806
2759
|
message_scene: scene,
|
|
@@ -2944,8 +2897,6 @@ var MilkyInboundRequest = class {
|
|
|
2944
2897
|
* (remove 走 onGroupEssenceListChange 列表 diff,shared/essence.ts)。
|
|
2945
2898
|
* - 528:349/381/382 多端设备同步族:不广播。
|
|
2946
2899
|
*/
|
|
2947
|
-
/** 数字串判别(faceId 实证为数字字符串)。 */
|
|
2948
|
-
const NUMERIC_RE = /^\d+$/;
|
|
2949
2900
|
/** 732:16 → group_message_reaction。 */
|
|
2950
2901
|
const REACTION_RULE = {
|
|
2951
2902
|
kind: "group_message_reaction",
|
|
@@ -3008,15 +2959,9 @@ const KIND_TABLE = /* @__PURE__ */ new Map([["732:16", REACTION_RULE], ["732:1",
|
|
|
3008
2959
|
};
|
|
3009
2960
|
}
|
|
3010
2961
|
}]]);
|
|
3011
|
-
/** 已观测但未命名的键(多端设备同步族等,不广播只走校准日志)。 */
|
|
3012
|
-
const OBSERVED_UNNAMED = /* @__PURE__ */ new Set([
|
|
3013
|
-
"528:382",
|
|
3014
|
-
"528:349",
|
|
3015
|
-
"528:381"
|
|
3016
|
-
]);
|
|
3017
2962
|
/** (msgType, subType) → 识别结果(绑定 Milky 表;table 参数供单测注入)。 */
|
|
3018
2963
|
function recognizeMilkySysMsg(msgType, subType, table = KIND_TABLE) {
|
|
3019
|
-
return recognizeSysMsg(msgType, subType, table,
|
|
2964
|
+
return recognizeSysMsg(msgType, subType, table, OBSERVED_UNNAMED_SYSMSG_KEYS);
|
|
3020
2965
|
}
|
|
3021
2966
|
// src/milky/inbound/sysmsg.ts
|
|
3022
2967
|
/**
|
|
@@ -3065,6 +3010,19 @@ var MilkyInboundSysMsg = class {
|
|
|
3065
3010
|
}
|
|
3066
3011
|
};
|
|
3067
3012
|
// src/milky/transport.ts
|
|
3013
|
+
/**
|
|
3014
|
+
* Milky 传输装配(单端口 HTTP:POST /api/:api + GET /event SSE + /event WS 升级
|
|
3015
|
+
* + WebHook 主动推送,docs/protocols/milky.md §4)
|
|
3016
|
+
*
|
|
3017
|
+
* - HTTP API:HttpServer onPathRequest 分发 → 动作注册表 → 规范响应信封
|
|
3018
|
+
* (200 ok / 200 failed(-400/-403/自定) / 401 鉴权 / 404 API 不存在(空 body)/
|
|
3019
|
+
* 415 Content-Type)。
|
|
3020
|
+
* - /event:onRawRequest 承接 SSE(createSseResponse,event: milky_event);
|
|
3021
|
+
* onUpgrade 承接同端口 WS 升级(网络原语 下沉 network)。
|
|
3022
|
+
* - WebHook:HttpClient(fire-and-forget POST,Authorization 头带 token)。
|
|
3023
|
+
*
|
|
3024
|
+
* 事件推送统一经 MilkyEventHub(注册到 EventBroadcaster,send → SSE/WS 客户端)。
|
|
3025
|
+
*/
|
|
3068
3026
|
/** /event 路径(规范固定)。 */
|
|
3069
3027
|
const EVENT_PATH = "/event";
|
|
3070
3028
|
/** /api/ 前缀 + 动作名(小写字母开头,小写/数字/下划线)。 */
|
|
@@ -3203,7 +3161,7 @@ function handleMilkyHttpRequest(ctx, req, respond, registry, logger) {
|
|
|
3203
3161
|
}).catch((err) => {
|
|
3204
3162
|
logger?.warn({
|
|
3205
3163
|
path: ctx.path,
|
|
3206
|
-
error:
|
|
3164
|
+
error: errorMessage(err)
|
|
3207
3165
|
}, "milky: 动作分发异常,已回 -500");
|
|
3208
3166
|
respond({
|
|
3209
3167
|
status: "failed",
|
|
@@ -3226,7 +3184,7 @@ function tokenMatches(ctx, token, logger) {
|
|
|
3226
3184
|
} catch (err) {
|
|
3227
3185
|
logger?.debug({
|
|
3228
3186
|
url: ctx.url,
|
|
3229
|
-
error:
|
|
3187
|
+
error: errorMessage(err)
|
|
3230
3188
|
}, "milky: 鉴权 URL 解析失败,按未授权拒绝");
|
|
3231
3189
|
return false;
|
|
3232
3190
|
}
|