refactor(protocol,core): converge self-uid resolution to one impl
「取自己 uid」原本散成 5 份、3 种错误文案:core/apis/shared.ts::resolveSelfUid、 group-file/message 各内联手抄一份、get-like 跨包再抄一份。收敛成 protocol 单一 resolveSelfUid(ctx: Pick<BridgeContext,'identity'|'resolveUserUid'>)。 阶段 1(行为不变): - 新增 protocol/self-uid.ts(依赖方向 core→protocol 要求权威实现下沉 protocol; Bridge 与 OIDB service Deps 都满足 Pick 切片)。 - core/apis/shared.ts 改为 re-export 它(现有 resolveSelfUid(bridge) 调用点不变)。 - get-like/group-file/message 三处内联手抄 → 全调权威实现。 - 唯一副作用:message 的错误文案统一为 'self uid is unavailable'(无测试依赖旧文案)。 flash-transfer/forward 的 ?? '' 空串 bug 留待阶段 2;group-admin 合成本地事件保持不动。 全仓 12 包 typecheck Done、protocol/core(471)/onebot(516) 全绿;对抗性 Agent 确认 toInt/Number 边界无实际差异(identity.uin 恒为正整数串)、5 处等价。
This commit is contained in:
6 files changed
+42
-45
No files matched your search
@@ -1,5 +1,3 @@
|
||||
import type { Bridge } from '../bridge';
|
||||
|
||||
export function toInt(value: unknown): number {
|
||||
if (typeof value === 'number' && Number.isFinite(value)) return Math.trunc(value);
|
||||
if (typeof value === 'bigint') {
|
||||
@@ -26,22 +24,10 @@ export function ensureRetCodeZero(operation: string, code: unknown, msg: unknown
|
||||
throw new Error(`${operation} failed: code=${retCode} msg=${text}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Look up the bot's own UID. Cached on Identity once warmup populates
|
||||
* `selfProfile`; forward/profile actions need this fast path before
|
||||
* warmup completes.
|
||||
*/
|
||||
export async function resolveSelfUid(bridge: Bridge): Promise<string> {
|
||||
let selfUid = bridge.identity.selfUid;
|
||||
if (selfUid) return selfUid;
|
||||
|
||||
const selfUin = toInt(bridge.identity.uin);
|
||||
if (selfUin <= 0) {
|
||||
throw new Error('self uid is unavailable');
|
||||
}
|
||||
selfUid = await bridge.resolveUserUid(selfUin);
|
||||
return selfUid;
|
||||
}
|
||||
// The bot's-own-UID resolver is the single source of truth in @snowluma/protocol
|
||||
// (a Bridge satisfies its BridgeContext slice). Re-exported here so the existing
|
||||
// `resolveSelfUid(bridge)` call sites in this package keep importing from shared.
|
||||
export { resolveSelfUid } from '@snowluma/protocol/self-uid';
|
||||
|
||||
/**
|
||||
* Index describing a server-side rich-media object (image / video /
|
||||
|
||||
Reference in new issue
Block a user