@napuketto/adapter 0.15.4 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/core/index.d.mts +8 -3
- package/dist/core/index.mjs +1 -1
- package/dist/core-Byoso-c3.mjs +108 -0
- package/dist/core-Byoso-c3.mjs.map +1 -0
- package/dist/{core-DOyFBFOW.mjs → essence-CYb60NC6.mjs} +164 -260
- package/dist/essence-CYb60NC6.mjs.map +1 -0
- package/dist/{gray-tip-C0pnbB__.mjs → gray-tip-C7lAbfOf.mjs} +10 -10
- package/dist/gray-tip-C7lAbfOf.mjs.map +1 -0
- package/dist/index-RMEWjNfV.d.mts +91 -0
- package/dist/index-RMEWjNfV.d.mts.map +1 -0
- package/dist/kurobot/index.d.mts +6 -6
- package/dist/kurobot/index.d.mts.map +1 -1
- package/dist/kurobot/index.mjs +10 -10
- package/dist/kurobot/index.mjs.map +1 -1
- package/dist/media-DMMn74TC.mjs +126 -0
- package/dist/media-DMMn74TC.mjs.map +1 -0
- package/dist/milky/index.d.mts +19 -22
- package/dist/milky/index.d.mts.map +1 -1
- package/dist/milky/index.mjs +1240 -1357
- package/dist/milky/index.mjs.map +1 -1
- package/dist/onebot11/index.d.mts +45 -21
- package/dist/onebot11/index.d.mts.map +1 -1
- package/dist/onebot11/index.mjs +1221 -1865
- package/dist/onebot11/index.mjs.map +1 -1
- package/dist/{raw-message-D2vA27kj.mjs → raw-message-DE3sdJg8.mjs} +18 -4
- package/dist/raw-message-DE3sdJg8.mjs.map +1 -0
- package/dist/satori/index.d.mts +24 -37
- package/dist/satori/index.d.mts.map +1 -1
- package/dist/satori/index.mjs +396 -564
- package/dist/satori/index.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/core-DOyFBFOW.mjs.map +0 -1
- package/dist/gray-tip-C0pnbB__.mjs.map +0 -1
- package/dist/index-BbHwULNm.d.mts +0 -269
- package/dist/index-BbHwULNm.d.mts.map +0 -1
- package/dist/log-DYEB3Eto.mjs +0 -176
- package/dist/log-DYEB3Eto.mjs.map +0 -1
- package/dist/lookup-Dw0W04Ng.mjs +0 -22
- package/dist/lookup-Dw0W04Ng.mjs.map +0 -1
- package/dist/raw-message-D2vA27kj.mjs.map +0 -1
- package/dist/transport-schema-BEzr06W3.mjs +0 -29
- package/dist/transport-schema-BEzr06W3.mjs.map +0 -1
package/dist/milky/index.mjs
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as
|
|
3
|
-
import { a as
|
|
4
|
-
import { r as subscribeRawMessages, t as forEachRawMessage } from "../raw-message-
|
|
5
|
-
import { a as narrowEssenceGroupArg, i as extractEssenceSetSysMsg, o as narrowBuddyReqs, r as EssenceListSync, t as sliceRaw } from "../log-DYEB3Eto.mjs";
|
|
1
|
+
import { i as runAction, n as BaseProtocolAdapter, r as ActionRegistry } from "../core-Byoso-c3.mjs";
|
|
2
|
+
import { a as MS_TO_SEC$2, c as toUin, i as hasGrayTip, n as findRevokeElement, o as numericUin, r as firstUntranslatedGrayTip, s as resolveUin, t as collectGrayTipUids } from "../gray-tip-C7lAbfOf.mjs";
|
|
3
|
+
import { a as nodeAt, c as textOf, d as logEventFailure, f as sliceRaw, i as narrowSysMsgBlobs, l as varintAt, m as narrowBuddyReqs, n as extractEssenceSetSysMsg, o as processSysMsgBlob, r as narrowEssenceGroupArg, s as recognizeSysMsg, t as EssenceListSync, u as varintOf } from "../essence-CYb60NC6.mjs";
|
|
4
|
+
import { r as subscribeRawMessages, t as forEachRawMessage } from "../raw-message-DE3sdJg8.mjs";
|
|
6
5
|
import { ChatType, GrayTipSubType, GroupApi, GroupNotifyMsgStatus, GroupNotifyMsgType, NTGroupRequestOperateTypes, TicketApi, TipGroupElementType, kernelError, toCanonicalElements } from "@napuketto/kernel";
|
|
7
|
-
import { mkdir, rename, writeFile } from "node:fs/promises";
|
|
8
|
-
import { join } from "node:path";
|
|
9
|
-
import { detectFileType, downloadUrl, inferExtension } from "@napuketto/media";
|
|
10
6
|
import { z } from "zod";
|
|
11
7
|
import { randomUUID } from "node:crypto";
|
|
8
|
+
import { join } from "node:path";
|
|
9
|
+
import { detectFileType, downloadUrl, inferExtension } from "@napuketto/media";
|
|
10
|
+
import { mkdir, rename, writeFile } from "node:fs/promises";
|
|
12
11
|
import { fileURLToPath } from "node:url";
|
|
13
12
|
import { HttpClient, HttpServer, createSseResponse, isWsOpen } from "@napuketto/network";
|
|
14
|
-
// src/milky/action/
|
|
13
|
+
// src/milky/action/base-action.ts
|
|
14
|
+
/** KernelErrorCode → Milky retcode 映射表(-400/-403 规范语义,其余取常见 HTTP 语义近似负数)。 */
|
|
15
15
|
const milkyErrorCodeMap = {
|
|
16
16
|
SEND_FAILED: -500,
|
|
17
17
|
PERMISSION_DENIED: -405,
|
|
@@ -22,118 +22,271 @@ const milkyErrorCodeMap = {
|
|
|
22
22
|
INVALID_STATE: -409,
|
|
23
23
|
UNKNOWN: -500
|
|
24
24
|
};
|
|
25
|
-
// src/milky/action/base-action.ts
|
|
26
25
|
/** zod 错误摘要(单行,issues 取前 3 条)。 */
|
|
27
26
|
function zodSummary(error) {
|
|
28
27
|
const parts = [];
|
|
29
28
|
for (const issue of error.issues.slice(0, 3)) parts.push(`${issue.path.map(String).join(".")}: ${issue.message}`);
|
|
30
29
|
return parts.join("; ");
|
|
31
30
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
*/
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
31
|
+
/** 声明式动作工厂:闭包依赖 + 统一信封与错误映射。 */
|
|
32
|
+
function defineMilkyAction(spec) {
|
|
33
|
+
return {
|
|
34
|
+
name: spec.name,
|
|
35
|
+
schema: spec.schema,
|
|
36
|
+
handle: async (payload) => {
|
|
37
|
+
const outcome = await runAction({
|
|
38
|
+
schema: spec.schema,
|
|
39
|
+
handle: spec.handle,
|
|
40
|
+
errorCodeMap: milkyErrorCodeMap,
|
|
41
|
+
invalidRetcode: -400,
|
|
42
|
+
invalidMessage: (error) => `参数解析失败: ${zodSummary(error)}`
|
|
43
|
+
}, payload);
|
|
44
|
+
return outcome.ok ? {
|
|
45
|
+
status: "ok",
|
|
46
|
+
retcode: 0,
|
|
47
|
+
data: outcome.data,
|
|
48
|
+
message: ""
|
|
49
|
+
} : {
|
|
50
|
+
status: "failed",
|
|
51
|
+
retcode: outcome.retcode,
|
|
52
|
+
data: null,
|
|
53
|
+
message: outcome.message
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
// src/milky/helper/message/entities.ts
|
|
59
|
+
/** GroupDetailInfo / Group → GroupEntity(detail 缺失时全兜底)。 */
|
|
60
|
+
function toGroupEntity(detail, groupCode) {
|
|
61
|
+
return {
|
|
62
|
+
group_id: Number(groupCode),
|
|
63
|
+
group_name: detail?.groupName ?? "",
|
|
64
|
+
member_count: detail?.memberNum ?? 0,
|
|
65
|
+
max_member_count: detail?.maxMemberNum ?? 0,
|
|
66
|
+
remark: detail?.remarkName ?? "",
|
|
67
|
+
created_time: detail?.groupCreateTime ?? 0,
|
|
68
|
+
description: "",
|
|
69
|
+
question: "",
|
|
70
|
+
announcement: ""
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/** 群列表项(GroupCache Group)→ GroupEntity。 */
|
|
74
|
+
function groupListToEntity(group) {
|
|
75
|
+
return {
|
|
76
|
+
group_id: Number(group.groupCode),
|
|
77
|
+
group_name: group.groupName,
|
|
78
|
+
member_count: group.memberCount,
|
|
79
|
+
max_member_count: group.maxMember,
|
|
80
|
+
remark: "",
|
|
81
|
+
created_time: 0,
|
|
82
|
+
description: "",
|
|
83
|
+
question: "",
|
|
84
|
+
announcement: ""
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/** GroupMember → GroupMemberEntity(member 缺失时按 uin 兜底最小实体)。 */
|
|
88
|
+
function toGroupMemberEntity(member, groupCode, uin) {
|
|
89
|
+
const shutUpSeconds = member?.shutUpTime ?? 0;
|
|
90
|
+
return {
|
|
91
|
+
user_id: Number(member?.uin !== void 0 && member.uin !== "" ? member.uin : uin),
|
|
92
|
+
nickname: member?.nick ?? "",
|
|
93
|
+
sex: "unknown",
|
|
94
|
+
group_id: Number(groupCode),
|
|
95
|
+
card: member?.cardName ?? "",
|
|
96
|
+
title: member?.memberSpecialTitle ?? "",
|
|
97
|
+
level: 0,
|
|
98
|
+
role: GroupApi.roleToString(member?.role ?? 2),
|
|
99
|
+
join_time: Number(member?.joinTime) || 0,
|
|
100
|
+
last_sent_time: Number(member?.lastSpeakTime) || 0,
|
|
101
|
+
shut_up_end_time: shutUpSeconds > 0 ? Math.floor(Date.now() / 1e3) + shutUpSeconds : null
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
/** Friend → FriendEntity(kernel 无 qid/分类挂载,按最小实体兜底)。 */
|
|
105
|
+
function toFriendEntity(friend, uin, nick) {
|
|
106
|
+
return {
|
|
107
|
+
user_id: Number(friend?.uin !== void 0 && friend.uin !== "" ? friend.uin : uin),
|
|
108
|
+
nickname: friend?.nickname ?? nick,
|
|
109
|
+
sex: "unknown",
|
|
110
|
+
qid: "",
|
|
111
|
+
remark: friend?.remark ?? "",
|
|
112
|
+
category: {
|
|
113
|
+
category_id: 0,
|
|
114
|
+
category_name: ""
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
// src/milky/action/group-query.ts
|
|
119
|
+
/** 群域共入参(群号 / 成员 uin / 可选布尔;群管理 / 通知 / 精华 / 文件域复用)。 */
|
|
120
|
+
const groupIdField = { group_id: z.number().int().min(10001) };
|
|
121
|
+
const userIdField = { user_id: z.number().int().min(10001) };
|
|
122
|
+
const optBool$1 = z.boolean().nullable().optional();
|
|
123
|
+
/** 群查询域动作工厂(群信息 / 成员列表 / 成员单查 / 公告列表)。 */
|
|
124
|
+
function createGroupQueryActions(api) {
|
|
125
|
+
return [
|
|
126
|
+
defineMilkyAction({
|
|
127
|
+
name: "get_group_info",
|
|
128
|
+
schema: z.object({
|
|
129
|
+
...groupIdField,
|
|
130
|
+
no_cache: optBool$1
|
|
131
|
+
}),
|
|
132
|
+
handle: async (payload) => {
|
|
133
|
+
const groupCode = String(payload.group_id);
|
|
134
|
+
return { group: toGroupEntity(api.groupCache !== void 0 ? await api.groupCache.getGroupDetail(groupCode) : await api.groupApi.getGroupInfo(groupCode), groupCode) };
|
|
135
|
+
}
|
|
136
|
+
}),
|
|
137
|
+
defineMilkyAction({
|
|
138
|
+
name: "get_group_member_list",
|
|
139
|
+
schema: z.object({
|
|
140
|
+
...groupIdField,
|
|
141
|
+
no_cache: optBool$1
|
|
142
|
+
}),
|
|
143
|
+
handle: async (payload) => {
|
|
144
|
+
return { members: (await membersOf(api, String(payload.group_id))).map((m) => toGroupMemberEntity(m, String(payload.group_id), m.uin)) };
|
|
145
|
+
}
|
|
146
|
+
}),
|
|
147
|
+
defineMilkyAction({
|
|
148
|
+
name: "get_group_member_info",
|
|
149
|
+
schema: z.object({
|
|
150
|
+
...groupIdField,
|
|
151
|
+
...userIdField,
|
|
152
|
+
no_cache: optBool$1
|
|
153
|
+
}),
|
|
154
|
+
handle: async (payload) => {
|
|
155
|
+
return { member: toGroupMemberEntity(await memberOf(api, payload.group_id, payload.user_id), String(payload.group_id), String(payload.user_id)) };
|
|
156
|
+
}
|
|
157
|
+
}),
|
|
158
|
+
defineMilkyAction({
|
|
159
|
+
name: "get_group_announcements",
|
|
160
|
+
schema: z.object({ ...groupIdField }),
|
|
161
|
+
handle: async (payload) => {
|
|
162
|
+
const groupCode = String(payload.group_id);
|
|
163
|
+
const bulletins = await api.groupApi.getGroupAnnouncements(groupCode);
|
|
164
|
+
return { announcements: await Promise.all(bulletins.map((b) => bulletinToEntity(b, payload.group_id, api))) };
|
|
165
|
+
}
|
|
166
|
+
})
|
|
167
|
+
];
|
|
168
|
+
}
|
|
169
|
+
/** ---------- 内部辅助 ---------- */
|
|
170
|
+
/** 成员列表(GroupCache 优先,未装配直查)。 */
|
|
171
|
+
async function membersOf(api, groupCode) {
|
|
172
|
+
if (api.groupCache !== void 0) return await api.groupCache.getMembers(groupCode);
|
|
173
|
+
return await api.groupApi.getGroupMemberList(groupCode, true);
|
|
174
|
+
}
|
|
175
|
+
/** 成员单查(user_id = uin;缓存路径经 uid,直查路径按 uin 匹配)。 */
|
|
176
|
+
async function memberOf(api, groupId, userId) {
|
|
177
|
+
const groupCode = String(groupId);
|
|
178
|
+
const uin = String(userId);
|
|
179
|
+
if (api.groupCache !== void 0) {
|
|
180
|
+
const uid = await api.resolveUidFromUin(userId).catch((err) => {
|
|
181
|
+
api.logger?.debug({
|
|
182
|
+
group: groupCode,
|
|
183
|
+
uin,
|
|
184
|
+
error: err instanceof Error ? err.message : String(err)
|
|
185
|
+
}, "milky: 成员 uin→uid 失败,退用 uin 查缓存");
|
|
186
|
+
return uin;
|
|
133
187
|
});
|
|
134
|
-
|
|
188
|
+
const member = await api.groupCache.getMember(groupCode, uid);
|
|
189
|
+
if (member === void 0) throw kernelError(`成员 ${uin} 不在群 ${groupCode}`, "NOT_FOUND");
|
|
190
|
+
return member;
|
|
135
191
|
}
|
|
136
|
-
|
|
192
|
+
const hit = (await api.groupApi.getGroupMemberList(groupCode, true)).find((m) => m.uin === uin);
|
|
193
|
+
if (hit === void 0) throw kernelError(`成员 ${uin} 不在群 ${groupCode}`, "NOT_FOUND");
|
|
194
|
+
return hit;
|
|
195
|
+
}
|
|
196
|
+
/** GroupBulletin → 群公告实体(senderUid → uin 反查;无源字段兜底,待校准)。 */
|
|
197
|
+
async function bulletinToEntity(b, groupId, api) {
|
|
198
|
+
return {
|
|
199
|
+
group_id: groupId,
|
|
200
|
+
announcement_id: b.announcementId ?? "",
|
|
201
|
+
user_id: await senderUinOf(b, api),
|
|
202
|
+
time: Number(b.publishTime) || 0,
|
|
203
|
+
content: b.content ?? "",
|
|
204
|
+
image_url: picUrlOf(b)
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
/** 公告发送者 uid → uin(缺省/转换失败 0 兜底)。 */
|
|
208
|
+
async function senderUinOf(b, api) {
|
|
209
|
+
const uid = b.senderUid;
|
|
210
|
+
if (typeof uid !== "string" || uid === "") return 0;
|
|
211
|
+
const uins = await api.uidToUin([uid]).catch((err) => {
|
|
212
|
+
api.logger?.debug({
|
|
213
|
+
uid,
|
|
214
|
+
error: err instanceof Error ? err.message : String(err)
|
|
215
|
+
}, "milky: 公告发送者 uid→uin 失败,兜底 0");
|
|
216
|
+
});
|
|
217
|
+
return Number(uins?.get(uid)) || 0;
|
|
218
|
+
}
|
|
219
|
+
/** 公告图片 url(缺省 null)。 */
|
|
220
|
+
function picUrlOf(b) {
|
|
221
|
+
const url = b.pic?.url;
|
|
222
|
+
return typeof url === "string" && url !== "" ? url : null;
|
|
223
|
+
}
|
|
224
|
+
// src/milky/action/group-essence.ts
|
|
225
|
+
/** 群精华与表态域动作工厂。 */
|
|
226
|
+
function createGroupEssenceActions(api) {
|
|
227
|
+
return [
|
|
228
|
+
defineMilkyAction({
|
|
229
|
+
name: "get_group_essence_messages",
|
|
230
|
+
schema: z.object({
|
|
231
|
+
...groupIdField,
|
|
232
|
+
page_index: z.number().int().min(0),
|
|
233
|
+
page_size: z.number().int().min(0)
|
|
234
|
+
}),
|
|
235
|
+
handle: async (payload) => {
|
|
236
|
+
const items = await api.webApi.getEssenceMsgList(String(payload.group_id));
|
|
237
|
+
const start = payload.page_index * payload.page_size;
|
|
238
|
+
const page = items.slice(start, start + payload.page_size);
|
|
239
|
+
return {
|
|
240
|
+
messages: page.map((item) => essenceToEntity(item, payload.group_id)),
|
|
241
|
+
is_end: start + page.length >= items.length
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
}),
|
|
245
|
+
defineMilkyAction({
|
|
246
|
+
name: "set_group_essence_message",
|
|
247
|
+
schema: z.object({
|
|
248
|
+
...groupIdField,
|
|
249
|
+
message_seq: z.number().int().min(0),
|
|
250
|
+
is_set: optBool$1
|
|
251
|
+
}),
|
|
252
|
+
handle: async (payload) => {
|
|
253
|
+
const groupCode = String(payload.group_id);
|
|
254
|
+
const peer = {
|
|
255
|
+
chatType: ChatType.GROUP,
|
|
256
|
+
peerUid: groupCode
|
|
257
|
+
};
|
|
258
|
+
const msgId = await api.resolveMsgIdBySeq(peer, payload.message_seq, ChatType.GROUP);
|
|
259
|
+
if (msgId === void 0) throw kernelError(`消息 ${payload.message_seq} 不存在`, "NOT_FOUND");
|
|
260
|
+
if (payload.is_set === false) await api.groupApi.removeGroupEssence(groupCode, msgId);
|
|
261
|
+
else await api.groupApi.addGroupEssence(groupCode, msgId);
|
|
262
|
+
return {};
|
|
263
|
+
}
|
|
264
|
+
}),
|
|
265
|
+
defineMilkyAction({
|
|
266
|
+
name: "send_group_message_reaction",
|
|
267
|
+
schema: z.object({
|
|
268
|
+
...groupIdField,
|
|
269
|
+
message_seq: z.number().int().min(0),
|
|
270
|
+
reaction: z.string().min(1),
|
|
271
|
+
reaction_type: z.enum(["face", "emoji"]).nullable().optional(),
|
|
272
|
+
is_add: z.boolean().nullable().optional()
|
|
273
|
+
}),
|
|
274
|
+
handle: async (payload) => {
|
|
275
|
+
const peer = {
|
|
276
|
+
chatType: ChatType.GROUP,
|
|
277
|
+
peerUid: String(payload.group_id)
|
|
278
|
+
};
|
|
279
|
+
await api.msgApi.setMsgEmojiLike(peer, {
|
|
280
|
+
msgSeq: String(payload.message_seq),
|
|
281
|
+
emojiId: payload.reaction,
|
|
282
|
+
emojiType: payload.reaction_type === "emoji" ? "2" : "1",
|
|
283
|
+
like: payload.is_add !== false
|
|
284
|
+
});
|
|
285
|
+
return {};
|
|
286
|
+
}
|
|
287
|
+
})
|
|
288
|
+
];
|
|
289
|
+
}
|
|
137
290
|
/** ---------- 内部辅助 ---------- */
|
|
138
291
|
/** 精华项 → GroupEssenceMessage(msg_content 近似翻译:text / image)。 */
|
|
139
292
|
function essenceToEntity(item, groupId) {
|
|
@@ -221,107 +374,142 @@ async function writeBase64(payload, mediaDir) {
|
|
|
221
374
|
}
|
|
222
375
|
}
|
|
223
376
|
// src/milky/action/group-file.ts
|
|
224
|
-
const groupIdField$3 = { group_id: z.number().int().min(10001) };
|
|
225
377
|
const fileIdField = { file_id: z.string().min(1) };
|
|
226
378
|
const optStr$2 = z.string().nullable().optional();
|
|
227
|
-
/**
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
};
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
379
|
+
/** 群文件域动作工厂(列表 / 移动 / 重命名 / 删除 / 转存 / 文件夹 / 闪传上传 / 下载链接)。 */
|
|
380
|
+
function createGroupFileActions(api) {
|
|
381
|
+
return [
|
|
382
|
+
defineMilkyAction({
|
|
383
|
+
name: "get_group_files",
|
|
384
|
+
schema: z.object({
|
|
385
|
+
...groupIdField,
|
|
386
|
+
parent_folder_id: optStr$2
|
|
387
|
+
}),
|
|
388
|
+
handle: async (payload) => {
|
|
389
|
+
const groupCode = String(payload.group_id);
|
|
390
|
+
const parent = payload.parent_folder_id ?? "";
|
|
391
|
+
const items = await api.richMediaApi.getGroupFileList(groupCode, parent);
|
|
392
|
+
const files = [];
|
|
393
|
+
const folders = [];
|
|
394
|
+
for (const item of items) if (item.fileInfo !== void 0) files.push(fileToEntity(item.fileInfo, payload.group_id));
|
|
395
|
+
else if (item.folderInfo !== void 0) folders.push(folderToEntity(item.folderInfo, payload.group_id));
|
|
396
|
+
return {
|
|
397
|
+
files,
|
|
398
|
+
folders
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
}),
|
|
402
|
+
defineMilkyAction({
|
|
403
|
+
name: "move_group_file",
|
|
404
|
+
schema: z.object({
|
|
405
|
+
...groupIdField,
|
|
406
|
+
...fileIdField,
|
|
407
|
+
parent_folder_id: optStr$2,
|
|
408
|
+
target_folder_id: optStr$2
|
|
409
|
+
}),
|
|
410
|
+
handle: async (payload) => {
|
|
411
|
+
await api.richMediaApi.moveGroupFile(String(payload.group_id), [payload.file_id], payload.target_folder_id ?? "");
|
|
412
|
+
return {};
|
|
413
|
+
}
|
|
414
|
+
}),
|
|
415
|
+
defineMilkyAction({
|
|
416
|
+
name: "rename_group_file",
|
|
417
|
+
schema: z.object({
|
|
418
|
+
...groupIdField,
|
|
419
|
+
...fileIdField,
|
|
420
|
+
parent_folder_id: optStr$2,
|
|
421
|
+
new_file_name: z.string().min(1)
|
|
422
|
+
}),
|
|
423
|
+
handle: async (payload) => {
|
|
424
|
+
await api.richMediaApi.renameGroupFile(String(payload.group_id), payload.file_id, payload.new_file_name);
|
|
425
|
+
return {};
|
|
426
|
+
}
|
|
427
|
+
}),
|
|
428
|
+
defineMilkyAction({
|
|
429
|
+
name: "delete_group_file",
|
|
430
|
+
schema: z.object({
|
|
431
|
+
...groupIdField,
|
|
432
|
+
...fileIdField
|
|
433
|
+
}),
|
|
434
|
+
handle: async (payload) => {
|
|
435
|
+
await api.richMediaApi.deleteGroupFile(String(payload.group_id), [payload.file_id]);
|
|
436
|
+
return {};
|
|
437
|
+
}
|
|
438
|
+
}),
|
|
439
|
+
defineMilkyAction({
|
|
440
|
+
name: "persist_group_file",
|
|
441
|
+
schema: z.object({
|
|
442
|
+
...groupIdField,
|
|
443
|
+
...fileIdField
|
|
444
|
+
}),
|
|
445
|
+
handle: async (payload) => {
|
|
446
|
+
await api.richMediaApi.transGroupFile(String(payload.group_id), payload.file_id);
|
|
447
|
+
return {};
|
|
448
|
+
}
|
|
449
|
+
}),
|
|
450
|
+
defineMilkyAction({
|
|
451
|
+
name: "create_group_folder",
|
|
452
|
+
schema: z.object({
|
|
453
|
+
...groupIdField,
|
|
454
|
+
folder_name: z.string().min(1)
|
|
455
|
+
}),
|
|
456
|
+
handle: async (payload) => {
|
|
457
|
+
return { folder_id: await api.richMediaApi.createGroupFolder(String(payload.group_id), payload.folder_name) };
|
|
458
|
+
}
|
|
459
|
+
}),
|
|
460
|
+
defineMilkyAction({
|
|
461
|
+
name: "delete_group_folder",
|
|
462
|
+
schema: z.object({
|
|
463
|
+
...groupIdField,
|
|
464
|
+
folder_id: z.string().min(1)
|
|
465
|
+
}),
|
|
466
|
+
handle: async (payload) => {
|
|
467
|
+
await api.richMediaApi.deleteGroupFolder(String(payload.group_id), payload.folder_id);
|
|
468
|
+
return {};
|
|
469
|
+
}
|
|
470
|
+
}),
|
|
471
|
+
defineMilkyAction({
|
|
472
|
+
name: "upload_group_file",
|
|
473
|
+
schema: z.object({
|
|
474
|
+
...groupIdField,
|
|
475
|
+
parent_folder_id: optStr$2,
|
|
476
|
+
file_uri: z.string().min(1),
|
|
477
|
+
file_name: z.string().min(1)
|
|
478
|
+
}),
|
|
479
|
+
handle: async (payload) => {
|
|
480
|
+
const path = await resolveUriToPath(payload.file_uri, api.mediaDir);
|
|
481
|
+
const peer = {
|
|
482
|
+
chatType: ChatType.GROUP,
|
|
483
|
+
peerUid: String(payload.group_id)
|
|
484
|
+
};
|
|
485
|
+
return { file_id: (await api.flashTransferApi.sendFile(peer, [path], { name: payload.file_name })).fileSetId };
|
|
486
|
+
}
|
|
487
|
+
}),
|
|
488
|
+
defineMilkyAction({
|
|
489
|
+
name: "get_group_file_download_url",
|
|
490
|
+
schema: z.object({
|
|
491
|
+
...groupIdField,
|
|
492
|
+
...fileIdField
|
|
493
|
+
}),
|
|
494
|
+
handle: async (payload) => {
|
|
495
|
+
return { download_url: await api.richMediaApi.getGroupFileDownloadUrl(String(payload.group_id), payload.file_id) };
|
|
496
|
+
}
|
|
497
|
+
}),
|
|
498
|
+
defineMilkyAction({
|
|
499
|
+
name: "rename_group_folder",
|
|
500
|
+
schema: z.object({
|
|
501
|
+
...groupIdField,
|
|
502
|
+
folder_id: z.string().min(1),
|
|
503
|
+
new_folder_name: z.string().min(1)
|
|
504
|
+
}),
|
|
505
|
+
handle: async (payload) => {
|
|
506
|
+
await api.richMediaApi.renameGroupFolder(String(payload.group_id), payload.folder_id, payload.new_folder_name);
|
|
507
|
+
return {};
|
|
508
|
+
}
|
|
509
|
+
})
|
|
510
|
+
];
|
|
511
|
+
}
|
|
512
|
+
/** ---------- 内部辅助 ---------- */
|
|
325
513
|
/** GroupFileItemInfo → GroupFileEntity(fileSize 原生为字符串;无源字段兜底)。 */
|
|
326
514
|
function fileToEntity(info, groupId) {
|
|
327
515
|
return {
|
|
@@ -353,231 +541,176 @@ function folderToEntity(info, groupId) {
|
|
|
353
541
|
file_count: num("totalFileCount")
|
|
354
542
|
};
|
|
355
543
|
}
|
|
356
|
-
/**
|
|
357
|
-
* upload_group_file:上传并投递文件(**闪传通道**:分享链接卡片,见文件头语义说明)。
|
|
358
|
-
* file_id 返回闪传文件集 id(非群文件 fileId)。
|
|
359
|
-
*/
|
|
360
|
-
var UploadGroupFileAction = class extends MilkyApiAction {
|
|
361
|
-
name = "upload_group_file";
|
|
362
|
-
schema = z.object({
|
|
363
|
-
...groupIdField$3,
|
|
364
|
-
parent_folder_id: optStr$2,
|
|
365
|
-
file_uri: z.string().min(1),
|
|
366
|
-
file_name: z.string().min(1)
|
|
367
|
-
});
|
|
368
|
-
async _handle(payload) {
|
|
369
|
-
const path = await resolveUriToPath(payload.file_uri, this.api.mediaDir);
|
|
370
|
-
const peer = {
|
|
371
|
-
chatType: ChatType.GROUP,
|
|
372
|
-
peerUid: String(payload.group_id)
|
|
373
|
-
};
|
|
374
|
-
return { file_id: (await this.api.flashTransferApi.sendFile(peer, [path], { name: payload.file_name })).fileSetId };
|
|
375
|
-
}
|
|
376
|
-
};
|
|
377
|
-
/** get_group_file_download_url:群文件下载链接(url 字段待实机确认,仅根目录)。 */
|
|
378
|
-
var GetGroupFileDownloadUrlAction = class extends MilkyApiAction {
|
|
379
|
-
name = "get_group_file_download_url";
|
|
380
|
-
schema = z.object({
|
|
381
|
-
...groupIdField$3,
|
|
382
|
-
...fileIdField
|
|
383
|
-
});
|
|
384
|
-
async _handle(payload) {
|
|
385
|
-
return { download_url: await this.api.richMediaApi.getGroupFileDownloadUrl(String(payload.group_id), payload.file_id) };
|
|
386
|
-
}
|
|
387
|
-
};
|
|
388
|
-
/** rename_group_folder:重命名群文件夹(renameGroupFile 同款形态,待校准)。 */
|
|
389
|
-
var RenameGroupFolderAction = class extends MilkyApiAction {
|
|
390
|
-
name = "rename_group_folder";
|
|
391
|
-
schema = z.object({
|
|
392
|
-
...groupIdField$3,
|
|
393
|
-
folder_id: z.string().min(1),
|
|
394
|
-
new_folder_name: z.string().min(1)
|
|
395
|
-
});
|
|
396
|
-
async _handle(payload) {
|
|
397
|
-
await this.api.richMediaApi.renameGroupFolder(String(payload.group_id), payload.folder_id, payload.new_folder_name);
|
|
398
|
-
return {};
|
|
399
|
-
}
|
|
400
|
-
};
|
|
401
544
|
// src/milky/action/group-manage.ts
|
|
402
545
|
/**
|
|
403
|
-
* Milky
|
|
404
|
-
*
|
|
405
|
-
*
|
|
406
|
-
*
|
|
407
|
-
*
|
|
546
|
+
* Milky 群管理域动作:send_group_nudge / set_group_name / set_group_member_card /
|
|
547
|
+
* set_group_member_admin / set_group_member_mute / set_group_whole_mute /
|
|
548
|
+
* kick_group_member / quit_group / set_group_avatar /
|
|
549
|
+
* set_group_member_special_title / send_group_announcement / delete_group_announcement。
|
|
550
|
+
* 写操作合:成员类操作 user_id(uin) → uid 转换后进 kernel(resolveUidFromUin);
|
|
551
|
+
* 公告 image_uri / 头像 image_uri 落盘后进 kernel。
|
|
408
552
|
*/
|
|
409
|
-
const groupIdField$2 = { group_id: z.number().int().min(10001) };
|
|
410
|
-
const userIdField$1 = { user_id: z.number().int().min(10001) };
|
|
411
|
-
const optBool$2 = z.boolean().nullable().optional();
|
|
412
553
|
const optStr$1 = z.string().nullable().optional();
|
|
413
554
|
/** NTGroupMemberRole 数值(ADMIN=3 / MEMBER=2,setMemberRole 入参)。 */
|
|
414
555
|
const NTGroupMemberRoleAdmin = 3;
|
|
415
556
|
const NTGroupMemberRoleMember = 2;
|
|
416
|
-
/**
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
};
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
announcement_id: z.string().min(1)
|
|
574
|
-
});
|
|
575
|
-
async _handle(payload) {
|
|
576
|
-
await this.api.groupApi.deleteGroupAnnouncement(String(payload.group_id), payload.announcement_id);
|
|
577
|
-
return {};
|
|
578
|
-
}
|
|
579
|
-
};
|
|
580
|
-
/** ---------- 内部辅助 ---------- */
|
|
557
|
+
/** 群管理域动作工厂(群设置 / 成员管理 / 公告 / 戳一戳)。 */
|
|
558
|
+
function createGroupManageActions(api) {
|
|
559
|
+
return [
|
|
560
|
+
defineMilkyAction({
|
|
561
|
+
name: "send_group_nudge",
|
|
562
|
+
schema: z.object({
|
|
563
|
+
...groupIdField,
|
|
564
|
+
...userIdField
|
|
565
|
+
}),
|
|
566
|
+
handle: async (payload) => {
|
|
567
|
+
const receiverUid = await api.resolveUidFromUin(payload.user_id);
|
|
568
|
+
const peer = await api.resolvePeer("group", payload.group_id);
|
|
569
|
+
await api.msgApi.sendNudge(peer, {
|
|
570
|
+
receiverUid,
|
|
571
|
+
callerUid: requireSelfUid$1(api)
|
|
572
|
+
});
|
|
573
|
+
return {};
|
|
574
|
+
}
|
|
575
|
+
}),
|
|
576
|
+
defineMilkyAction({
|
|
577
|
+
name: "set_group_name",
|
|
578
|
+
schema: z.object({
|
|
579
|
+
...groupIdField,
|
|
580
|
+
new_group_name: z.string()
|
|
581
|
+
}),
|
|
582
|
+
handle: async (payload) => {
|
|
583
|
+
await api.groupApi.modifyGroupName(String(payload.group_id), payload.new_group_name);
|
|
584
|
+
return {};
|
|
585
|
+
}
|
|
586
|
+
}),
|
|
587
|
+
defineMilkyAction({
|
|
588
|
+
name: "set_group_member_card",
|
|
589
|
+
schema: z.object({
|
|
590
|
+
...groupIdField,
|
|
591
|
+
...userIdField,
|
|
592
|
+
card: z.string()
|
|
593
|
+
}),
|
|
594
|
+
handle: async (payload) => {
|
|
595
|
+
const uid = await api.resolveUidFromUin(payload.user_id);
|
|
596
|
+
api.groupApi.setMemberCardName(String(payload.group_id), uid, payload.card);
|
|
597
|
+
return {};
|
|
598
|
+
}
|
|
599
|
+
}),
|
|
600
|
+
defineMilkyAction({
|
|
601
|
+
name: "set_group_member_admin",
|
|
602
|
+
schema: z.object({
|
|
603
|
+
...groupIdField,
|
|
604
|
+
...userIdField,
|
|
605
|
+
is_set: optBool$1
|
|
606
|
+
}),
|
|
607
|
+
handle: async (payload) => {
|
|
608
|
+
const uid = await api.resolveUidFromUin(payload.user_id);
|
|
609
|
+
api.groupApi.setMemberRole(String(payload.group_id), uid, payload.is_set === false ? NTGroupMemberRoleMember : NTGroupMemberRoleAdmin);
|
|
610
|
+
return {};
|
|
611
|
+
}
|
|
612
|
+
}),
|
|
613
|
+
defineMilkyAction({
|
|
614
|
+
name: "set_group_member_mute",
|
|
615
|
+
schema: z.object({
|
|
616
|
+
...groupIdField,
|
|
617
|
+
...userIdField,
|
|
618
|
+
duration: z.number().int().min(0).nullable().optional()
|
|
619
|
+
}),
|
|
620
|
+
handle: async (payload) => {
|
|
621
|
+
const uid = await api.resolveUidFromUin(payload.user_id);
|
|
622
|
+
await api.groupApi.setMemberShutUp(String(payload.group_id), [{
|
|
623
|
+
uid,
|
|
624
|
+
duration: payload.duration ?? 0
|
|
625
|
+
}]);
|
|
626
|
+
return {};
|
|
627
|
+
}
|
|
628
|
+
}),
|
|
629
|
+
defineMilkyAction({
|
|
630
|
+
name: "set_group_whole_mute",
|
|
631
|
+
schema: z.object({
|
|
632
|
+
...groupIdField,
|
|
633
|
+
is_mute: optBool$1
|
|
634
|
+
}),
|
|
635
|
+
handle: async (payload) => {
|
|
636
|
+
await api.groupApi.setGroupShutUp(String(payload.group_id), payload.is_mute !== false);
|
|
637
|
+
return {};
|
|
638
|
+
}
|
|
639
|
+
}),
|
|
640
|
+
defineMilkyAction({
|
|
641
|
+
name: "kick_group_member",
|
|
642
|
+
schema: z.object({
|
|
643
|
+
...groupIdField,
|
|
644
|
+
...userIdField,
|
|
645
|
+
reject_add_request: optBool$1
|
|
646
|
+
}),
|
|
647
|
+
handle: async (payload) => {
|
|
648
|
+
const uid = await api.resolveUidFromUin(payload.user_id);
|
|
649
|
+
await api.groupApi.kickMember(String(payload.group_id), [uid], payload.reject_add_request === true);
|
|
650
|
+
return {};
|
|
651
|
+
}
|
|
652
|
+
}),
|
|
653
|
+
defineMilkyAction({
|
|
654
|
+
name: "quit_group",
|
|
655
|
+
schema: z.object({ ...groupIdField }),
|
|
656
|
+
handle: async (payload) => {
|
|
657
|
+
await api.groupApi.quitGroup(String(payload.group_id));
|
|
658
|
+
return {};
|
|
659
|
+
}
|
|
660
|
+
}),
|
|
661
|
+
defineMilkyAction({
|
|
662
|
+
name: "set_group_avatar",
|
|
663
|
+
schema: z.object({
|
|
664
|
+
...groupIdField,
|
|
665
|
+
image_uri: z.string().min(1)
|
|
666
|
+
}),
|
|
667
|
+
handle: async (payload) => {
|
|
668
|
+
const imagePath = await resolveUriToPath(payload.image_uri, api.mediaDir);
|
|
669
|
+
await api.groupApi.setGroupAvatar(String(payload.group_id), imagePath);
|
|
670
|
+
return {};
|
|
671
|
+
}
|
|
672
|
+
}),
|
|
673
|
+
defineMilkyAction({
|
|
674
|
+
name: "set_group_member_special_title",
|
|
675
|
+
schema: z.object({
|
|
676
|
+
...groupIdField,
|
|
677
|
+
...userIdField,
|
|
678
|
+
special_title: z.string()
|
|
679
|
+
}),
|
|
680
|
+
handle: async (payload) => {
|
|
681
|
+
const uid = await api.resolveUidFromUin(payload.user_id);
|
|
682
|
+
await api.groupApi.setMemberSpecialTitle(String(payload.group_id), uid, payload.special_title);
|
|
683
|
+
return {};
|
|
684
|
+
}
|
|
685
|
+
}),
|
|
686
|
+
defineMilkyAction({
|
|
687
|
+
name: "send_group_announcement",
|
|
688
|
+
schema: z.object({
|
|
689
|
+
...groupIdField,
|
|
690
|
+
content: z.string().min(1),
|
|
691
|
+
image_uri: optStr$1
|
|
692
|
+
}),
|
|
693
|
+
handle: async (payload) => {
|
|
694
|
+
const groupCode = String(payload.group_id);
|
|
695
|
+
let imagePath;
|
|
696
|
+
if (payload.image_uri !== void 0 && payload.image_uri !== null && payload.image_uri !== "") imagePath = await resolveUriToPath(payload.image_uri, api.mediaDir);
|
|
697
|
+
await api.groupApi.publishGroupAnnouncement(groupCode, payload.content, imagePath);
|
|
698
|
+
return {};
|
|
699
|
+
}
|
|
700
|
+
}),
|
|
701
|
+
defineMilkyAction({
|
|
702
|
+
name: "delete_group_announcement",
|
|
703
|
+
schema: z.object({
|
|
704
|
+
...groupIdField,
|
|
705
|
+
announcement_id: z.string().min(1)
|
|
706
|
+
}),
|
|
707
|
+
handle: async (payload) => {
|
|
708
|
+
await api.groupApi.deleteGroupAnnouncement(String(payload.group_id), payload.announcement_id);
|
|
709
|
+
return {};
|
|
710
|
+
}
|
|
711
|
+
})
|
|
712
|
+
];
|
|
713
|
+
}
|
|
581
714
|
/** self.uid 必备(nudge 发送的 callerUid;缺配置报 INVALID_PARAM)。 */
|
|
582
715
|
function requireSelfUid$1(api) {
|
|
583
716
|
const uid = api.self.uid;
|
|
@@ -707,19 +840,22 @@ var MilkyApi = class {
|
|
|
707
840
|
/** 通知查找默认搜索数量(单屏全量,OB11 DEFAULT_COUNT 同值)。 */
|
|
708
841
|
const NOTIFY_SEARCH_COUNT$1 = 100;
|
|
709
842
|
/**
|
|
710
|
-
* 按通知 seq
|
|
711
|
-
*
|
|
843
|
+
* 按通知 seq 查找群通知(先非可疑后可疑两屏依序,OB11 set_group_add_request
|
|
844
|
+
* 同路径)。屏序惰性拉取:前一屏命中则不拉后续屏(群通知规范序)。
|
|
712
845
|
* 未找到抛 NOT_FOUND(应答动作的 seq 无效或已过期)。
|
|
713
846
|
* 模块级函数(非类成员):应答动作的公共入口,OB11 同路径。
|
|
714
847
|
*/
|
|
715
848
|
async function findGroupNotify(api, seq) {
|
|
716
|
-
const
|
|
717
|
-
|
|
718
|
-
|
|
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");
|
|
719
855
|
}
|
|
720
856
|
/** 按发起者 uid 查找好友申请(getBuddyReqList 匹配 friendUid);未找到抛 NOT_FOUND。 */
|
|
721
857
|
async function findBuddyReq(api, initiatorUid) {
|
|
722
|
-
const hit = await
|
|
858
|
+
const hit = (await api.friendApi.getBuddyReqList()).find((req) => req.friendUid === initiatorUid);
|
|
723
859
|
if (hit === void 0) throw kernelError(`未找到来自 ${initiatorUid} 的好友申请`, "NOT_FOUND");
|
|
724
860
|
return hit;
|
|
725
861
|
}
|
|
@@ -795,114 +931,96 @@ function collectNotifyUids(notifies) {
|
|
|
795
931
|
return [...uids];
|
|
796
932
|
}
|
|
797
933
|
// src/milky/action/group-notice.ts
|
|
798
|
-
const groupIdField$1 = { group_id: z.number().int().min(10001) };
|
|
799
|
-
const optBool$1 = z.boolean().nullable().optional();
|
|
800
934
|
const optStr = z.string().nullable().optional();
|
|
801
|
-
/**
|
|
802
|
-
* get_group_notifications:获取群通知列表。
|
|
803
|
-
* kernel getSingleScreenNotifies 为单屏快照(无翻页)——start_notification_seq
|
|
804
|
-
* 作客户端过滤(取 seq 更小的记录);next = 本页最小 seq(仍有余量时)。
|
|
805
|
-
*/
|
|
806
|
-
var GetGroupNotificationsAction = class extends MilkyApiAction {
|
|
807
|
-
name = "get_group_notifications";
|
|
808
|
-
schema = z.object({
|
|
809
|
-
start_notification_seq: z.number().int().min(0).nullable().optional(),
|
|
810
|
-
is_filtered: optBool$1,
|
|
811
|
-
limit: z.number().int().min(0).nullable().optional()
|
|
812
|
-
});
|
|
813
|
-
async _handle(payload) {
|
|
814
|
-
const notifies = await this.api.groupNotifyApi.getSingleScreenNotifies(payload.is_filtered === true, NOTIFY_SEARCH_COUNT);
|
|
815
|
-
const start = payload.start_notification_seq;
|
|
816
|
-
const filtered = notifies.filter((n) => start === void 0 || start === null || Number(n.seq) < start);
|
|
817
|
-
const uidToUin = await this.collectUidToUin(filtered);
|
|
818
|
-
const entities = filtered.map((n) => notifyToEntity(n, payload.is_filtered === true, uidToUin)).filter((e) => e !== null);
|
|
819
|
-
const limit = payload.limit ?? NOTIFICATIONS_DEFAULT_LIMIT;
|
|
820
|
-
const page = entities.slice(0, limit);
|
|
821
|
-
const minSeq = page.reduce((acc, e) => acc === null ? e.notification_seq : Math.min(acc, e.notification_seq), null);
|
|
822
|
-
return {
|
|
823
|
-
notifications: page,
|
|
824
|
-
next_notification_seq: entities.length > page.length && minSeq !== null ? minSeq : null
|
|
825
|
-
};
|
|
826
|
-
}
|
|
827
|
-
/** 通知 user1/user2 uid → uin 批量转换(失败退空 Map,实体 id 兜底 0)。 */
|
|
828
|
-
async collectUidToUin(notifies) {
|
|
829
|
-
const uids = collectNotifyUids(notifies);
|
|
830
|
-
if (uids.length === 0) return /* @__PURE__ */ new Map();
|
|
831
|
-
return await this.api.uidToUin(uids).catch((err) => {
|
|
832
|
-
this.api.logger?.warn({
|
|
833
|
-
count: uids.length,
|
|
834
|
-
error: err instanceof Error ? err.message : String(err)
|
|
835
|
-
}, "milky: 通知 uid→uin 失败,实体 id 兜底 0");
|
|
836
|
-
return /* @__PURE__ */ new Map();
|
|
837
|
-
});
|
|
838
|
-
}
|
|
839
|
-
};
|
|
840
|
-
/** accept/reject 群请求 / 群邀请公共基类:seq → 通知匹配 → handleGroupRequest。 */
|
|
841
|
-
var HandleGroupNotifyBase = class extends MilkyApiAction {
|
|
842
|
-
async respond(seq, doubt) {
|
|
843
|
-
const notify = await findGroupNotify(this.api, String(seq));
|
|
844
|
-
await this.api.groupNotifyApi.handleGroupRequest(doubt, notify, this.approve ? NTGroupRequestOperateTypes.KAGREE : NTGroupRequestOperateTypes.KREFUSE, " ");
|
|
845
|
-
return {};
|
|
846
|
-
}
|
|
847
|
-
};
|
|
848
|
-
/** accept_group_request:同意入群请求(notification_type/group_id 仅 schema 校验)。 */
|
|
849
|
-
var AcceptGroupRequestAction = class extends HandleGroupNotifyBase {
|
|
850
|
-
name = "accept_group_request";
|
|
851
|
-
schema = z.object({
|
|
852
|
-
notification_seq: z.number().int().min(0),
|
|
853
|
-
notification_type: z.enum(["join_request", "invited_join_request"]),
|
|
854
|
-
...groupIdField$1,
|
|
855
|
-
is_filtered: optBool$1
|
|
856
|
-
});
|
|
857
|
-
approve = true;
|
|
858
|
-
async _handle(payload) {
|
|
859
|
-
return await this.respond(payload.notification_seq, payload.is_filtered === true);
|
|
860
|
-
}
|
|
861
|
-
};
|
|
862
|
-
/** reject_group_request:拒绝入群请求(reason 无源,kernel postscript 占位空格)。 */
|
|
863
|
-
var RejectGroupRequestAction = class extends HandleGroupNotifyBase {
|
|
864
|
-
name = "reject_group_request";
|
|
865
|
-
schema = z.object({
|
|
866
|
-
notification_seq: z.number().int().min(0),
|
|
867
|
-
notification_type: z.enum(["join_request", "invited_join_request"]),
|
|
868
|
-
...groupIdField$1,
|
|
869
|
-
is_filtered: optBool$1,
|
|
870
|
-
reason: optStr
|
|
871
|
-
});
|
|
872
|
-
approve = false;
|
|
873
|
-
async _handle(payload) {
|
|
874
|
-
return await this.respond(payload.notification_seq, payload.is_filtered === true);
|
|
875
|
-
}
|
|
876
|
-
};
|
|
877
|
-
/** accept_group_invitation:接受入群邀请(按 invitation_seq 匹配)。 */
|
|
878
|
-
var AcceptGroupInvitationAction = class extends HandleGroupNotifyBase {
|
|
879
|
-
name = "accept_group_invitation";
|
|
880
|
-
schema = z.object({
|
|
881
|
-
...groupIdField$1,
|
|
882
|
-
invitation_seq: z.number().int().min(0)
|
|
883
|
-
});
|
|
884
|
-
approve = true;
|
|
885
|
-
async _handle(payload) {
|
|
886
|
-
return await this.respond(payload.invitation_seq, false);
|
|
887
|
-
}
|
|
888
|
-
};
|
|
889
|
-
/** reject_group_invitation:拒绝入群邀请。 */
|
|
890
|
-
var RejectGroupInvitationAction = class extends HandleGroupNotifyBase {
|
|
891
|
-
name = "reject_group_invitation";
|
|
892
|
-
schema = z.object({
|
|
893
|
-
...groupIdField$1,
|
|
894
|
-
invitation_seq: z.number().int().min(0)
|
|
895
|
-
});
|
|
896
|
-
approve = false;
|
|
897
|
-
async _handle(payload) {
|
|
898
|
-
return await this.respond(payload.invitation_seq, false);
|
|
899
|
-
}
|
|
900
|
-
};
|
|
901
|
-
/** ---------- 内部辅助 ---------- */
|
|
902
935
|
/** 通知查找数量(单屏全量,OB11 DEFAULT_COUNT 同值)。 */
|
|
903
936
|
const NOTIFY_SEARCH_COUNT = 100;
|
|
904
937
|
/** get_group_notifications 默认 limit(规范 default 20)。 */
|
|
905
938
|
const NOTIFICATIONS_DEFAULT_LIMIT = 20;
|
|
939
|
+
/** 群通知域动作工厂(通知列表 + 应答四动作)。 */
|
|
940
|
+
function createGroupNoticeActions(api) {
|
|
941
|
+
return [
|
|
942
|
+
defineMilkyAction({
|
|
943
|
+
name: "get_group_notifications",
|
|
944
|
+
schema: z.object({
|
|
945
|
+
start_notification_seq: z.number().int().min(0).nullable().optional(),
|
|
946
|
+
is_filtered: optBool$1,
|
|
947
|
+
limit: z.number().int().min(0).nullable().optional()
|
|
948
|
+
}),
|
|
949
|
+
handle: async (payload) => {
|
|
950
|
+
const notifies = await api.groupNotifyApi.getSingleScreenNotifies(payload.is_filtered === true, NOTIFY_SEARCH_COUNT);
|
|
951
|
+
const start = payload.start_notification_seq;
|
|
952
|
+
const filtered = notifies.filter((n) => start === void 0 || start === null || Number(n.seq) < start);
|
|
953
|
+
const uidToUin = await collectUidToUin$1(api, filtered);
|
|
954
|
+
const entities = filtered.map((n) => notifyToEntity(n, payload.is_filtered === true, uidToUin)).filter((e) => e !== null);
|
|
955
|
+
const limit = payload.limit ?? NOTIFICATIONS_DEFAULT_LIMIT;
|
|
956
|
+
const page = entities.slice(0, limit);
|
|
957
|
+
const minSeq = page.reduce((acc, e) => acc === null ? e.notification_seq : Math.min(acc, e.notification_seq), null);
|
|
958
|
+
return {
|
|
959
|
+
notifications: page,
|
|
960
|
+
next_notification_seq: entities.length > page.length && minSeq !== null ? minSeq : null
|
|
961
|
+
};
|
|
962
|
+
}
|
|
963
|
+
}),
|
|
964
|
+
defineMilkyAction({
|
|
965
|
+
name: "accept_group_request",
|
|
966
|
+
schema: respondRequestSchema,
|
|
967
|
+
handle: async (payload) => respondGroupNotify(api, payload.notification_seq, payload.is_filtered === true, true)
|
|
968
|
+
}),
|
|
969
|
+
defineMilkyAction({
|
|
970
|
+
name: "reject_group_request",
|
|
971
|
+
schema: rejectRequestSchema,
|
|
972
|
+
handle: async (payload) => respondGroupNotify(api, payload.notification_seq, payload.is_filtered === true, false)
|
|
973
|
+
}),
|
|
974
|
+
defineMilkyAction({
|
|
975
|
+
name: "accept_group_invitation",
|
|
976
|
+
schema: invitationSchema,
|
|
977
|
+
handle: async (payload) => respondGroupNotify(api, payload.invitation_seq, false, true)
|
|
978
|
+
}),
|
|
979
|
+
defineMilkyAction({
|
|
980
|
+
name: "reject_group_invitation",
|
|
981
|
+
schema: invitationSchema,
|
|
982
|
+
handle: async (payload) => respondGroupNotify(api, payload.invitation_seq, false, false)
|
|
983
|
+
})
|
|
984
|
+
];
|
|
985
|
+
}
|
|
986
|
+
/** accept_group_request 入参(notification_type 仅 schema 校验)。 */
|
|
987
|
+
const respondRequestSchema = z.object({
|
|
988
|
+
notification_seq: z.number().int().min(0),
|
|
989
|
+
notification_type: z.enum(["join_request", "invited_join_request"]),
|
|
990
|
+
...groupIdField,
|
|
991
|
+
is_filtered: optBool$1
|
|
992
|
+
});
|
|
993
|
+
/** reject_group_request 入参(reason 无源)。 */
|
|
994
|
+
const rejectRequestSchema = z.object({
|
|
995
|
+
notification_seq: z.number().int().min(0),
|
|
996
|
+
notification_type: z.enum(["join_request", "invited_join_request"]),
|
|
997
|
+
...groupIdField,
|
|
998
|
+
is_filtered: optBool$1,
|
|
999
|
+
reason: optStr
|
|
1000
|
+
});
|
|
1001
|
+
/** accept/reject_group_invitation 入参。 */
|
|
1002
|
+
const invitationSchema = z.object({
|
|
1003
|
+
...groupIdField,
|
|
1004
|
+
invitation_seq: z.number().int().min(0)
|
|
1005
|
+
});
|
|
1006
|
+
/** 应答公共路径:seq → 通知匹配 → handleGroupRequest。 */
|
|
1007
|
+
async function respondGroupNotify(api, seq, doubt, approve) {
|
|
1008
|
+
const notify = await findGroupNotify(api, String(seq));
|
|
1009
|
+
await api.groupNotifyApi.handleGroupRequest(doubt, notify, approve ? NTGroupRequestOperateTypes.KAGREE : NTGroupRequestOperateTypes.KREFUSE, " ");
|
|
1010
|
+
return {};
|
|
1011
|
+
}
|
|
1012
|
+
/** 通知 user1/user2 uid → uin 批量转换(失败退空 Map,实体 id 兜底 0)。 */
|
|
1013
|
+
async function collectUidToUin$1(api, notifies) {
|
|
1014
|
+
const uids = collectNotifyUids(notifies);
|
|
1015
|
+
if (uids.length === 0) return /* @__PURE__ */ new Map();
|
|
1016
|
+
return await api.uidToUin(uids).catch((err) => {
|
|
1017
|
+
api.logger?.warn({
|
|
1018
|
+
count: uids.length,
|
|
1019
|
+
error: err instanceof Error ? err.message : String(err)
|
|
1020
|
+
}, "milky: 通知 uid→uin 失败,实体 id 兜底 0");
|
|
1021
|
+
return /* @__PURE__ */ new Map();
|
|
1022
|
+
});
|
|
1023
|
+
}
|
|
906
1024
|
/**
|
|
907
1025
|
* GroupNotify → GroupNotificationEntity(uidToUin 已由调用方批量转换)。
|
|
908
1026
|
* 类型→构造器表:7=入群申请 / 5=成员邀请他人 / 8=设管理 / 12,13=取消管理 /
|
|
@@ -918,225 +1036,61 @@ const NOTIFY_ENTITY_BUILDERS = {
|
|
|
918
1036
|
state: "pending",
|
|
919
1037
|
operator_id: null,
|
|
920
1038
|
comment: n.postscript ?? ""
|
|
921
|
-
}),
|
|
922
|
-
5: (n, uinOf) => ({
|
|
923
|
-
type: "invited_join_request",
|
|
924
|
-
group_id: Number(n.group?.groupCode ?? 0),
|
|
925
|
-
notification_seq: Number(n.seq),
|
|
926
|
-
initiator_id: uinOf(n.user1?.uid),
|
|
927
|
-
target_user_id: uinOf(n.user2?.uid),
|
|
928
|
-
state: "pending",
|
|
929
|
-
operator_id: null
|
|
930
|
-
}),
|
|
931
|
-
8: (n, uinOf) => adminChangeEntity(n, uinOf, true),
|
|
932
|
-
12: (n, uinOf) => adminChangeEntity(n, uinOf, false),
|
|
933
|
-
13: (n, uinOf) => adminChangeEntity(n, uinOf, false),
|
|
934
|
-
9: (n, uinOf) => kickEntity(n, uinOf),
|
|
935
|
-
10: (n, uinOf) => kickEntity(n, uinOf),
|
|
936
|
-
11: (n, uinOf) => ({
|
|
937
|
-
type: "quit",
|
|
938
|
-
group_id: Number(n.group?.groupCode ?? 0),
|
|
939
|
-
notification_seq: Number(n.seq),
|
|
940
|
-
target_user_id: uinOf(n.user1?.uid)
|
|
941
|
-
})
|
|
942
|
-
};
|
|
943
|
-
/** admin_change 实体(8/12/13 共用)。 */
|
|
944
|
-
function adminChangeEntity(n, uinOf, isSet) {
|
|
945
|
-
return {
|
|
946
|
-
type: "admin_change",
|
|
947
|
-
group_id: Number(n.group?.groupCode ?? 0),
|
|
948
|
-
notification_seq: Number(n.seq),
|
|
949
|
-
target_user_id: uinOf(n.user1?.uid),
|
|
950
|
-
is_set: isSet,
|
|
951
|
-
operator_id: uinOf(n.user2?.uid)
|
|
952
|
-
};
|
|
953
|
-
}
|
|
954
|
-
/** kick 实体(9/10 共用)。 */
|
|
955
|
-
function kickEntity(n, uinOf) {
|
|
956
|
-
return {
|
|
957
|
-
type: "kick",
|
|
958
|
-
group_id: Number(n.group?.groupCode ?? 0),
|
|
959
|
-
notification_seq: Number(n.seq),
|
|
960
|
-
target_user_id: uinOf(n.user1?.uid),
|
|
961
|
-
operator_id: uinOf(n.user2?.uid)
|
|
962
|
-
};
|
|
963
|
-
}
|
|
964
|
-
/** GroupNotify → 实体(isFiltered 透传给 join_request;未识别类型 null)。 */
|
|
965
|
-
function notifyToEntity(notify, isFiltered, uidToUin) {
|
|
966
|
-
const uinOf = (uid) => uid === void 0 || uid === "" ? 0 : Number(uidToUin.get(uid) ?? 0) || 0;
|
|
967
|
-
const builder = NOTIFY_ENTITY_BUILDERS[notify.type];
|
|
968
|
-
if (builder === void 0) return null;
|
|
969
|
-
const entity = builder(notify, uinOf);
|
|
970
|
-
if (entity.type === "join_request") entity.is_filtered = isFiltered;
|
|
971
|
-
return entity;
|
|
972
|
-
}
|
|
973
|
-
// src/milky/helper/message/entities.ts
|
|
974
|
-
/** GroupDetailInfo / Group → GroupEntity(detail 缺失时全兜底)。 */
|
|
975
|
-
function toGroupEntity(detail, groupCode) {
|
|
976
|
-
return {
|
|
977
|
-
group_id: Number(groupCode),
|
|
978
|
-
group_name: detail?.groupName ?? "",
|
|
979
|
-
member_count: detail?.memberNum ?? 0,
|
|
980
|
-
max_member_count: detail?.maxMemberNum ?? 0,
|
|
981
|
-
remark: detail?.remarkName ?? "",
|
|
982
|
-
created_time: detail?.groupCreateTime ?? 0,
|
|
983
|
-
description: "",
|
|
984
|
-
question: "",
|
|
985
|
-
announcement: ""
|
|
986
|
-
};
|
|
987
|
-
}
|
|
988
|
-
/** 群列表项(GroupCache Group)→ GroupEntity。 */
|
|
989
|
-
function groupListToEntity(group) {
|
|
990
|
-
return {
|
|
991
|
-
group_id: Number(group.groupCode),
|
|
992
|
-
group_name: group.groupName,
|
|
993
|
-
member_count: group.memberCount,
|
|
994
|
-
max_member_count: group.maxMember,
|
|
995
|
-
remark: "",
|
|
996
|
-
created_time: 0,
|
|
997
|
-
description: "",
|
|
998
|
-
question: "",
|
|
999
|
-
announcement: ""
|
|
1000
|
-
};
|
|
1001
|
-
}
|
|
1002
|
-
/** GroupMember → GroupMemberEntity(member 缺失时按 uin 兜底最小实体)。 */
|
|
1003
|
-
function toGroupMemberEntity(member, groupCode, uin) {
|
|
1004
|
-
const shutUpSeconds = member?.shutUpTime ?? 0;
|
|
1005
|
-
return {
|
|
1006
|
-
user_id: Number(member?.uin !== void 0 && member.uin !== "" ? member.uin : uin),
|
|
1007
|
-
nickname: member?.nick ?? "",
|
|
1008
|
-
sex: "unknown",
|
|
1009
|
-
group_id: Number(groupCode),
|
|
1010
|
-
card: member?.cardName ?? "",
|
|
1011
|
-
title: member?.memberSpecialTitle ?? "",
|
|
1012
|
-
level: 0,
|
|
1013
|
-
role: GroupApi.roleToString(member?.role ?? 2),
|
|
1014
|
-
join_time: Number(member?.joinTime) || 0,
|
|
1015
|
-
last_sent_time: Number(member?.lastSpeakTime) || 0,
|
|
1016
|
-
shut_up_end_time: shutUpSeconds > 0 ? Math.floor(Date.now() / 1e3) + shutUpSeconds : null
|
|
1017
|
-
};
|
|
1018
|
-
}
|
|
1019
|
-
/** Friend → FriendEntity(kernel 无 qid/分类挂载,按最小实体兜底)。 */
|
|
1020
|
-
function toFriendEntity(friend, uin, nick) {
|
|
1021
|
-
return {
|
|
1022
|
-
user_id: Number(friend?.uin !== void 0 && friend.uin !== "" ? friend.uin : uin),
|
|
1023
|
-
nickname: friend?.nickname ?? nick,
|
|
1024
|
-
sex: "unknown",
|
|
1025
|
-
qid: "",
|
|
1026
|
-
remark: friend?.remark ?? "",
|
|
1027
|
-
category: {
|
|
1028
|
-
category_id: 0,
|
|
1029
|
-
category_name: ""
|
|
1030
|
-
}
|
|
1031
|
-
};
|
|
1032
|
-
}
|
|
1033
|
-
// src/milky/action/group-query.ts
|
|
1034
|
-
const groupIdField = { group_id: z.number().int().min(10001) };
|
|
1035
|
-
const userIdField = { user_id: z.number().int().min(10001) };
|
|
1036
|
-
const optBool = z.boolean().nullable().optional();
|
|
1037
|
-
/** get_group_info:获取群信息(GroupCache 详情缓存优先)。 */
|
|
1038
|
-
var GetGroupInfoAction = class extends MilkyApiAction {
|
|
1039
|
-
name = "get_group_info";
|
|
1040
|
-
schema = z.object({
|
|
1041
|
-
...groupIdField,
|
|
1042
|
-
no_cache: optBool
|
|
1043
|
-
});
|
|
1044
|
-
async _handle(payload) {
|
|
1045
|
-
const groupCode = String(payload.group_id);
|
|
1046
|
-
return { group: toGroupEntity(this.api.groupCache !== void 0 ? await this.api.groupCache.getGroupDetail(groupCode) : await this.api.groupApi.getGroupInfo(groupCode), groupCode) };
|
|
1047
|
-
}
|
|
1048
|
-
};
|
|
1049
|
-
/** get_group_member_list:获取群成员列表(GroupCache 惰性回填)。 */
|
|
1050
|
-
var GetGroupMemberListAction = class extends MilkyApiAction {
|
|
1051
|
-
name = "get_group_member_list";
|
|
1052
|
-
schema = z.object({
|
|
1053
|
-
...groupIdField,
|
|
1054
|
-
no_cache: optBool
|
|
1055
|
-
});
|
|
1056
|
-
async _handle(payload) {
|
|
1057
|
-
return { members: (await membersOf(this.api, String(payload.group_id))).map((m) => toGroupMemberEntity(m, String(payload.group_id), m.uin)) };
|
|
1058
|
-
}
|
|
1059
|
-
};
|
|
1060
|
-
/** get_group_member_info:获取群成员信息(user_id = uin → 成员单查)。 */
|
|
1061
|
-
var GetGroupMemberInfoAction = class extends MilkyApiAction {
|
|
1062
|
-
name = "get_group_member_info";
|
|
1063
|
-
schema = z.object({
|
|
1064
|
-
...groupIdField,
|
|
1065
|
-
...userIdField,
|
|
1066
|
-
no_cache: optBool
|
|
1067
|
-
});
|
|
1068
|
-
async _handle(payload) {
|
|
1069
|
-
return { member: toGroupMemberEntity(await memberOf(this.api, payload.group_id, payload.user_id), String(payload.group_id), String(payload.user_id)) };
|
|
1070
|
-
}
|
|
1071
|
-
};
|
|
1072
|
-
/** get_group_announcements:获取群公告列表(bulletin 形状待校准,宽松映射)。 */
|
|
1073
|
-
var GetGroupAnnouncementsAction = class extends MilkyApiAction {
|
|
1074
|
-
name = "get_group_announcements";
|
|
1075
|
-
schema = z.object({ ...groupIdField });
|
|
1076
|
-
async _handle(payload) {
|
|
1077
|
-
const groupCode = String(payload.group_id);
|
|
1078
|
-
const bulletins = await this.api.groupApi.getGroupAnnouncements(groupCode);
|
|
1079
|
-
return { announcements: await Promise.all(bulletins.map((b) => bulletinToEntity(b, payload.group_id, this.api))) };
|
|
1080
|
-
}
|
|
1081
|
-
};
|
|
1082
|
-
/** ---------- 内部辅助 ---------- */
|
|
1083
|
-
/** 成员列表(GroupCache 优先,未装配直查)。 */
|
|
1084
|
-
async function membersOf(api, groupCode) {
|
|
1085
|
-
if (api.groupCache !== void 0) return await api.groupCache.getMembers(groupCode);
|
|
1086
|
-
return await api.groupApi.getGroupMemberList(groupCode, true);
|
|
1087
|
-
}
|
|
1088
|
-
/** 成员单查(user_id = uin;缓存路径经 uid,直查路径按 uin 匹配)。 */
|
|
1089
|
-
async function memberOf(api, groupId, userId) {
|
|
1090
|
-
const groupCode = String(groupId);
|
|
1091
|
-
const uin = String(userId);
|
|
1092
|
-
if (api.groupCache !== void 0) {
|
|
1093
|
-
const uid = await api.resolveUidFromUin(userId).catch((err) => {
|
|
1094
|
-
api.logger?.debug({
|
|
1095
|
-
group: groupCode,
|
|
1096
|
-
uin,
|
|
1097
|
-
error: err instanceof Error ? err.message : String(err)
|
|
1098
|
-
}, "milky: 成员 uin→uid 失败,退用 uin 查缓存");
|
|
1099
|
-
return uin;
|
|
1100
|
-
});
|
|
1101
|
-
const member = await api.groupCache.getMember(groupCode, uid);
|
|
1102
|
-
if (member === void 0) throw kernelError(`成员 ${uin} 不在群 ${groupCode}`, "NOT_FOUND");
|
|
1103
|
-
return member;
|
|
1104
|
-
}
|
|
1105
|
-
const hit = (await api.groupApi.getGroupMemberList(groupCode, true)).find((m) => m.uin === uin);
|
|
1106
|
-
if (hit === void 0) throw kernelError(`成员 ${uin} 不在群 ${groupCode}`, "NOT_FOUND");
|
|
1107
|
-
return hit;
|
|
1108
|
-
}
|
|
1109
|
-
/** GroupBulletin → 群公告实体(senderUid → uin 反查;无源字段兜底,待校准)。 */
|
|
1110
|
-
async function bulletinToEntity(b, groupId, api) {
|
|
1039
|
+
}),
|
|
1040
|
+
5: (n, uinOf) => ({
|
|
1041
|
+
type: "invited_join_request",
|
|
1042
|
+
group_id: Number(n.group?.groupCode ?? 0),
|
|
1043
|
+
notification_seq: Number(n.seq),
|
|
1044
|
+
initiator_id: uinOf(n.user1?.uid),
|
|
1045
|
+
target_user_id: uinOf(n.user2?.uid),
|
|
1046
|
+
state: "pending",
|
|
1047
|
+
operator_id: null
|
|
1048
|
+
}),
|
|
1049
|
+
8: (n, uinOf) => adminChangeEntity(n, uinOf, true),
|
|
1050
|
+
12: (n, uinOf) => adminChangeEntity(n, uinOf, false),
|
|
1051
|
+
13: (n, uinOf) => adminChangeEntity(n, uinOf, false),
|
|
1052
|
+
9: (n, uinOf) => kickEntity(n, uinOf),
|
|
1053
|
+
10: (n, uinOf) => kickEntity(n, uinOf),
|
|
1054
|
+
11: (n, uinOf) => ({
|
|
1055
|
+
type: "quit",
|
|
1056
|
+
group_id: Number(n.group?.groupCode ?? 0),
|
|
1057
|
+
notification_seq: Number(n.seq),
|
|
1058
|
+
target_user_id: uinOf(n.user1?.uid)
|
|
1059
|
+
})
|
|
1060
|
+
};
|
|
1061
|
+
/** admin_change 实体(8/12/13 共用)。 */
|
|
1062
|
+
function adminChangeEntity(n, uinOf, isSet) {
|
|
1111
1063
|
return {
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1064
|
+
type: "admin_change",
|
|
1065
|
+
group_id: Number(n.group?.groupCode ?? 0),
|
|
1066
|
+
notification_seq: Number(n.seq),
|
|
1067
|
+
target_user_id: uinOf(n.user1?.uid),
|
|
1068
|
+
is_set: isSet,
|
|
1069
|
+
operator_id: uinOf(n.user2?.uid)
|
|
1118
1070
|
};
|
|
1119
1071
|
}
|
|
1120
|
-
/**
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
});
|
|
1130
|
-
return Number(uins?.get(uid)) || 0;
|
|
1072
|
+
/** kick 实体(9/10 共用)。 */
|
|
1073
|
+
function kickEntity(n, uinOf) {
|
|
1074
|
+
return {
|
|
1075
|
+
type: "kick",
|
|
1076
|
+
group_id: Number(n.group?.groupCode ?? 0),
|
|
1077
|
+
notification_seq: Number(n.seq),
|
|
1078
|
+
target_user_id: uinOf(n.user1?.uid),
|
|
1079
|
+
operator_id: uinOf(n.user2?.uid)
|
|
1080
|
+
};
|
|
1131
1081
|
}
|
|
1132
|
-
/**
|
|
1133
|
-
function
|
|
1134
|
-
const
|
|
1135
|
-
|
|
1082
|
+
/** GroupNotify → 实体(isFiltered 透传给 join_request;未识别类型 null)。 */
|
|
1083
|
+
function notifyToEntity(notify, isFiltered, uidToUin) {
|
|
1084
|
+
const uinOf = (uid) => uid === void 0 || uid === "" ? 0 : Number(uidToUin.get(uid) ?? 0) || 0;
|
|
1085
|
+
const builder = NOTIFY_ENTITY_BUILDERS[notify.type];
|
|
1086
|
+
if (builder === void 0) return null;
|
|
1087
|
+
const entity = builder(notify, uinOf);
|
|
1088
|
+
if (entity.type === "join_request") entity.is_filtered = isFiltered;
|
|
1089
|
+
return entity;
|
|
1136
1090
|
}
|
|
1137
1091
|
// src/milky/helper/message/segments.ts
|
|
1138
1092
|
/**
|
|
1139
|
-
* Milky 消息段 ↔ canonical
|
|
1093
|
+
* Milky 消息段 ↔ canonical 元素转换(纯函数)
|
|
1140
1094
|
*
|
|
1141
1095
|
* 接收方向:canonical → IncomingSegment(规范 14 种中映射 12 种;market_face /
|
|
1142
1096
|
* markdown 无 canonical 对应(MFACE/MARKDOWN 原始元素形状未探测),unknown 一律
|
|
@@ -1278,7 +1232,7 @@ function fileToIncoming(el) {
|
|
|
1278
1232
|
};
|
|
1279
1233
|
}
|
|
1280
1234
|
/**
|
|
1281
|
-
* 合并转发 → forward
|
|
1235
|
+
* 合并转发 → forward 段。
|
|
1282
1236
|
* 接收方向 canonical 不承载 MULTI_FORWARD(kernel toCanonicalElement 无此分支),
|
|
1283
1237
|
* 由 adapter 从 RawMessage 提取 resId 后调用本函数经 ctx 注入(翻译保持纯函数)。
|
|
1284
1238
|
* title 取 NT fileName(转发卡片标题语义)。
|
|
@@ -1319,7 +1273,7 @@ function rawToPayload(raw) {
|
|
|
1319
1273
|
* OutgoingSegment 数组 → canonical 元素(同步映射;媒体 URI 解析与 at uin→uid
|
|
1320
1274
|
* 由调用方在返回值上继续处理)。
|
|
1321
1275
|
* forward 在此报错:顶层 forward 已由 sendMilkyMessage 分流到组装链(message.ts,
|
|
1322
|
-
|
|
1276
|
+
*),命中本分支 = forward 与其他段混发漏网或嵌套 forward(组装链内逐项
|
|
1323
1277
|
* 转换经过此处)——均显式拒绝。
|
|
1324
1278
|
*/
|
|
1325
1279
|
function outgoingSegmentsToCanonical(segments) {
|
|
@@ -1415,9 +1369,9 @@ function fileUriToPath(uri) {
|
|
|
1415
1369
|
}
|
|
1416
1370
|
// src/milky/helper/event/translate.ts
|
|
1417
1371
|
/**
|
|
1418
|
-
* Milky 事件翻译(RawMessage → Milky
|
|
1372
|
+
* Milky 事件翻译(RawMessage → Milky 事件,纯函数)
|
|
1419
1373
|
*
|
|
1420
|
-
*
|
|
1374
|
+
* 事件两种:message_receive(onRecvMsg)/ message_recall(grayTip REVOKE)。
|
|
1421
1375
|
* 实体与 reply 回填在广播路径异步取得后经 ctx 注入(翻译保持纯函数);
|
|
1422
1376
|
* 撤回事件的 sender_id 取 RawMessage.senderUin(grayTip 系统消息的 sender
|
|
1423
1377
|
* 即被撤回原消息的发送者,口径待真实事件校准)。
|
|
@@ -1529,171 +1483,173 @@ const peerMessageFields = {
|
|
|
1529
1483
|
peer_id: z.number().int().min(10001),
|
|
1530
1484
|
message_seq: z.number().int().min(0)
|
|
1531
1485
|
};
|
|
1532
|
-
/** get_message:获取单条消息(seq → msgId 反查 + 实体回填)。 */
|
|
1533
|
-
var GetMessageAction = class extends MilkyApiAction {
|
|
1534
|
-
name = "get_message";
|
|
1535
|
-
schema = z.object({ ...peerMessageFields });
|
|
1536
|
-
async _handle(payload) {
|
|
1537
|
-
const peer = await this.api.resolvePeer(payload.message_scene, payload.peer_id);
|
|
1538
|
-
const msgId = await this.api.resolveMsgIdBySeq(peer, payload.message_seq, peer.chatType);
|
|
1539
|
-
if (msgId === void 0) throw kernelError(`消息 ${payload.message_seq} 不存在`, "NOT_FOUND");
|
|
1540
|
-
const [msg] = await this.api.msgApi.fetchMsgsByMsgId(peer, [msgId]);
|
|
1541
|
-
if (msg === void 0) throw kernelError(`消息 ${payload.message_seq} 不存在`, "NOT_FOUND");
|
|
1542
|
-
return { message: await this.translateWithEntities(payload.message_scene, peer, msg) };
|
|
1543
|
-
}
|
|
1544
|
-
/** 实体回填(group 场景 schema 要求完整实体)→ IncomingMessage。 */
|
|
1545
|
-
async translateWithEntities(scene, peer, msg) {
|
|
1546
|
-
const ctx = { selfUin: this.api.self.uin };
|
|
1547
|
-
if (scene === "group") {
|
|
1548
|
-
const [detail, member] = await Promise.all([this.api.groupCache?.getGroupDetail(peer.peerUid).catch((err) => {
|
|
1549
|
-
this.api.logger?.warn({
|
|
1550
|
-
group: peer.peerUid,
|
|
1551
|
-
error: err instanceof Error ? err.message : String(err)
|
|
1552
|
-
}, "milky: 群详情缓存读取失败,实体回填退化");
|
|
1553
|
-
}), this.api.groupCache?.getMember(peer.peerUid, msg.senderUid).catch((err) => {
|
|
1554
|
-
this.api.logger?.debug({
|
|
1555
|
-
group: peer.peerUid,
|
|
1556
|
-
member: msg.senderUid,
|
|
1557
|
-
error: err instanceof Error ? err.message : String(err)
|
|
1558
|
-
}, "milky: 群成员缓存读取失败,实体回填退化");
|
|
1559
|
-
})]);
|
|
1560
|
-
ctx.groupEntity = toGroupEntity(detail, peer.peerUid);
|
|
1561
|
-
ctx.groupMemberEntity = toGroupMemberEntity(member, peer.peerUid, msg.senderUin);
|
|
1562
|
-
}
|
|
1563
|
-
return toMessageReceiveEvent(msg, ctx).data;
|
|
1564
|
-
}
|
|
1565
|
-
};
|
|
1566
1486
|
/** 历史消息默认条数(规范 default 20)。 */
|
|
1567
1487
|
const HISTORY_DEFAULT_LIMIT = 20;
|
|
1568
|
-
/**
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1488
|
+
/** 消息查询域动作工厂(get_message / get_history_messages / get_forwarded_messages)。 */
|
|
1489
|
+
function createMessageQueryActions(api) {
|
|
1490
|
+
return [
|
|
1491
|
+
defineMilkyAction({
|
|
1492
|
+
name: "get_message",
|
|
1493
|
+
schema: z.object({ ...peerMessageFields }),
|
|
1494
|
+
handle: async (payload) => {
|
|
1495
|
+
const peer = await api.resolvePeer(payload.message_scene, payload.peer_id);
|
|
1496
|
+
const msgId = await api.resolveMsgIdBySeq(peer, payload.message_seq, peer.chatType);
|
|
1497
|
+
if (msgId === void 0) throw kernelError(`消息 ${payload.message_seq} 不存在`, "NOT_FOUND");
|
|
1498
|
+
const [msg] = await api.msgApi.fetchMsgsByMsgId(peer, [msgId]);
|
|
1499
|
+
if (msg === void 0) throw kernelError(`消息 ${payload.message_seq} 不存在`, "NOT_FOUND");
|
|
1500
|
+
return { message: await translateWithEntities(api, payload.message_scene, peer, msg) };
|
|
1501
|
+
}
|
|
1502
|
+
}),
|
|
1503
|
+
defineMilkyAction({
|
|
1504
|
+
name: "get_history_messages",
|
|
1505
|
+
schema: z.object({
|
|
1506
|
+
message_scene: z.enum([
|
|
1507
|
+
"friend",
|
|
1508
|
+
"group",
|
|
1509
|
+
"temp"
|
|
1510
|
+
]),
|
|
1511
|
+
peer_id: z.number().int().min(10001),
|
|
1512
|
+
start_message_seq: z.number().int().min(0).nullable().optional(),
|
|
1513
|
+
limit: z.number().int().min(0).nullable().optional()
|
|
1514
|
+
}),
|
|
1515
|
+
handle: async (payload) => {
|
|
1516
|
+
const limit = payload.limit ?? HISTORY_DEFAULT_LIMIT;
|
|
1517
|
+
const peer = await api.resolvePeer(payload.message_scene, payload.peer_id);
|
|
1518
|
+
const anchor = await resolveAnchor(api, peer, payload.start_message_seq);
|
|
1519
|
+
const msgs = await api.msgApi.fetchMessages(peer, {
|
|
1520
|
+
count: limit,
|
|
1521
|
+
...anchor !== void 0 ? { msgId: anchor } : {}
|
|
1522
|
+
});
|
|
1523
|
+
for (const m of msgs) api.seqIndex.record(m);
|
|
1524
|
+
const groupData = payload.message_scene === "group" ? await loadGroupData(api, peer.peerUid) : null;
|
|
1525
|
+
const ordered = [...msgs].reverse();
|
|
1526
|
+
const messages = ordered.map((m) => translateHistoryMessage(api, m, peer.peerUid, groupData));
|
|
1527
|
+
const hasMore = msgs.length >= limit;
|
|
1528
|
+
const oldest = ordered[0];
|
|
1529
|
+
return {
|
|
1530
|
+
messages,
|
|
1531
|
+
next_message_seq: hasMore && oldest !== void 0 ? Number(oldest.msgSeq) : null
|
|
1532
|
+
};
|
|
1533
|
+
}
|
|
1534
|
+
}),
|
|
1535
|
+
defineMilkyAction({
|
|
1536
|
+
name: "get_forwarded_messages",
|
|
1537
|
+
schema: z.object({ forward_id: z.string().min(1) }),
|
|
1538
|
+
handle: async (payload) => {
|
|
1539
|
+
const entry = api.seqIndex.resolveForward(payload.forward_id);
|
|
1540
|
+
if (entry === void 0) throw kernelError(`转发消息 ${payload.forward_id} 不存在(未登记)`, "NOT_FOUND");
|
|
1541
|
+
const peer = {
|
|
1542
|
+
chatType: entry.chatType,
|
|
1543
|
+
peerUid: entry.peerUid
|
|
1544
|
+
};
|
|
1545
|
+
const msgs = await api.msgApi.fetchForwardMessage(peer, entry.msgId);
|
|
1546
|
+
for (const m of msgs) api.seqIndex.record(m);
|
|
1547
|
+
const uidToUin = await collectUidToUin(api, msgs);
|
|
1548
|
+
const messages = [];
|
|
1549
|
+
for (const m of msgs) messages.push({
|
|
1550
|
+
message_seq: Number(m.msgSeq),
|
|
1551
|
+
sender_name: await senderNameOf(api, m),
|
|
1552
|
+
avatar_url: avatarUrlOf(m.senderUin),
|
|
1553
|
+
time: Math.floor(Number(m.msgTime) / 1e3),
|
|
1554
|
+
segments: receiveSegmentsOf(m, uidToUin)
|
|
1555
|
+
});
|
|
1556
|
+
return { messages };
|
|
1557
|
+
}
|
|
1558
|
+
})
|
|
1559
|
+
];
|
|
1560
|
+
}
|
|
1561
|
+
/** ---------- 内部辅助 ---------- */
|
|
1562
|
+
/** 实体回填(group 场景 schema 要求完整实体)→ IncomingMessage。 */
|
|
1563
|
+
async function translateWithEntities(api, scene, peer, msg) {
|
|
1564
|
+
const ctx = { selfUin: api.self.uin };
|
|
1565
|
+
if (scene === "group") {
|
|
1566
|
+
const [detail, member] = await Promise.all([api.groupCache?.getGroupDetail(peer.peerUid).catch((err) => {
|
|
1567
|
+
api.logger?.warn({
|
|
1568
|
+
group: peer.peerUid,
|
|
1616
1569
|
error: err instanceof Error ? err.message : String(err)
|
|
1617
|
-
}, "milky:
|
|
1618
|
-
}),
|
|
1619
|
-
|
|
1620
|
-
group:
|
|
1570
|
+
}, "milky: 群详情缓存读取失败,实体回填退化");
|
|
1571
|
+
}), api.groupCache?.getMember(peer.peerUid, msg.senderUid).catch((err) => {
|
|
1572
|
+
api.logger?.debug({
|
|
1573
|
+
group: peer.peerUid,
|
|
1574
|
+
member: msg.senderUid,
|
|
1621
1575
|
error: err instanceof Error ? err.message : String(err)
|
|
1622
|
-
}, "milky:
|
|
1623
|
-
return [];
|
|
1576
|
+
}, "milky: 群成员缓存读取失败,实体回填退化");
|
|
1624
1577
|
})]);
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1578
|
+
ctx.groupEntity = toGroupEntity(detail, peer.peerUid);
|
|
1579
|
+
ctx.groupMemberEntity = toGroupMemberEntity(member, peer.peerUid, msg.senderUin);
|
|
1580
|
+
}
|
|
1581
|
+
return toMessageReceiveEvent(msg, ctx).data;
|
|
1582
|
+
}
|
|
1583
|
+
/** start_message_seq → 锚点 msgId(给了 seq 却反查不到 = NOT_FOUND)。 */
|
|
1584
|
+
async function resolveAnchor(api, peer, startSeq) {
|
|
1585
|
+
if (startSeq === void 0 || startSeq === null) return;
|
|
1586
|
+
const msgId = await api.resolveMsgIdBySeq(peer, startSeq, peer.chatType);
|
|
1587
|
+
if (msgId === void 0) throw kernelError(`起始消息 ${startSeq} 不存在`, "NOT_FOUND");
|
|
1588
|
+
return msgId;
|
|
1589
|
+
}
|
|
1590
|
+
/** 群场景回填数据(详情 + 成员表;缓存未装配返回空数据)。 */
|
|
1591
|
+
async function loadGroupData(api, groupCode) {
|
|
1592
|
+
if (api.groupCache === void 0) return {
|
|
1593
|
+
detail: void 0,
|
|
1594
|
+
members: /* @__PURE__ */ new Map()
|
|
1595
|
+
};
|
|
1596
|
+
const [detail, members] = await Promise.all([api.groupCache.getGroupDetail(groupCode).catch((err) => {
|
|
1597
|
+
api.logger?.warn({
|
|
1598
|
+
group: groupCode,
|
|
1599
|
+
error: err instanceof Error ? err.message : String(err)
|
|
1600
|
+
}, "milky: 群详情缓存读取失败,历史翻译退化");
|
|
1601
|
+
}), api.groupCache.getMembers(groupCode).catch((err) => {
|
|
1602
|
+
api.logger?.warn({
|
|
1603
|
+
group: groupCode,
|
|
1604
|
+
error: err instanceof Error ? err.message : String(err)
|
|
1605
|
+
}, "milky: 群成员表缓存读取失败,历史翻译退化");
|
|
1606
|
+
return [];
|
|
1607
|
+
})]);
|
|
1608
|
+
const memberByUid = /* @__PURE__ */ new Map();
|
|
1609
|
+
for (const m of members) memberByUid.set(m.uid, m);
|
|
1610
|
+
return {
|
|
1611
|
+
detail,
|
|
1612
|
+
members: memberByUid
|
|
1613
|
+
};
|
|
1614
|
+
}
|
|
1615
|
+
/** 单条历史消息 → IncomingMessage(群场景注入实体,fail-soft)。 */
|
|
1616
|
+
function translateHistoryMessage(api, msg, peerUid, groupData) {
|
|
1617
|
+
const ctx = { selfUin: api.self.uin };
|
|
1618
|
+
if (groupData !== null) {
|
|
1619
|
+
if (groupData.detail !== void 0) ctx.groupEntity = toGroupEntity(groupData.detail, peerUid);
|
|
1620
|
+
const member = groupData.members.get(msg.senderUid);
|
|
1621
|
+
if (member !== void 0) ctx.groupMemberEntity = toGroupMemberEntity(member, peerUid, msg.senderUin);
|
|
1641
1622
|
}
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
};
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
});
|
|
1665
|
-
return { messages };
|
|
1666
|
-
}
|
|
1667
|
-
/** at 段 uid → uin 批量转换(mention 翻译;失败退空 Map)。 */
|
|
1668
|
-
async collectUidToUin(msgs) {
|
|
1669
|
-
const uids = /* @__PURE__ */ new Set();
|
|
1670
|
-
for (const m of msgs) for (const el of toCanonicalElements(m)) if (el.type === "at" && el.target !== "all") uids.add(el.target);
|
|
1671
|
-
if (uids.size === 0) return /* @__PURE__ */ new Map();
|
|
1672
|
-
return await this.api.uidToUin([...uids]).catch((err) => {
|
|
1673
|
-
this.api.logger?.warn({
|
|
1674
|
-
count: uids.size,
|
|
1623
|
+
return toMessageReceiveEvent(msg, ctx).data;
|
|
1624
|
+
}
|
|
1625
|
+
/** at 段 uid → uin 批量转换(mention 翻译;失败退空 Map)。 */
|
|
1626
|
+
async function collectUidToUin(api, msgs) {
|
|
1627
|
+
const uids = /* @__PURE__ */ new Set();
|
|
1628
|
+
for (const m of msgs) for (const el of toCanonicalElements(m)) if (el.type === "at" && el.target !== "all") uids.add(el.target);
|
|
1629
|
+
if (uids.size === 0) return /* @__PURE__ */ new Map();
|
|
1630
|
+
return await api.uidToUin([...uids]).catch((err) => {
|
|
1631
|
+
api.logger?.warn({
|
|
1632
|
+
count: uids.size,
|
|
1633
|
+
error: err instanceof Error ? err.message : String(err)
|
|
1634
|
+
}, "milky: 历史 at uid→uin 失败,mention 段跳过");
|
|
1635
|
+
return /* @__PURE__ */ new Map();
|
|
1636
|
+
});
|
|
1637
|
+
}
|
|
1638
|
+
/** 发送者名(群场景成员缓存昵称/名片,失败退 uin 字符串)。 */
|
|
1639
|
+
async function senderNameOf(api, msg) {
|
|
1640
|
+
if (api.groupCache !== void 0 && msg.chatType === ChatType.GROUP) {
|
|
1641
|
+
const member = await api.groupCache.getMember(msg.peerUid, msg.senderUid).catch((err) => {
|
|
1642
|
+
api.logger?.debug({
|
|
1643
|
+
group: msg.peerUid,
|
|
1644
|
+
member: msg.senderUid,
|
|
1675
1645
|
error: err instanceof Error ? err.message : String(err)
|
|
1676
|
-
}, "milky:
|
|
1677
|
-
return /* @__PURE__ */ new Map();
|
|
1646
|
+
}, "milky: 发送者成员缓存读取失败,退 uin 字符串");
|
|
1678
1647
|
});
|
|
1648
|
+
const name = member?.cardName !== void 0 && member.cardName !== "" ? member.cardName : member?.nick;
|
|
1649
|
+
if (name !== void 0 && name !== "") return name;
|
|
1679
1650
|
}
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
if (this.api.groupCache !== void 0 && msg.chatType === ChatType.GROUP) {
|
|
1683
|
-
const member = await this.api.groupCache.getMember(msg.peerUid, msg.senderUid).catch((err) => {
|
|
1684
|
-
this.api.logger?.debug({
|
|
1685
|
-
group: msg.peerUid,
|
|
1686
|
-
member: msg.senderUid,
|
|
1687
|
-
error: err instanceof Error ? err.message : String(err)
|
|
1688
|
-
}, "milky: 发送者成员缓存读取失败,退 uin 字符串");
|
|
1689
|
-
});
|
|
1690
|
-
const name = member?.cardName !== void 0 && member.cardName !== "" ? member.cardName : member?.nick;
|
|
1691
|
-
if (name !== void 0 && name !== "") return name;
|
|
1692
|
-
}
|
|
1693
|
-
return msg.senderUin;
|
|
1694
|
-
}
|
|
1695
|
-
};
|
|
1696
|
-
/** ---------- 内部辅助 ---------- */
|
|
1651
|
+
return msg.senderUin;
|
|
1652
|
+
}
|
|
1697
1653
|
/** 单条消息 → 接收段(canonical 映射 + forward 段注入,forward 不经 canonical)。 */
|
|
1698
1654
|
function receiveSegmentsOf(msg, uidToUin) {
|
|
1699
1655
|
const segments = canonicalToIncomingSegments(toCanonicalElements(msg), { ...uidToUin.size > 0 ? { uidToUin } : {} });
|
|
@@ -1707,86 +1663,75 @@ function avatarUrlOf(uin) {
|
|
|
1707
1663
|
}
|
|
1708
1664
|
// src/milky/action/message-ops.ts
|
|
1709
1665
|
const recallFields = { message_seq: z.number().int().min(0) };
|
|
1710
|
-
/**
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
};
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
}
|
|
1666
|
+
/** 消息操作域动作工厂(recall×2 / mark_read / 收藏表情 / 资源反查 / 私聊文件上传)。 */
|
|
1667
|
+
function createMessageOpsActions(api) {
|
|
1668
|
+
return [
|
|
1669
|
+
defineMilkyAction({
|
|
1670
|
+
name: "recall_private_message",
|
|
1671
|
+
schema: z.object({
|
|
1672
|
+
user_id: z.number().int().min(10001),
|
|
1673
|
+
...recallFields
|
|
1674
|
+
}),
|
|
1675
|
+
handle: async (payload) => {
|
|
1676
|
+
await recallBySeq(await api.resolvePeer("friend", payload.user_id), payload.message_seq, api);
|
|
1677
|
+
return {};
|
|
1678
|
+
}
|
|
1679
|
+
}),
|
|
1680
|
+
defineMilkyAction({
|
|
1681
|
+
name: "recall_group_message",
|
|
1682
|
+
schema: z.object({
|
|
1683
|
+
group_id: z.number().int().min(10001),
|
|
1684
|
+
...recallFields
|
|
1685
|
+
}),
|
|
1686
|
+
handle: async (payload) => {
|
|
1687
|
+
await recallBySeq(await api.resolvePeer("group", payload.group_id), payload.message_seq, api);
|
|
1688
|
+
return {};
|
|
1689
|
+
}
|
|
1690
|
+
}),
|
|
1691
|
+
defineMilkyAction({
|
|
1692
|
+
name: "mark_message_as_read",
|
|
1693
|
+
schema: z.object({ ...peerMessageFields }),
|
|
1694
|
+
handle: async (payload) => {
|
|
1695
|
+
const peer = await api.resolvePeer(payload.message_scene, payload.peer_id);
|
|
1696
|
+
await api.msgApi.markRead(peer);
|
|
1697
|
+
return {};
|
|
1698
|
+
}
|
|
1699
|
+
}),
|
|
1700
|
+
defineMilkyAction({
|
|
1701
|
+
name: "get_custom_face_url_list",
|
|
1702
|
+
schema: z.object({}),
|
|
1703
|
+
handle: async () => ({ urls: await api.msgApi.queryFavEmojis() })
|
|
1704
|
+
}),
|
|
1705
|
+
defineMilkyAction({
|
|
1706
|
+
name: "get_resource_temp_url",
|
|
1707
|
+
schema: z.object({ resource_id: z.string().min(1) }),
|
|
1708
|
+
handle: async (payload) => {
|
|
1709
|
+
const id = payload.resource_id;
|
|
1710
|
+
if (id.startsWith("http://") || id.startsWith("https://") || id.startsWith("base64://")) return { url: id };
|
|
1711
|
+
throw kernelError(`资源 ${id} 无临时链接(resource_id 非链接形态)`, "NOT_FOUND");
|
|
1712
|
+
}
|
|
1713
|
+
}),
|
|
1714
|
+
defineMilkyAction({
|
|
1715
|
+
name: "upload_private_file",
|
|
1716
|
+
schema: z.object({
|
|
1717
|
+
user_id: z.number().int().min(10001),
|
|
1718
|
+
file_uri: z.string().min(1),
|
|
1719
|
+
file_name: z.string().min(1)
|
|
1720
|
+
}),
|
|
1721
|
+
handle: async (payload) => {
|
|
1722
|
+
const path = await resolveUriToPath(payload.file_uri, api.mediaDir);
|
|
1723
|
+
const peer = await api.resolvePeer("friend", payload.user_id);
|
|
1724
|
+
return { file_id: (await api.flashTransferApi.sendFile(peer, [path], { name: payload.file_name })).fileSetId };
|
|
1725
|
+
}
|
|
1726
|
+
})
|
|
1727
|
+
];
|
|
1728
|
+
}
|
|
1734
1729
|
/** seq → msgId(反查)→ recallMessage。 */
|
|
1735
1730
|
async function recallBySeq(peer, seq, api) {
|
|
1736
1731
|
const msgId = await api.resolveMsgIdBySeq(peer, seq, peer.chatType);
|
|
1737
1732
|
if (msgId === void 0) throw kernelError(`消息 ${seq} 不存在`, "NOT_FOUND");
|
|
1738
1733
|
await api.msgApi.recallMessage(peer, [msgId]);
|
|
1739
1734
|
}
|
|
1740
|
-
/** mark_message_as_read:标记会话已读(NT setMsgRead 以会话为粒度,seq 入参仅兼容 schema)。 */
|
|
1741
|
-
var MarkMessageAsReadAction = class extends MilkyApiAction {
|
|
1742
|
-
name = "mark_message_as_read";
|
|
1743
|
-
schema = z.object({ ...peerMessageFields });
|
|
1744
|
-
async _handle(payload) {
|
|
1745
|
-
const peer = await this.api.resolvePeer(payload.message_scene, payload.peer_id);
|
|
1746
|
-
await this.api.msgApi.markRead(peer);
|
|
1747
|
-
return {};
|
|
1748
|
-
}
|
|
1749
|
-
};
|
|
1750
|
-
/** get_custom_face_url_list:收藏表情链接(queryFavEmojiByDesc 形状待校准)。 */
|
|
1751
|
-
var GetCustomFaceUrlListAction = class extends MilkyApiAction {
|
|
1752
|
-
name = "get_custom_face_url_list";
|
|
1753
|
-
schema = z.object({});
|
|
1754
|
-
async _handle() {
|
|
1755
|
-
return { urls: await this.api.msgApi.queryFavEmojis() };
|
|
1756
|
-
}
|
|
1757
|
-
};
|
|
1758
|
-
/**
|
|
1759
|
-
* get_resource_temp_url:资源临时链接。
|
|
1760
|
-
* 已知差异(P0 模型):接收段 resource_id 即临时链接(本地路径优先 url 兜底),
|
|
1761
|
-
* 无独立资源索引——http(s)/base64 形态原样返回,其余 NOT_FOUND。
|
|
1762
|
-
*/
|
|
1763
|
-
var GetResourceTempUrlAction = class extends MilkyApiAction {
|
|
1764
|
-
name = "get_resource_temp_url";
|
|
1765
|
-
schema = z.object({ resource_id: z.string().min(1) });
|
|
1766
|
-
async _handle(payload) {
|
|
1767
|
-
const id = payload.resource_id;
|
|
1768
|
-
if (id.startsWith("http://") || id.startsWith("https://") || id.startsWith("base64://")) return { url: id };
|
|
1769
|
-
throw kernelError(`资源 ${id} 无临时链接(resource_id 非链接形态)`, "NOT_FOUND");
|
|
1770
|
-
}
|
|
1771
|
-
};
|
|
1772
|
-
/**
|
|
1773
|
-
* upload_private_file:上传并投递私聊文件(**闪传通道**:分享链接卡片)。
|
|
1774
|
-
* file_id 返回闪传文件集 id(非文件消息 fileUuid)。语义降级同 upload_group_file:
|
|
1775
|
-
* 对端收到的是分享链接卡片而不是 fileElement 文件消息(kernel design §15)。
|
|
1776
|
-
*/
|
|
1777
|
-
var UploadPrivateFileAction = class extends MilkyApiAction {
|
|
1778
|
-
name = "upload_private_file";
|
|
1779
|
-
schema = z.object({
|
|
1780
|
-
user_id: z.number().int().min(10001),
|
|
1781
|
-
file_uri: z.string().min(1),
|
|
1782
|
-
file_name: z.string().min(1)
|
|
1783
|
-
});
|
|
1784
|
-
async _handle(payload) {
|
|
1785
|
-
const path = await resolveUriToPath(payload.file_uri, this.api.mediaDir);
|
|
1786
|
-
const peer = await this.api.resolvePeer("friend", payload.user_id);
|
|
1787
|
-
return { file_id: (await this.api.flashTransferApi.sendFile(peer, [path], { name: payload.file_name })).fileSetId };
|
|
1788
|
-
}
|
|
1789
|
-
};
|
|
1790
1735
|
// src/milky/action/message-send.ts
|
|
1791
1736
|
/**
|
|
1792
1737
|
* OutgoingSegment 宽松校验:入口只保证「{type, data}」形状,字段级转换在
|
|
@@ -1797,31 +1742,31 @@ const outgoingSegmentSchema = z.object({
|
|
|
1797
1742
|
data: z.record(z.string(), z.unknown())
|
|
1798
1743
|
}).loose();
|
|
1799
1744
|
const sendMessageFields = { message: z.array(outgoingSegmentSchema).min(1).max(200) };
|
|
1800
|
-
/** send_private_message
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
}
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
}
|
|
1821
|
-
}
|
|
1745
|
+
/** 消息发送域动作工厂(send_private_message / send_group_message)。 */
|
|
1746
|
+
function createMessageSendActions(api) {
|
|
1747
|
+
return [defineMilkyAction({
|
|
1748
|
+
name: "send_private_message",
|
|
1749
|
+
schema: z.object({
|
|
1750
|
+
user_id: z.number().int().min(10001),
|
|
1751
|
+
...sendMessageFields
|
|
1752
|
+
}),
|
|
1753
|
+
handle: async (payload) => {
|
|
1754
|
+
return await sendMilkyMessage(await api.resolvePeer("friend", payload.user_id), payload.message, api);
|
|
1755
|
+
}
|
|
1756
|
+
}), defineMilkyAction({
|
|
1757
|
+
name: "send_group_message",
|
|
1758
|
+
schema: z.object({
|
|
1759
|
+
group_id: z.number().int().min(10001),
|
|
1760
|
+
...sendMessageFields
|
|
1761
|
+
}),
|
|
1762
|
+
handle: async (payload) => {
|
|
1763
|
+
return await sendMilkyMessage(await api.resolvePeer("group", payload.group_id), payload.message, api);
|
|
1764
|
+
}
|
|
1765
|
+
})];
|
|
1766
|
+
}
|
|
1822
1767
|
/** ---------- 发送核心与组装链 ---------- */
|
|
1823
1768
|
/** 发送核心:segments → canonical(URI/ID 转换)→ sendMessage → 回查输出。
|
|
1824
|
-
* forward
|
|
1769
|
+
* forward 段分流到组装链(临时消息法)。 */
|
|
1825
1770
|
async function sendMilkyMessage(peer, segments, api) {
|
|
1826
1771
|
if (segments.some((s) => s.type === "forward")) return await sendForwardComposition(peer, segments, api);
|
|
1827
1772
|
const { elements, atUins } = outgoingSegmentsToCanonical(segments);
|
|
@@ -1831,7 +1776,7 @@ async function sendMilkyMessage(peer, segments, api) {
|
|
|
1831
1776
|
return await api.resolveSentOutput(peer, msgId);
|
|
1832
1777
|
}
|
|
1833
1778
|
/**
|
|
1834
|
-
* forward 段组装链(
|
|
1779
|
+
* forward 段组装链(milky.md §0.6):仅支持单 forward 单独发。
|
|
1835
1780
|
* 临时消息法:逐条发送 messages[i].segments → sendForwardMessage(buildMultiForwardMsg
|
|
1836
1781
|
* 以目标 peer 的真实消息组装 → sendMsg)→ best-effort 撤回临时消息 → 回查输出。
|
|
1837
1782
|
*
|
|
@@ -1926,8 +1871,8 @@ function isRemoteMediaUri(el) {
|
|
|
1926
1871
|
}
|
|
1927
1872
|
// src/milky/action/profile.ts
|
|
1928
1873
|
/**
|
|
1929
|
-
* Milky
|
|
1930
|
-
* set_nickname / set_bio / get_cookies / get_csrf_token
|
|
1874
|
+
* Milky 资料类动作:get_user_profile / get_friend_info / set_avatar /
|
|
1875
|
+
* set_nickname / set_bio / get_cookies / get_csrf_token。
|
|
1931
1876
|
*
|
|
1932
1877
|
* set_avatar 的 uri 经 media-uri 解析(本地路径 / file:// 直用,http(s)/base64
|
|
1933
1878
|
* 落盘 mediaDir);get_cookies 输出规范为单字符串(k=v 分号拼接);
|
|
@@ -1935,242 +1880,229 @@ function isRemoteMediaUri(el) {
|
|
|
1935
1880
|
*/
|
|
1936
1881
|
/** CSRF 计算域名(bkn 口径,OB11 get_csrf_token 同源)。 */
|
|
1937
1882
|
const CSRF_DOMAIN = "qun.qq.com";
|
|
1938
|
-
/**
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
};
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
}
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
}
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
}
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
}
|
|
2017
|
-
};
|
|
1883
|
+
/** 资料类动作工厂(资料读取 / 头像昵称签名设置 / cookies 与 bkn)。 */
|
|
1884
|
+
function createProfileActions(api) {
|
|
1885
|
+
return [
|
|
1886
|
+
defineMilkyAction({
|
|
1887
|
+
name: "get_user_profile",
|
|
1888
|
+
schema: z.object({ user_id: z.number().int().min(10001) }),
|
|
1889
|
+
handle: async (payload) => {
|
|
1890
|
+
const info = await api.profileApi.getStrangerInfo(String(payload.user_id));
|
|
1891
|
+
return {
|
|
1892
|
+
nickname: info.nickname,
|
|
1893
|
+
qid: info.qid,
|
|
1894
|
+
age: info.age,
|
|
1895
|
+
sex: info.sex,
|
|
1896
|
+
remark: info.remark,
|
|
1897
|
+
bio: info.long_nick,
|
|
1898
|
+
level: info.qq_level,
|
|
1899
|
+
country: "",
|
|
1900
|
+
city: "",
|
|
1901
|
+
school: ""
|
|
1902
|
+
};
|
|
1903
|
+
}
|
|
1904
|
+
}),
|
|
1905
|
+
defineMilkyAction({
|
|
1906
|
+
name: "get_friend_info",
|
|
1907
|
+
schema: z.object({
|
|
1908
|
+
user_id: z.number().int().min(10001),
|
|
1909
|
+
no_cache: z.boolean().nullable().optional()
|
|
1910
|
+
}),
|
|
1911
|
+
handle: async (payload) => {
|
|
1912
|
+
const uin = String(payload.user_id);
|
|
1913
|
+
const friend = (await api.friendApi.getFriendList()).find((f) => f.uin === uin);
|
|
1914
|
+
if (friend === void 0) throw kernelError(`好友 ${uin} 不存在`, "NOT_FOUND");
|
|
1915
|
+
return { friend: toFriendEntity(friend, friend.uin, friend.nickname) };
|
|
1916
|
+
}
|
|
1917
|
+
}),
|
|
1918
|
+
defineMilkyAction({
|
|
1919
|
+
name: "set_avatar",
|
|
1920
|
+
schema: z.object({ uri: z.string().min(1) }),
|
|
1921
|
+
handle: async (payload) => {
|
|
1922
|
+
const path = await resolveMediaUri(payload.uri, api.mediaDir);
|
|
1923
|
+
await api.profileApi.setHeader(path);
|
|
1924
|
+
return {};
|
|
1925
|
+
}
|
|
1926
|
+
}),
|
|
1927
|
+
defineMilkyAction({
|
|
1928
|
+
name: "set_nickname",
|
|
1929
|
+
schema: z.object({ new_nickname: z.string() }),
|
|
1930
|
+
handle: async (payload) => {
|
|
1931
|
+
await api.profileApi.setNickName(payload.new_nickname);
|
|
1932
|
+
return {};
|
|
1933
|
+
}
|
|
1934
|
+
}),
|
|
1935
|
+
defineMilkyAction({
|
|
1936
|
+
name: "set_bio",
|
|
1937
|
+
schema: z.object({ new_bio: z.string() }),
|
|
1938
|
+
handle: async (payload) => {
|
|
1939
|
+
await api.profileApi.setLongNick(payload.new_bio);
|
|
1940
|
+
return {};
|
|
1941
|
+
}
|
|
1942
|
+
}),
|
|
1943
|
+
defineMilkyAction({
|
|
1944
|
+
name: "get_cookies",
|
|
1945
|
+
schema: z.object({ domain: z.string().min(1) }),
|
|
1946
|
+
handle: async (payload) => {
|
|
1947
|
+
const cookies = await api.ticketApi.getCookies(payload.domain, api.self.uin);
|
|
1948
|
+
return { cookies: Object.entries(cookies).map(([k, v]) => `${k}=${v}`).join("; ") };
|
|
1949
|
+
}
|
|
1950
|
+
}),
|
|
1951
|
+
defineMilkyAction({
|
|
1952
|
+
name: "get_csrf_token",
|
|
1953
|
+
schema: z.object({}).strict(),
|
|
1954
|
+
handle: async () => {
|
|
1955
|
+
const cookies = await api.ticketApi.getCookies(CSRF_DOMAIN, api.self.uin);
|
|
1956
|
+
return { csrf_token: TicketApi.getBkn(cookies["skey"] ?? "") };
|
|
1957
|
+
}
|
|
1958
|
+
})
|
|
1959
|
+
];
|
|
1960
|
+
}
|
|
2018
1961
|
// src/milky/action/social.ts
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
}
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
}
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
}
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
"temp"
|
|
2164
|
-
]),
|
|
2165
|
-
peer_id: z.number().int().min(10001),
|
|
2166
|
-
is_pinned: optBoolNudge
|
|
2167
|
-
});
|
|
2168
|
-
async _handle(payload) {
|
|
2169
|
-
const peer = await this.api.resolvePeer(payload.message_scene, payload.peer_id);
|
|
2170
|
-
await this.api.msgApi.setContactTop(peer, payload.is_pinned ?? true);
|
|
2171
|
-
return {};
|
|
2172
|
-
}
|
|
2173
|
-
};
|
|
1962
|
+
/** 可选布尔(nudge / pin 入参共用口径)。 */
|
|
1963
|
+
const optBool = z.boolean().nullable().optional();
|
|
1964
|
+
/** 社交类动作工厂(好友/群列表、赞、删好友、申请处理、戳一戳、会话置顶)。 */
|
|
1965
|
+
function createSocialActions(api) {
|
|
1966
|
+
return [
|
|
1967
|
+
defineMilkyAction({
|
|
1968
|
+
name: "get_friend_list",
|
|
1969
|
+
schema: z.object({}).strict(),
|
|
1970
|
+
handle: async () => {
|
|
1971
|
+
return { friends: (await api.friendApi.getFriendList()).map((f) => toFriendEntity(f, f.uin, f.nickname)) };
|
|
1972
|
+
}
|
|
1973
|
+
}),
|
|
1974
|
+
defineMilkyAction({
|
|
1975
|
+
name: "get_group_list",
|
|
1976
|
+
schema: z.object({}).strict(),
|
|
1977
|
+
handle: async () => {
|
|
1978
|
+
return { groups: (api.groupCache !== void 0 ? await api.groupCache.listGroupsRefreshed() : await api.groupApi.getGroupList(true)).map(groupListToEntity) };
|
|
1979
|
+
}
|
|
1980
|
+
}),
|
|
1981
|
+
defineMilkyAction({
|
|
1982
|
+
name: "send_profile_like",
|
|
1983
|
+
schema: z.object({
|
|
1984
|
+
user_id: z.number().int().min(10001),
|
|
1985
|
+
count: z.number().int().min(0).nullable().optional()
|
|
1986
|
+
}),
|
|
1987
|
+
handle: async (payload) => {
|
|
1988
|
+
const uid = await api.resolveUidFromUin(payload.user_id);
|
|
1989
|
+
await api.profileLikeApi.sendLike(uid, payload.count ?? 1);
|
|
1990
|
+
return {};
|
|
1991
|
+
}
|
|
1992
|
+
}),
|
|
1993
|
+
defineMilkyAction({
|
|
1994
|
+
name: "delete_friend",
|
|
1995
|
+
schema: z.object({ user_id: z.number().int().min(10001) }),
|
|
1996
|
+
handle: async (payload) => {
|
|
1997
|
+
const uid = await api.resolveUidFromUin(payload.user_id);
|
|
1998
|
+
await api.friendApi.deleteFriend(uid);
|
|
1999
|
+
return {};
|
|
2000
|
+
}
|
|
2001
|
+
}),
|
|
2002
|
+
defineMilkyAction({
|
|
2003
|
+
name: "get_friend_requests",
|
|
2004
|
+
schema: z.object({
|
|
2005
|
+
limit: z.number().int().min(0).nullable().optional(),
|
|
2006
|
+
is_filtered: z.boolean().nullable().optional()
|
|
2007
|
+
}),
|
|
2008
|
+
handle: async (payload) => {
|
|
2009
|
+
const reqs = await api.friendApi.getBuddyReqList();
|
|
2010
|
+
let uidToUin = /* @__PURE__ */ new Map();
|
|
2011
|
+
if (reqs.length > 0) uidToUin = await api.uidToUin(reqs.map((req) => req.friendUid)).catch((err) => {
|
|
2012
|
+
api.logger?.warn({
|
|
2013
|
+
count: reqs.length,
|
|
2014
|
+
error: err instanceof Error ? err.message : String(err)
|
|
2015
|
+
}, "milky: 好友申请 uid→uin 失败,initiator_id 兜底 0");
|
|
2016
|
+
return /* @__PURE__ */ new Map();
|
|
2017
|
+
});
|
|
2018
|
+
const requests = reqs.map((req) => ({
|
|
2019
|
+
time: Number(req.reqTime) || 0,
|
|
2020
|
+
initiator_id: Number(uidToUin.get(req.friendUid)) || 0,
|
|
2021
|
+
initiator_uid: req.friendUid,
|
|
2022
|
+
target_user_id: Number(api.self.uin),
|
|
2023
|
+
target_user_uid: api.self.uid ?? "",
|
|
2024
|
+
state: "pending",
|
|
2025
|
+
comment: typeof req["words"] === "string" ? req["words"] : "",
|
|
2026
|
+
via: req.sourceName ?? "",
|
|
2027
|
+
is_filtered: false
|
|
2028
|
+
}));
|
|
2029
|
+
const limit = payload.limit ?? requests.length;
|
|
2030
|
+
return { requests: requests.slice(0, limit) };
|
|
2031
|
+
}
|
|
2032
|
+
}),
|
|
2033
|
+
defineMilkyAction({
|
|
2034
|
+
name: "accept_friend_request",
|
|
2035
|
+
schema: friendRequestRespondSchema,
|
|
2036
|
+
handle: async (payload) => {
|
|
2037
|
+
const notify = await findBuddyReq(api, payload.initiator_uid);
|
|
2038
|
+
await api.friendApi.handleFriendRequest(notify, true);
|
|
2039
|
+
return {};
|
|
2040
|
+
}
|
|
2041
|
+
}),
|
|
2042
|
+
defineMilkyAction({
|
|
2043
|
+
name: "reject_friend_request",
|
|
2044
|
+
schema: friendRequestRespondSchema,
|
|
2045
|
+
handle: async (payload) => {
|
|
2046
|
+
const notify = await findBuddyReq(api, payload.initiator_uid);
|
|
2047
|
+
await api.friendApi.handleFriendRequest(notify, false);
|
|
2048
|
+
return {};
|
|
2049
|
+
}
|
|
2050
|
+
}),
|
|
2051
|
+
defineMilkyAction({
|
|
2052
|
+
name: "send_friend_nudge",
|
|
2053
|
+
schema: z.object({
|
|
2054
|
+
user_id: z.number().int().min(10001),
|
|
2055
|
+
is_self: optBool
|
|
2056
|
+
}),
|
|
2057
|
+
handle: async (payload) => {
|
|
2058
|
+
const callerUid = requireSelfUid(api);
|
|
2059
|
+
const receiverUid = payload.is_self === true ? callerUid : await api.resolveUidFromUin(payload.user_id);
|
|
2060
|
+
const peer = await api.resolvePeer("friend", payload.user_id);
|
|
2061
|
+
await api.msgApi.sendNudge(peer, {
|
|
2062
|
+
receiverUid,
|
|
2063
|
+
callerUid
|
|
2064
|
+
});
|
|
2065
|
+
return {};
|
|
2066
|
+
}
|
|
2067
|
+
}),
|
|
2068
|
+
defineMilkyAction({
|
|
2069
|
+
name: "get_peer_pins",
|
|
2070
|
+
schema: z.object({}),
|
|
2071
|
+
handle: async () => {
|
|
2072
|
+
const pinned = await api.recentContactApi.getPinnedContacts();
|
|
2073
|
+
const friendUids = pinned.filter((p) => p.scene === "friend").map((p) => p.peerUid);
|
|
2074
|
+
const groupCodes = pinned.filter((p) => p.scene === "group").map((p) => p.peerUid);
|
|
2075
|
+
return {
|
|
2076
|
+
friends: await pinnedFriendEntities(api, friendUids),
|
|
2077
|
+
groups: await pinnedGroupEntities(api, groupCodes)
|
|
2078
|
+
};
|
|
2079
|
+
}
|
|
2080
|
+
}),
|
|
2081
|
+
defineMilkyAction({
|
|
2082
|
+
name: "set_peer_pin",
|
|
2083
|
+
schema: z.object({
|
|
2084
|
+
message_scene: z.enum([
|
|
2085
|
+
"friend",
|
|
2086
|
+
"group",
|
|
2087
|
+
"temp"
|
|
2088
|
+
]),
|
|
2089
|
+
peer_id: z.number().int().min(10001),
|
|
2090
|
+
is_pinned: optBool
|
|
2091
|
+
}),
|
|
2092
|
+
handle: async (payload) => {
|
|
2093
|
+
const peer = await api.resolvePeer(payload.message_scene, payload.peer_id);
|
|
2094
|
+
await api.msgApi.setContactTop(peer, payload.is_pinned ?? true);
|
|
2095
|
+
return {};
|
|
2096
|
+
}
|
|
2097
|
+
})
|
|
2098
|
+
];
|
|
2099
|
+
}
|
|
2100
|
+
/** accept/reject_friend_request 共入参(is_filtered / reason 仅 schema 兼容)。 */
|
|
2101
|
+
const friendRequestRespondSchema = z.object({
|
|
2102
|
+
initiator_uid: z.string().min(1),
|
|
2103
|
+
is_filtered: z.boolean().nullable().optional(),
|
|
2104
|
+
reason: z.string().nullable().optional()
|
|
2105
|
+
});
|
|
2174
2106
|
/** 置顶好友实体(uid 匹配全量好友列表;未命中跳过)。 */
|
|
2175
2107
|
async function pinnedFriendEntities(api, uids) {
|
|
2176
2108
|
if (uids.length === 0) return [];
|
|
@@ -2197,119 +2129,61 @@ function requireSelfUid(api) {
|
|
|
2197
2129
|
if (uid === void 0 || uid === "") throw kernelError("登录身份缺 uid(无法发起戳一戳)", "INVALID_PARAM");
|
|
2198
2130
|
return uid;
|
|
2199
2131
|
}
|
|
2200
|
-
/** 可选布尔(social.ts 本文件原无 optBool,本地定义避免全局重名)。 */
|
|
2201
|
-
const optBoolNudge = z.boolean().nullable().optional();
|
|
2202
2132
|
// src/milky/action/system.ts
|
|
2203
2133
|
/**
|
|
2204
|
-
* Milky
|
|
2134
|
+
* Milky 系统类动作:get_login_info / get_impl_info
|
|
2205
2135
|
*
|
|
2206
2136
|
* get_impl_info 是 Milky 的版本协商面(规范 §compatibility):milky_version
|
|
2207
2137
|
* 固定 "1.3"(目标协议版本 1.3.0),qq_protocol_type 固定 windows(自建宿主)。
|
|
2208
2138
|
*/
|
|
2209
2139
|
/** Milky 协议版本(docs/protocols/milky.md:目标 1.3.0)。 */
|
|
2210
2140
|
const MILKY_VERSION = "1.3";
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
}
|
|
2223
|
-
|
|
2224
|
-
var GetImplInfoAction = class extends MilkyApiAction {
|
|
2225
|
-
name = "get_impl_info";
|
|
2226
|
-
schema = emptySchema;
|
|
2227
|
-
async _handle() {
|
|
2228
|
-
return {
|
|
2141
|
+
/** 系统类动作工厂(login_info / impl_info)。 */
|
|
2142
|
+
function createSystemActions(api) {
|
|
2143
|
+
return [defineMilkyAction({
|
|
2144
|
+
name: "get_login_info",
|
|
2145
|
+
schema: z.object({}).strict(),
|
|
2146
|
+
handle: async () => ({
|
|
2147
|
+
uin: Number(api.self.uin),
|
|
2148
|
+
nickname: api.self.nickname
|
|
2149
|
+
})
|
|
2150
|
+
}), defineMilkyAction({
|
|
2151
|
+
name: "get_impl_info",
|
|
2152
|
+
schema: z.object({}).strict(),
|
|
2153
|
+
handle: async () => ({
|
|
2229
2154
|
impl_name: "napukettoqq",
|
|
2230
|
-
impl_version:
|
|
2231
|
-
qq_protocol_version:
|
|
2155
|
+
impl_version: api.implVersion,
|
|
2156
|
+
qq_protocol_version: api.qqVersion,
|
|
2232
2157
|
qq_protocol_type: "windows",
|
|
2233
2158
|
milky_version: MILKY_VERSION
|
|
2234
|
-
}
|
|
2235
|
-
}
|
|
2236
|
-
}
|
|
2159
|
+
})
|
|
2160
|
+
})];
|
|
2161
|
+
}
|
|
2237
2162
|
// src/milky/action/index.ts
|
|
2238
2163
|
/**
|
|
2239
|
-
* Milky
|
|
2164
|
+
* Milky 动作注册表:动作按领域文件组织(每文件一个 create*Actions 工厂),
|
|
2165
|
+
* 本入口按固定顺序遍历注册——新增动作在领域文件的工厂里登记即可。
|
|
2240
2166
|
*
|
|
2241
|
-
*
|
|
2242
|
-
* 头衔 / 群头像 / peer_pins / 上传 / download_url / rename_folder / 收藏表情 /
|
|
2243
|
-
* resource 反查)。
|
|
2167
|
+
* 64 动作 = docs/protocols/milky.md §9 清单全量。
|
|
2244
2168
|
*/
|
|
2245
|
-
/** Milky
|
|
2169
|
+
/** Milky 动作域工厂(注册顺序即列表顺序:system → message → social/profile → group)。 */
|
|
2170
|
+
const ACTION_FACTORIES = [
|
|
2171
|
+
createSystemActions,
|
|
2172
|
+
createMessageSendActions,
|
|
2173
|
+
createMessageQueryActions,
|
|
2174
|
+
createMessageOpsActions,
|
|
2175
|
+
createSocialActions,
|
|
2176
|
+
createProfileActions,
|
|
2177
|
+
createGroupQueryActions,
|
|
2178
|
+
createGroupManageActions,
|
|
2179
|
+
createGroupEssenceActions,
|
|
2180
|
+
createGroupNoticeActions,
|
|
2181
|
+
createGroupFileActions
|
|
2182
|
+
];
|
|
2183
|
+
/** 构建 Milky 动作注册表(64 个动作,领域工厂遍历注册)。 */
|
|
2246
2184
|
function createMilkyActionRegistry(opts) {
|
|
2247
2185
|
const registry = new ActionRegistry();
|
|
2248
|
-
const
|
|
2249
|
-
registry.register(new GetLoginInfoAction(api));
|
|
2250
|
-
registry.register(new GetImplInfoAction(api));
|
|
2251
|
-
registry.register(new SendPrivateMessageAction(api));
|
|
2252
|
-
registry.register(new SendGroupMessageAction(api));
|
|
2253
|
-
registry.register(new GetMessageAction(api));
|
|
2254
|
-
registry.register(new RecallPrivateMessageAction(api));
|
|
2255
|
-
registry.register(new RecallGroupMessageAction(api));
|
|
2256
|
-
registry.register(new GetFriendListAction(api));
|
|
2257
|
-
registry.register(new GetGroupListAction(api));
|
|
2258
|
-
registry.register(new GetUserProfileAction(api));
|
|
2259
|
-
registry.register(new GetFriendInfoAction(api));
|
|
2260
|
-
registry.register(new SetAvatarAction(api));
|
|
2261
|
-
registry.register(new SetNicknameAction(api));
|
|
2262
|
-
registry.register(new SetBioAction(api));
|
|
2263
|
-
registry.register(new GetCookiesAction(api));
|
|
2264
|
-
registry.register(new GetCSRFTokenAction(api));
|
|
2265
|
-
registry.register(new SendProfileLikeAction(api));
|
|
2266
|
-
registry.register(new DeleteFriendAction(api));
|
|
2267
|
-
registry.register(new GetFriendRequestsAction(api));
|
|
2268
|
-
registry.register(new AcceptFriendRequestAction(api));
|
|
2269
|
-
registry.register(new RejectFriendRequestAction(api));
|
|
2270
|
-
registry.register(new GetHistoryMessagesAction(api));
|
|
2271
|
-
registry.register(new GetForwardedMessagesAction(api));
|
|
2272
|
-
registry.register(new MarkMessageAsReadAction(api));
|
|
2273
|
-
registry.register(new GetGroupInfoAction(api));
|
|
2274
|
-
registry.register(new GetGroupMemberListAction(api));
|
|
2275
|
-
registry.register(new GetGroupMemberInfoAction(api));
|
|
2276
|
-
registry.register(new SetGroupNameAction(api));
|
|
2277
|
-
registry.register(new SetGroupMemberCardAction(api));
|
|
2278
|
-
registry.register(new SetGroupMemberAdminAction(api));
|
|
2279
|
-
registry.register(new SetGroupMemberMuteAction(api));
|
|
2280
|
-
registry.register(new SetGroupWholeMuteAction(api));
|
|
2281
|
-
registry.register(new KickGroupMemberAction(api));
|
|
2282
|
-
registry.register(new QuitGroupAction(api));
|
|
2283
|
-
registry.register(new GetGroupEssenceMessagesAction(api));
|
|
2284
|
-
registry.register(new SetGroupEssenceMessageAction(api));
|
|
2285
|
-
registry.register(new SendGroupMessageReactionAction(api));
|
|
2286
|
-
registry.register(new GetGroupNotificationsAction(api));
|
|
2287
|
-
registry.register(new AcceptGroupRequestAction(api));
|
|
2288
|
-
registry.register(new RejectGroupRequestAction(api));
|
|
2289
|
-
registry.register(new AcceptGroupInvitationAction(api));
|
|
2290
|
-
registry.register(new RejectGroupInvitationAction(api));
|
|
2291
|
-
registry.register(new GetGroupFilesAction(api));
|
|
2292
|
-
registry.register(new MoveGroupFileAction(api));
|
|
2293
|
-
registry.register(new RenameGroupFileAction(api));
|
|
2294
|
-
registry.register(new DeleteGroupFileAction(api));
|
|
2295
|
-
registry.register(new PersistGroupFileAction(api));
|
|
2296
|
-
registry.register(new CreateGroupFolderAction(api));
|
|
2297
|
-
registry.register(new DeleteGroupFolderAction(api));
|
|
2298
|
-
registry.register(new SendFriendNudgeAction(api));
|
|
2299
|
-
registry.register(new GetPeerPinsAction(api));
|
|
2300
|
-
registry.register(new SetPeerPinAction(api));
|
|
2301
|
-
registry.register(new SendGroupNudgeAction(api));
|
|
2302
|
-
registry.register(new GetGroupAnnouncementsAction(api));
|
|
2303
|
-
registry.register(new SendGroupAnnouncementAction(api));
|
|
2304
|
-
registry.register(new DeleteGroupAnnouncementAction(api));
|
|
2305
|
-
registry.register(new SetGroupAvatarAction(api));
|
|
2306
|
-
registry.register(new SetGroupMemberSpecialTitleAction(api));
|
|
2307
|
-
registry.register(new GetCustomFaceUrlListAction(api));
|
|
2308
|
-
registry.register(new GetResourceTempUrlAction(api));
|
|
2309
|
-
registry.register(new UploadPrivateFileAction(api));
|
|
2310
|
-
registry.register(new UploadGroupFileAction(api));
|
|
2311
|
-
registry.register(new GetGroupFileDownloadUrlAction(api));
|
|
2312
|
-
registry.register(new RenameGroupFolderAction(api));
|
|
2186
|
+
for (const factory of ACTION_FACTORIES) for (const action of factory(opts.api)) registry.register(action);
|
|
2313
2187
|
return registry;
|
|
2314
2188
|
}
|
|
2315
2189
|
// src/milky/enrichment.ts
|
|
@@ -2369,13 +2243,21 @@ var MilkyEventPipeline = class {
|
|
|
2369
2243
|
constructor(deps) {
|
|
2370
2244
|
this.deps = deps;
|
|
2371
2245
|
}
|
|
2372
|
-
/**
|
|
2246
|
+
/** 事件链异步失败兜底(单条/整批丢弃,warn 留痕不打断订阅)。 */
|
|
2247
|
+
logFailure(kind, err) {
|
|
2248
|
+
logEventFailure(this.deps.logger, `milky: ${kind} 翻译失败(丢弃)`, err);
|
|
2249
|
+
}
|
|
2250
|
+
/** 订阅 kernel 事件(消息 + 群 + 好友 + ,幂等;路由到 inbound/)。 */
|
|
2373
2251
|
subscribe() {
|
|
2374
2252
|
if (this.unsubscribes.length > 0) return;
|
|
2375
2253
|
const { msgChannel, groupChannel, buddyChannel, recentContactChannel, loginChannel } = this.deps;
|
|
2376
|
-
this.unsubscribes.push(subscribeRawMessages(msgChannel, (msg) =>
|
|
2254
|
+
this.unsubscribes.push(subscribeRawMessages(msgChannel, (msg) => this.deps.message.handle(msg).catch((err) => {
|
|
2255
|
+
this.logFailure("message_receive", err);
|
|
2256
|
+
})), msgChannel.on("Msg/onRecvSysMsg", (a) => this.deps.sysMsg.handleRawArg(a)), msgChannel.on("Msg/onRecvOfflineFileMsg", (m) => this.deps.fileNotice.fileMessages(m)), msgChannel.on("Msg/onFileMsgCome", (m) => this.deps.fileNotice.fileMessages(m)));
|
|
2377
2257
|
if (groupChannel !== void 0) this.unsubscribes.push(groupChannel.on("Group/onGroupNotifiesUpdated", (doubt, notifies) => {
|
|
2378
|
-
this.deps.request.groupNotifies(doubt, notifies)
|
|
2258
|
+
this.deps.request.groupNotifies(doubt, notifies).catch((err) => {
|
|
2259
|
+
this.logFailure("group request", err);
|
|
2260
|
+
});
|
|
2379
2261
|
}), groupChannel.on("Group/onGroupEssenceListChange", (a) => this.deps.essence.change(a)));
|
|
2380
2262
|
if (buddyChannel !== void 0) this.unsubscribes.push(buddyChannel.on("Buddy/onBuddyReqChange", (a) => this.deps.request.buddyReqs(a)));
|
|
2381
2263
|
if (recentContactChannel !== void 0) {
|
|
@@ -2404,7 +2286,7 @@ var MessageSeqIndex = class {
|
|
|
2404
2286
|
seqToMsg = /* @__PURE__ */ new Map();
|
|
2405
2287
|
/** msgId → seq 元信息。 */
|
|
2406
2288
|
msgToMeta = /* @__PURE__ */ new Map();
|
|
2407
|
-
/** 合并转发 resId → 定位信息(
|
|
2289
|
+
/** 合并转发 resId → 定位信息(get_forwarded_messages)。 */
|
|
2408
2290
|
forwards = /* @__PURE__ */ new Map();
|
|
2409
2291
|
/** 接收链路登记(一条消息双向写入;重复 msgId 覆盖)。 */
|
|
2410
2292
|
record(msg) {
|
|
@@ -2475,7 +2357,7 @@ var MessageSeqIndex = class {
|
|
|
2475
2357
|
};
|
|
2476
2358
|
// src/milky/helper/state/recent-keys.ts
|
|
2477
2359
|
/**
|
|
2478
|
-
* 带过期去重键缓存(Milky
|
|
2360
|
+
* 带过期去重键缓存(Milky)
|
|
2479
2361
|
*
|
|
2480
2362
|
* 两个场景共用:friend_file_upload 双回调(onRecvOfflineFileMsg / onFileMsgCome
|
|
2481
2363
|
* 同载荷,按 msgId 去重)与 group_essence_message_change 双路径(732:1 快路径
|
|
@@ -2564,7 +2446,7 @@ var MilkyInboundEssence = class {
|
|
|
2564
2446
|
};
|
|
2565
2447
|
// src/milky/helper/event/file-upload.ts
|
|
2566
2448
|
/**
|
|
2567
|
-
* friend_file_upload 翻译(Milky
|
|
2449
|
+
* friend_file_upload 翻译(Milky ,录制定型)
|
|
2568
2450
|
*
|
|
2569
2451
|
* 源:Msg/onRecvOfflineFileMsg 与 Msg/onFileMsgCome(同载荷 RawMessage 数组,
|
|
2570
2452
|
* 双回调按 msgId 在适配器去重);fileElement{fileName, fileSize 字符串,
|
|
@@ -2592,13 +2474,13 @@ function toFriendFileUploadData(msg, selfUin, uidToUin) {
|
|
|
2592
2474
|
}
|
|
2593
2475
|
// src/milky/helper/event/peer-pin.ts
|
|
2594
2476
|
/**
|
|
2595
|
-
* peer_pin_change 翻译(Milky
|
|
2477
|
+
* peer_pin_change 翻译(Milky ,RecentContact/onRecentContactListChangedVer2)
|
|
2596
2478
|
*
|
|
2597
2479
|
* 回调随消息活动高频快照(含 topFlag 的全量条目 + chatType=7 影子条目),
|
|
2598
2480
|
* 不能见条目就广播——按「同会话 topFlag 前后值翻转」检测(PinWatch)。
|
|
2599
2481
|
* 启动期以 getPinnedContacts 播种基线(重启后首个取消置顶也能观测到)。
|
|
2600
2482
|
*
|
|
2601
|
-
* 证据:
|
|
2483
|
+
* 证据:set_peer_pin 自触发翻转实验——changedList 条目
|
|
2602
2484
|
* {chatType, peerUin, topFlag(1/0), topFlagTime(秒级 unix 字符串)},与操作
|
|
2603
2485
|
* 一一对应(milky.md §0.8.6)。
|
|
2604
2486
|
*/
|
|
@@ -2652,7 +2534,7 @@ function toPeerPinChangeData(entry) {
|
|
|
2652
2534
|
/** Milky 置顶域处理器(翻转检测 + 播种基线 + peer_pin_change 广播)。 */
|
|
2653
2535
|
var MilkyInboundPin = class {
|
|
2654
2536
|
deps;
|
|
2655
|
-
/** peer_pin
|
|
2537
|
+
/** peer_pin 翻转检测(启动期 getPinnedContacts 播种)。 */
|
|
2656
2538
|
pinWatch = new PinWatch();
|
|
2657
2539
|
constructor(deps) {
|
|
2658
2540
|
this.deps = deps;
|
|
@@ -2662,7 +2544,7 @@ var MilkyInboundPin = class {
|
|
|
2662
2544
|
const arr = Array.isArray(lists) ? lists : [lists];
|
|
2663
2545
|
for (const list of arr) for (const entry of changedListOf(list)) this.handleEntry(entry);
|
|
2664
2546
|
}
|
|
2665
|
-
/**
|
|
2547
|
+
/** 启动基线:置顶会话播种(失败补 debug 日志,不再静默)。 */
|
|
2666
2548
|
seed() {
|
|
2667
2549
|
this.deps.api.recentContactApi.getPinnedContacts().then((pins) => {
|
|
2668
2550
|
this.pinWatch.seed(pins);
|
|
@@ -2979,7 +2861,7 @@ var MilkyInboundRequest = class {
|
|
|
2979
2861
|
}
|
|
2980
2862
|
/** 好友请求通道:Buddy/onBuddyReqChange(防御收窄,未知形状 raw 日志)。 */
|
|
2981
2863
|
buddyReqs(arg) {
|
|
2982
|
-
this.broadcastBuddyReqs(arg);
|
|
2864
|
+
this.broadcastBuddyReqs(arg).catch((err) => logEventFailure(this.deps.logger, "milky: friend request 翻译失败(整批丢弃)", err));
|
|
2983
2865
|
}
|
|
2984
2866
|
async broadcastBuddyReqs(arg) {
|
|
2985
2867
|
const reqs = narrowBuddyReqs(arg);
|
|
@@ -3001,7 +2883,7 @@ var MilkyInboundRequest = class {
|
|
|
3001
2883
|
};
|
|
3002
2884
|
// src/milky/helper/event/sysmsg.ts
|
|
3003
2885
|
/**
|
|
3004
|
-
* Milky sysmsg
|
|
2886
|
+
* Milky sysmsg 识别表(识别机制共享自 core/sysmsg.ts)
|
|
3005
2887
|
*
|
|
3006
2888
|
* 键 = 原生分发键 "msgType:subType",规则产出事件 data 体(信封 time/self_id/
|
|
3007
2889
|
* event_type 由适配器统一包装)。路径依据 = 三轮录制 wire bytes 全量解码
|
|
@@ -3319,7 +3201,7 @@ var NapukettoMilkyAdapter = class extends BaseProtocolAdapter {
|
|
|
3319
3201
|
seqIndex = new MessageSeqIndex();
|
|
3320
3202
|
/** 动作注册表(公共只读:装配方/测试枚举)。 */
|
|
3321
3203
|
registry;
|
|
3322
|
-
/** 收链路事件管道(订阅 / 过滤 / 去重 /
|
|
3204
|
+
/** 收链路事件管道(订阅 / 过滤 / 去重 / 翻译派发,拆出)。 */
|
|
3323
3205
|
pipeline;
|
|
3324
3206
|
stopTransports = null;
|
|
3325
3207
|
constructor(opts) {
|
|
@@ -3362,7 +3244,8 @@ var NapukettoMilkyAdapter = class extends BaseProtocolAdapter {
|
|
|
3362
3244
|
enrich
|
|
3363
3245
|
}),
|
|
3364
3246
|
fileNotice: new MilkyInboundFileNotice(base),
|
|
3365
|
-
pin: new MilkyInboundPin(base)
|
|
3247
|
+
pin: new MilkyInboundPin(base),
|
|
3248
|
+
logger: opts.logger
|
|
3366
3249
|
});
|
|
3367
3250
|
this.registry = createMilkyActionRegistry({ api: this.api });
|
|
3368
3251
|
}
|
|
@@ -3406,7 +3289,7 @@ var NapukettoMilkyAdapter = class extends BaseProtocolAdapter {
|
|
|
3406
3289
|
};
|
|
3407
3290
|
// src/milky/config.ts
|
|
3408
3291
|
/**
|
|
3409
|
-
* Milky 协议配置(zod schema
|
|
3292
|
+
* Milky 协议配置(zod schema,归属本包)
|
|
3410
3293
|
*
|
|
3411
3294
|
* 单一 TOML 的 `[accounts.milky]` 账号段(docs/protocols/milky.md §4):
|
|
3412
3295
|
* 单端口 HTTP 模型(/api + /event 同端口),`enabled` 缺省 false = 不启用。
|