@napuketto/adapter 0.24.2 → 0.24.3
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/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { f as ActionRegistry, n as ProtocolConfig, o as BaseProtocolAdapter, p as runAction, r as createServerSchema, t as ConfigBase } from "./framework-CA3087JP.mjs";
|
|
2
2
|
import { N as kurobotConfigSchema, t as NapukettoKurobotAdapter } from "./kurobot-3nvb4oqh.mjs";
|
|
3
3
|
import { r as milkyConfigSchema, t as NapukettoMilkyAdapter } from "./milky-BWLRoCdN.mjs";
|
|
4
|
-
import { t as NapukettoOneBot11Adapter, u as ob11ConfigSchema } from "./onebot11-
|
|
4
|
+
import { t as NapukettoOneBot11Adapter, u as ob11ConfigSchema } from "./onebot11-CQhxsoc_.mjs";
|
|
5
5
|
import { m as satoriConfigSchema, t as NapukettoSatoriAdapter } from "./satori-CgaSIlQs.mjs";
|
|
6
6
|
export { ActionRegistry, BaseProtocolAdapter, ConfigBase, NapukettoKurobotAdapter, NapukettoMilkyAdapter, NapukettoOneBot11Adapter, NapukettoSatoriAdapter, ProtocolConfig, createServerSchema, kurobotConfigSchema, milkyConfigSchema, ob11ConfigSchema, runAction, satoriConfigSchema };
|
package/dist/onebot11/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { y as MessageUnique, t as NapukettoOneBot11Adapter, r as OneBotApi, n as assembleOb11Transports, a as canonicalToCqMessage, o as canonicalToSegments, s as cqMessageToCanonical, c as cqMessageToSegments, i as createOb11ActionRegistry, f as encodeCqCode, p as escapeCqParam, m as escapeCqText, u as ob11ConfigSchema, v as ob11ErrorCodeMap, h as parseCqMessage, l as segmentsToCanonical, d as segmentsToCqMessage, g as serializeCqParts, _ as unescapeCqText } from "../onebot11-
|
|
1
|
+
export { y as MessageUnique, t as NapukettoOneBot11Adapter, r as OneBotApi, n as assembleOb11Transports, a as canonicalToCqMessage, o as canonicalToSegments, s as cqMessageToCanonical, c as cqMessageToSegments, i as createOb11ActionRegistry, f as encodeCqCode, p as escapeCqParam, m as escapeCqText, u as ob11ConfigSchema, v as ob11ErrorCodeMap, h as parseCqMessage, l as segmentsToCanonical, d as segmentsToCqMessage, g as serializeCqParts, _ as unescapeCqText } from "../onebot11-CQhxsoc_.mjs";
|
|
@@ -1488,8 +1488,12 @@ function applyReceiveContext(elements, ctx) {
|
|
|
1488
1488
|
}
|
|
1489
1489
|
return out;
|
|
1490
1490
|
}
|
|
1491
|
-
/**
|
|
1491
|
+
/**
|
|
1492
|
+
* at 段:uin → uid(缺省不转换)。
|
|
1493
|
+
* `u_...` 已是 NT UID:直通(不再查映射,与 loader ipc-actions 的 at 归一化同契约)。
|
|
1494
|
+
*/
|
|
1492
1495
|
function translateAtElement(el, ctx) {
|
|
1496
|
+
if (el.target.startsWith("u_")) return el;
|
|
1493
1497
|
const uid = ctx.uinToUid?.get(el.target);
|
|
1494
1498
|
return uid !== void 0 ? {
|
|
1495
1499
|
...el,
|
|
@@ -2377,6 +2381,8 @@ const sendGroupMsgSchema = z.object({
|
|
|
2377
2381
|
group_id: z.number(),
|
|
2378
2382
|
...sendMsgBodyFields
|
|
2379
2383
|
});
|
|
2384
|
+
/** NT UID 前缀(`u_...`:调用方直接给 uid,发送方向直通,不再走 uinToUid)。 */
|
|
2385
|
+
const UID_PREFIX = "u_";
|
|
2380
2386
|
/** 共享发送核心:解析 Peer → canonical 翻译(含 auto_escape)→ sendMessage → 映射 message_id。 */
|
|
2381
2387
|
async function sendOb11Message(payload, deps) {
|
|
2382
2388
|
const peer = await resolveTargetPeer(payload, deps, "send_msg 需要 group_id 或 user_id");
|
|
@@ -2385,7 +2391,7 @@ async function sendOb11Message(payload, deps) {
|
|
|
2385
2391
|
else canonical = cqMessageToCanonical(payload.message);
|
|
2386
2392
|
canonical = await prepareLocalElements(canonical, deps);
|
|
2387
2393
|
const atUins = [];
|
|
2388
|
-
for (const el of canonical) if (el.type === "at" && el.target !== "all") atUins.push(el.target);
|
|
2394
|
+
for (const el of canonical) if (el.type === "at" && el.target !== "all" && !el.target.startsWith(UID_PREFIX)) atUins.push(el.target);
|
|
2389
2395
|
let uinToUid;
|
|
2390
2396
|
if (atUins.length > 0) try {
|
|
2391
2397
|
uinToUid = await deps.uinToUid(atUins);
|
|
@@ -2399,6 +2405,7 @@ async function sendOb11Message(payload, deps) {
|
|
|
2399
2405
|
...uinToUid !== void 0 ? { uinToUid } : {},
|
|
2400
2406
|
ob11IdToMsgId: (id) => deps.messageUnique.getMsgId(id)
|
|
2401
2407
|
});
|
|
2408
|
+
canonical = await fillAtDisplays(canonical, peer, deps);
|
|
2402
2409
|
if (payload.auto_escape === true) canonical = canonical.map((el) => {
|
|
2403
2410
|
if (el.type === "text") return {
|
|
2404
2411
|
...el,
|
|
@@ -2416,6 +2423,44 @@ async function sendOb11Message(payload, deps) {
|
|
|
2416
2423
|
await prepared.cleanup();
|
|
2417
2424
|
}
|
|
2418
2425
|
}
|
|
2426
|
+
/**
|
|
2427
|
+
* 群聊 at 段显示名补全(uid → 群名片优先、昵称兜底)。
|
|
2428
|
+
*
|
|
2429
|
+
* 仅补「已是 uid + 无 display」的单人 at:@全体、数字 uin(转换失败保留的 uin)、
|
|
2430
|
+
* 非群聊或未装配 groupCache 时原样返回;查询失败只留 debug 痕迹(fail-soft,不阻塞发送)。
|
|
2431
|
+
*/
|
|
2432
|
+
async function fillAtDisplays(elements, peer, deps) {
|
|
2433
|
+
const groupCache = deps.groupCache;
|
|
2434
|
+
if (peer.chatType !== ChatType.GROUP || groupCache === void 0) return elements;
|
|
2435
|
+
const out = [];
|
|
2436
|
+
for (const el of elements) {
|
|
2437
|
+
if (el.type !== "at" || el.target === "all" || !el.target.startsWith(UID_PREFIX) || el.display !== void 0 && el.display !== "") {
|
|
2438
|
+
out.push(el);
|
|
2439
|
+
continue;
|
|
2440
|
+
}
|
|
2441
|
+
const display = await memberDisplayName(deps, groupCache, peer.peerUid, el.target);
|
|
2442
|
+
out.push(display === void 0 ? el : {
|
|
2443
|
+
...el,
|
|
2444
|
+
display
|
|
2445
|
+
});
|
|
2446
|
+
}
|
|
2447
|
+
return out;
|
|
2448
|
+
}
|
|
2449
|
+
/** 群成员显示名(群名片 → 昵称;查不到/抛错返回 undefined)。 */
|
|
2450
|
+
async function memberDisplayName(deps, groupCache, groupCode, uid) {
|
|
2451
|
+
try {
|
|
2452
|
+
const member = await groupCache.getMember(groupCode, uid);
|
|
2453
|
+
if (member === void 0) return;
|
|
2454
|
+
const name = member.cardName ?? member.nick;
|
|
2455
|
+
return name === void 0 || name === "" ? void 0 : name;
|
|
2456
|
+
} catch (err) {
|
|
2457
|
+
deps.logger?.debug({
|
|
2458
|
+
group: groupCode,
|
|
2459
|
+
error: errorMessage(err)
|
|
2460
|
+
}, "ob11: at 群成员显示名查询失败(at 段无 display)");
|
|
2461
|
+
return;
|
|
2462
|
+
}
|
|
2463
|
+
}
|
|
2419
2464
|
async function prepareLocalElements(elements, deps) {
|
|
2420
2465
|
const roots = deps.getLocalMediaRoots?.();
|
|
2421
2466
|
const prepared = [];
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@napuketto/adapter",
|
|
4
|
-
"version": "0.24.
|
|
4
|
+
"version": "0.24.3",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Protocol adapters (OneBot11 / Satori / KuroBot / Milky) for Napuketto",
|
|
7
7
|
"keywords": [
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
"dev": "tsdown --watch"
|
|
83
83
|
},
|
|
84
84
|
"dependencies": {
|
|
85
|
-
"@napuketto/kernel": "^0.19.
|
|
85
|
+
"@napuketto/kernel": "^0.19.4",
|
|
86
86
|
"@napuketto/media": "^0.4.1",
|
|
87
87
|
"@napuketto/network": "^0.5.1",
|
|
88
88
|
"zod": "^4.6.7"
|