@napuketto/adapter 0.4.1 → 0.5.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/dist/kurobot/index.mjs +1 -1
- package/dist/milky/index.d.mts +187 -0
- package/dist/milky/index.d.mts.map +1 -0
- package/dist/milky/index.mjs +1240 -0
- package/dist/milky/index.mjs.map +1 -0
- package/dist/onebot11/index.d.mts +163 -143
- package/dist/onebot11/index.d.mts.map +1 -1
- package/dist/onebot11/index.mjs +68 -23
- package/dist/onebot11/index.mjs.map +1 -1
- package/dist/raw-message-D_ecJy4C.mjs +19 -0
- package/dist/raw-message-D_ecJy4C.mjs.map +1 -0
- package/dist/satori/index.mjs +1 -1
- package/package.json +10 -5
- package/dist/raw-message-6KdlG8kR.mjs +0 -13
- package/dist/raw-message-6KdlG8kR.mjs.map +0 -1
package/dist/onebot11/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { i as BaseAction, o as ActionRegistry, r as BaseProtocolAdapter, t as ensureSilk } from "../core-DyXyDUcU.mjs";
|
|
2
2
|
import { n as createHttpServerSchema, r as createWsServerSchema, t as collectGrayTipUids } from "../gray-tip-B80z9KR4.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { n as subscribeRawMessages } from "../raw-message-D_ecJy4C.mjs";
|
|
4
4
|
import { ChatType, GrayTipSubType, GroupApi, GroupNotifyMsgStatus, GroupNotifyMsgType, NTGroupMemberRole, NTGroupRequestOperateTypes, TicketApi, TipGroupElementType, WebHonorType, kernelError, toCanonicalElements } from "@napuketto/kernel";
|
|
5
5
|
import { downloadUrl, inferExtension } from "@napuketto/media";
|
|
6
6
|
import { z } from "zod";
|
|
@@ -1901,7 +1901,7 @@ function toOb11MessageInfo(msg, unique, ctx = {}) {
|
|
|
1901
1901
|
if (msg.chatType === ChatType.GROUP) {
|
|
1902
1902
|
info.group_id = Number(msg.peerUid);
|
|
1903
1903
|
const { sender } = info;
|
|
1904
|
-
sender.role = "member";
|
|
1904
|
+
sender.role = ctx.senderRole ?? "member";
|
|
1905
1905
|
if (msg.sendMemberName !== void 0) sender.card = msg.sendMemberName;
|
|
1906
1906
|
} else info.user_id = Number(msg.senderUin);
|
|
1907
1907
|
return info;
|
|
@@ -2258,6 +2258,7 @@ function resolveStartMsgId(messageSeq, messageUnique) {
|
|
|
2258
2258
|
/**
|
|
2259
2259
|
* 拉取历史消息并翻译为 OB11 消息信息数组。
|
|
2260
2260
|
* 收集全部消息 at uid → 一次批量 uidToUin → 上下文注入(P2-19)。
|
|
2261
|
+
* 群聊另取发送者角色表(GroupCache 一次整表读取,失败回退缺省 member)。
|
|
2261
2262
|
*/
|
|
2262
2263
|
async function fetchAndTranslateHistory(peer, messageSeq, count, deps) {
|
|
2263
2264
|
const startMsgId = resolveStartMsgId(messageSeq, deps.messageUnique);
|
|
@@ -2278,7 +2279,15 @@ async function fetchAndTranslateHistory(peer, messageSeq, count, deps) {
|
|
|
2278
2279
|
...uidToUin !== void 0 ? { uidToUin } : {},
|
|
2279
2280
|
msgIdToOb11Id: (m) => deps.messageUnique.getMessageId(m)
|
|
2280
2281
|
};
|
|
2281
|
-
|
|
2282
|
+
let senderRoles;
|
|
2283
|
+
if (peer.chatType === ChatType.GROUP) senderRoles = await deps.groupMemberRoles(peer.peerUid);
|
|
2284
|
+
return { messages: msgs.map((msg) => {
|
|
2285
|
+
const role = senderRoles?.get(msg.senderUid);
|
|
2286
|
+
return toOb11MessageInfo(msg, deps.messageUnique, {
|
|
2287
|
+
...ctx,
|
|
2288
|
+
...role !== void 0 ? { senderRole: role } : {}
|
|
2289
|
+
});
|
|
2290
|
+
}) };
|
|
2282
2291
|
}
|
|
2283
2292
|
//#endregion
|
|
2284
2293
|
//#region src/onebot11/action/message/get-friend-msg-history.ts
|
|
@@ -2508,8 +2517,10 @@ var GetMsgAction = class extends BaseAction {
|
|
|
2508
2517
|
if (atUids.length > 0) try {
|
|
2509
2518
|
uidToUin = await this.deps.uidToUin(atUids);
|
|
2510
2519
|
} catch {}
|
|
2520
|
+
const senderRole = msg.chatType === ChatType.GROUP ? await this.deps.groupMemberRole(msg.peerUid, msg.senderUid) : void 0;
|
|
2511
2521
|
const ctx = {
|
|
2512
2522
|
...uidToUin !== void 0 ? { uidToUin } : {},
|
|
2523
|
+
...senderRole !== void 0 ? { senderRole } : {},
|
|
2513
2524
|
msgIdToOb11Id: (m) => this.deps.messageUnique.getMessageId(m)
|
|
2514
2525
|
};
|
|
2515
2526
|
return toOb11MessageInfo(msg, this.deps.messageUnique, ctx);
|
|
@@ -3571,6 +3582,34 @@ var OneBotApi = class {
|
|
|
3571
3582
|
uidToUin(uids) {
|
|
3572
3583
|
return this.groupApi.uidToUin(uids);
|
|
3573
3584
|
}
|
|
3585
|
+
/**
|
|
3586
|
+
* 群成员角色(GroupCache 缓存优先,缺失惰性回填;sender.role 判定用)。
|
|
3587
|
+
* 未装配缓存 / 成员不在群 / 查询失败 → undefined(调用方回退缺省 "member",
|
|
3588
|
+
* 不阻塞消息上报)。
|
|
3589
|
+
*/
|
|
3590
|
+
async groupMemberRole(groupCode, uid) {
|
|
3591
|
+
if (this.groupCache === void 0) return;
|
|
3592
|
+
try {
|
|
3593
|
+
const member = await this.groupCache.getMember(groupCode, uid);
|
|
3594
|
+
return member === void 0 ? void 0 : GroupApi.roleToString(member.role);
|
|
3595
|
+
} catch {
|
|
3596
|
+
return;
|
|
3597
|
+
}
|
|
3598
|
+
}
|
|
3599
|
+
/**
|
|
3600
|
+
* 群成员角色表(历史消息批量用:一次整表读取,uid → role)。
|
|
3601
|
+
* 失败语义同 groupMemberRole。
|
|
3602
|
+
*/
|
|
3603
|
+
async groupMemberRoles(groupCode) {
|
|
3604
|
+
if (this.groupCache === void 0) return;
|
|
3605
|
+
try {
|
|
3606
|
+
const out = /* @__PURE__ */ new Map();
|
|
3607
|
+
for (const member of await this.groupCache.getMembers(groupCode)) out.set(member.uid, GroupApi.roleToString(member.role));
|
|
3608
|
+
return out;
|
|
3609
|
+
} catch {
|
|
3610
|
+
return;
|
|
3611
|
+
}
|
|
3612
|
+
}
|
|
3574
3613
|
};
|
|
3575
3614
|
//#endregion
|
|
3576
3615
|
//#region src/onebot11/helper/message-event.ts
|
|
@@ -3601,7 +3640,7 @@ function toOb11MessageEvent(msg, selfUin, unique, messageFormat = "array", ctx =
|
|
|
3601
3640
|
const sender = {
|
|
3602
3641
|
user_id: userId,
|
|
3603
3642
|
nickname: msg.sendNickName,
|
|
3604
|
-
role: "member"
|
|
3643
|
+
role: ctx.senderRole ?? "member"
|
|
3605
3644
|
};
|
|
3606
3645
|
if (msg.sendMemberName !== void 0) sender.card = msg.sendMemberName;
|
|
3607
3646
|
return {
|
|
@@ -4230,22 +4269,20 @@ var NapukettoOneBot11Adapter = class extends BaseProtocolAdapter {
|
|
|
4230
4269
|
/** 订阅 kernel 事件(消息 + 群通知 + 好友请求,幂等)。 */
|
|
4231
4270
|
subscribe() {
|
|
4232
4271
|
if (this.unsubscribes.length > 0) return;
|
|
4233
|
-
this.unsubscribes.push(this.msgChannel
|
|
4234
|
-
|
|
4235
|
-
|
|
4236
|
-
|
|
4272
|
+
this.unsubscribes.push(subscribeRawMessages(this.msgChannel, (msg) => {
|
|
4273
|
+
if (hasGrayTip(msg)) {
|
|
4274
|
+
this.broadcastNotice(msg).catch(() => {});
|
|
4275
|
+
return;
|
|
4276
|
+
}
|
|
4277
|
+
if (!this.reportSelfMessage && String(msg.senderUin) === this.selfUin) return;
|
|
4278
|
+
if (this.groupUploadAsNotice && msg.chatType === ChatType.GROUP && hasFileElement(msg)) {
|
|
4279
|
+
const notice = toGroupUpload(msg, this.selfUin);
|
|
4280
|
+
if (notice !== null) {
|
|
4281
|
+
this.broadcastEvent(notice);
|
|
4237
4282
|
return;
|
|
4238
4283
|
}
|
|
4239
|
-
|
|
4240
|
-
|
|
4241
|
-
const notice = toGroupUpload(msg, this.selfUin);
|
|
4242
|
-
if (notice !== null) {
|
|
4243
|
-
this.broadcastEvent(notice);
|
|
4244
|
-
return;
|
|
4245
|
-
}
|
|
4246
|
-
}
|
|
4247
|
-
this.broadcastMessageEvent(msg);
|
|
4248
|
-
});
|
|
4284
|
+
}
|
|
4285
|
+
this.broadcastMessageEvent(msg);
|
|
4249
4286
|
}));
|
|
4250
4287
|
this.unsubscribes.push(this.msgChannel.on("Msg/onRecvOfflineFileMsg", (arg) => {
|
|
4251
4288
|
const items = narrowOfflineFiles(arg);
|
|
@@ -4345,6 +4382,7 @@ var NapukettoOneBot11Adapter = class extends BaseProtocolAdapter {
|
|
|
4345
4382
|
/**
|
|
4346
4383
|
* 广播消息事件(P2-19:接收方向 ID 转换)。
|
|
4347
4384
|
* 收集 at uid → 一次批量 uidToUin → 构造上下文 → 翻译广播。
|
|
4385
|
+
* 群消息另查发送者角色(GroupCache 缓存优先,失败回退缺省 member)。
|
|
4348
4386
|
* 翻译失败退化为原样(不阻塞上报)。
|
|
4349
4387
|
*/
|
|
4350
4388
|
async broadcastMessageEvent(msg) {
|
|
@@ -4353,8 +4391,10 @@ var NapukettoOneBot11Adapter = class extends BaseProtocolAdapter {
|
|
|
4353
4391
|
if (atUids.length > 0) try {
|
|
4354
4392
|
uidToUin = await this.oneBotApi.uidToUin(atUids);
|
|
4355
4393
|
} catch {}
|
|
4394
|
+
const senderRole = msg.chatType === ChatType.GROUP ? await this.oneBotApi.groupMemberRole(msg.peerUid, msg.senderUid) : void 0;
|
|
4356
4395
|
const ctx = {
|
|
4357
4396
|
...uidToUin !== void 0 ? { uidToUin } : {},
|
|
4397
|
+
...senderRole !== void 0 ? { senderRole } : {},
|
|
4358
4398
|
msgIdToOb11Id: (msgId) => this.oneBotApi.messageUnique.getMessageId(msgId)
|
|
4359
4399
|
};
|
|
4360
4400
|
this.broadcastEvent(toOb11MessageEvent(msg, this.selfUin, this.oneBotApi.messageUnique, this.messageFormat, ctx));
|
|
@@ -4373,11 +4413,7 @@ var NapukettoOneBot11Adapter = class extends BaseProtocolAdapter {
|
|
|
4373
4413
|
}
|
|
4374
4414
|
/** 广播群系统通知 → OB11 group request 事件(批量 uidToUin 后翻译,纯函数)。 */
|
|
4375
4415
|
async broadcastGroupRequests(notifies) {
|
|
4376
|
-
const uids =
|
|
4377
|
-
for (const n of notifies) {
|
|
4378
|
-
const notify = n;
|
|
4379
|
-
for (const u of [notify.user1, notify.user2]) if (typeof u?.uid === "string" && u.uid !== "") uids.push(u.uid);
|
|
4380
|
-
}
|
|
4416
|
+
const uids = collectGroupNotifyUids(notifies);
|
|
4381
4417
|
let uidToUin = /* @__PURE__ */ new Map();
|
|
4382
4418
|
if (uids.length > 0) try {
|
|
4383
4419
|
uidToUin = await this.oneBotApi.uidToUin(uids);
|
|
@@ -4444,6 +4480,15 @@ var NapukettoOneBot11Adapter = class extends BaseProtocolAdapter {
|
|
|
4444
4480
|
respond(result);
|
|
4445
4481
|
}
|
|
4446
4482
|
};
|
|
4483
|
+
/** 收集群系统通知涉及的 uid(user1/user2 双方,空 uid 跳过)。 */
|
|
4484
|
+
function collectGroupNotifyUids(notifies) {
|
|
4485
|
+
const uids = [];
|
|
4486
|
+
for (const n of notifies) {
|
|
4487
|
+
const notify = n;
|
|
4488
|
+
for (const u of [notify.user1, notify.user2]) if (typeof u?.uid === "string" && u.uid !== "") uids.push(u.uid);
|
|
4489
|
+
}
|
|
4490
|
+
return uids;
|
|
4491
|
+
}
|
|
4447
4492
|
//#endregion
|
|
4448
4493
|
export { MessageUnique, NapukettoOneBot11Adapter, OneBotApi, assembleOb11Transports, canonicalToCqMessage, canonicalToSegments, cqMessageToCanonical, cqMessageToSegments, createOb11ActionRegistry, encodeCqCode, escapeCqParam, escapeCqText, ob11ConfigSchema, ob11ErrorCodeMap, parseCqMessage, segmentsToCanonical, segmentsToCqMessage, serializeCqParts, unescapeCqText };
|
|
4449
4494
|
|