refactor(oidb): migrate misc.ts OIDB cmds to namespaces

3 OIDB cmds migrated; the 1 non-OIDB cmd (getMiniAppArk via
LightAppSvc) stays on the facade unchanged.

  - TranslateEnToZh           (0x990_2)
  - ClickInlineKeyboardButton (0x112E_1)
  - SendGroupSign             (0xEB7_1) — preserves historic UPPERCASE
                                          EB7 wire name via the new
                                          `wireName` override (the only
                                          cmd in the codebase with this
                                          quirk; every other cmd uses
                                          the default lowercase).

Tests:
  - misc.test.ts moved to bridge.sendRawPacket assertion model
  - 18 new namespace-level tests covering serialize, deserialize edge
    cases, magic constants, BigInt widening, and the EB7 case quirk

Verification:
  - typecheck green
  - @snowluma/bridge: 18 files / 153 tests
  - @snowluma/core: 302 tests
Wire bytes unchanged.
This commit is contained in:
DrSmoothl committed 2026-05-22 23:37:41 +08:00
1 parent f78431242c
commit 58e8081420
9 files changed
+425 -117

No files matched your search

+10 -74
View File
@@ -4,48 +4,21 @@
// commit 13).
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type {
MiniAppShareReq,
MiniAppShareResp,
Oidb0x112eReq,
Oidb0x112eResp,
Oidb0x990Req,
Oidb0x990Resp,
Oidb0xeb7Req,
Oidb0xeb7Resp,
} from '@snowluma/proto-defs/oidb-actions/base';
import type { BridgeContext } from '../bridge-context';
import type { Bridge } from '../bridge';
import { makeOidbEnvelope, runOidb } from '@snowluma/bridge/bridge-oidb';
function asBridge(ctx: BridgeContext): Bridge { return ctx as unknown as Bridge; }
// Migrated OIDB cmds — facade methods are one-line forwarders.
import { TranslateEnToZh } from '@snowluma/bridge/oidb-services/misc/translate-en-to-zh';
import { ClickInlineKeyboardButton } from '@snowluma/bridge/oidb-services/misc/click-inline-keyboard-button';
import { SendGroupSign } from '@snowluma/bridge/oidb-services/misc/send-group-sign';
export class MiscApi {
constructor(private readonly ctx: BridgeContext) {}
async translateEn2Zh(words: string[]): Promise<string[]> {
const bridge = asBridge(this.ctx);
const req = {
translateReq: {
srcLang: 'en',
dstLang: 'zh',
words,
},
tag10: 1,
tag12: 1,
};
const env = makeOidbEnvelope<Oidb0x990Req>(0x990, 2, req);
const respBytes = await runOidb(bridge, 'OidbSvcTrpcTcp.0x990_2', protobuf_encode<OidbBase<Oidb0x990Req>>(env));
const result = protobuf_decode<OidbBase<Oidb0x990Resp>>(respBytes).body;
const resp = result?.translateResp;
if (!resp) {
throw new Error('translate response empty');
}
return resp.dstWords || [];
translateEn2Zh(words: string[]): Promise<string[]> {
return TranslateEnToZh.invoke(this.ctx, { words });
}
async getMiniAppArk(type: string, title: string, desc: string, picUrl: string, jumpUrl: string): Promise<any> {
@@ -93,54 +66,17 @@ export class MiscApi {
};
}
async clickInlineKeyboardButton(
clickInlineKeyboardButton(
groupId: number,
botAppid: number,
buttonId: string,
callbackData: string,
msgSeq: number,
): Promise<any> {
const bridge = asBridge(this.ctx);
const req = {
botAppid: BigInt(botAppid),
msgSeq: BigInt(msgSeq),
buttonId: String(buttonId),
callbackData: String(callbackData || ''),
unknown7: 0,
groupId: BigInt(groupId),
unknown9: 1,
};
const env = makeOidbEnvelope<Oidb0x112eReq>(0x112E, 1, req);
const respBytes = await runOidb(bridge, 'OidbSvcTrpcTcp.0x112e_1', protobuf_encode<OidbBase<Oidb0x112eReq>>(env));
const result = protobuf_decode<OidbBase<Oidb0x112eResp>>(respBytes).body;
if (!result) {
throw new Error('click inline keyboard button result empty');
}
return {
result: Number(result.result || 0),
errMsg: result.errMsg || '',
status: 0,
promptText: result.promptText || '',
promptType: 0,
promptIcon: 0,
};
return ClickInlineKeyboardButton.invoke(this.ctx, { groupId, botAppid, buttonId, callbackData, msgSeq });
}
async sendGroupSign(groupId: number): Promise<void> {
const bridge = asBridge(this.ctx);
const req = {
signInInfo: {
uin: String(this.ctx.identity.uin),
groupId: String(groupId),
version: '9.0.90',
},
};
const env = makeOidbEnvelope<Oidb0xeb7Req>(0xEB7, 1, req);
const respBytes = await runOidb(bridge, 'OidbSvcTrpcTcp.0xEB7_1', protobuf_encode<OidbBase<Oidb0xeb7Req>>(env));
protobuf_decode<OidbBase<Oidb0xeb7Resp>>(respBytes);
sendGroupSign(groupId: number): Promise<void> {
return SendGroupSign.invoke(this.ctx, { groupId });
}
}