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

@@ -0,0 +1,60 @@
// 0x112E_1 — relay an inline-keyboard-button click event to the bot
// owning the button (so the bot can react). All identity fields go on
// the wire as uint_64 → callers pass JS numbers and we widen here.
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type { Oidb0x112eReq, Oidb0x112eResp } from '@snowluma/proto-defs/oidb-actions/base';
import { invokeOidb, type OidbSender } from '../../oidb-service';
export interface InlineButtonClickResult {
result: number;
errMsg: string;
status: 0;
promptText: string;
promptType: 0;
promptIcon: 0;
}
export namespace ClickInlineKeyboardButton {
export const command = 0x112E;
export const subCommand = 1;
export interface Params {
groupId: number;
botAppid: number;
buttonId: string;
callbackData: string;
msgSeq: number;
}
export type Deps = OidbSender;
export const serialize = (p: Params): Oidb0x112eReq => ({
botAppid: BigInt(p.botAppid),
msgSeq: BigInt(p.msgSeq),
buttonId: String(p.buttonId),
callbackData: String(p.callbackData || ''),
unknown7: 0,
groupId: BigInt(p.groupId),
unknown9: 1,
});
export const deserialize = (body: Oidb0x112eResp): InlineButtonClickResult => ({
result: Number(body.result || 0),
errMsg: body.errMsg || '',
status: 0,
promptText: body.promptText || '',
promptType: 0,
promptIcon: 0,
});
export const encode = (env: OidbBase<Oidb0x112eReq>): Uint8Array =>
protobuf_encode<OidbBase<Oidb0x112eReq>>(env);
export const decode = (bytes: Uint8Array): OidbBase<Oidb0x112eResp> =>
protobuf_decode<OidbBase<Oidb0x112eResp>>(bytes);
export const invoke = (deps: Deps, params: Params): Promise<InlineButtonClickResult> =>
invokeOidb(deps, ClickInlineKeyboardButton, params);
}
@@ -0,0 +1,53 @@
// 0xEB7_1 — group daily sign-in (群打卡).
//
// **Wire name case**: historically SnowLuma sent this cmd as
// `OidbSvcTrpcTcp.0xEB7_1` (uppercase EB7) while every other cmd uses
// lowercase. The server accepts either, but the refactor's hard rule
// is "wire-byte-equal to before", so we keep the uppercase via the
// `wireName` override. This is the ONLY cmd in the codebase with this
// quirk — every new cmd should use the default lowercase scheme.
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type { Oidb0xeb7Req, Oidb0xeb7Resp } from '@snowluma/proto-defs/oidb-actions/base';
import { invokeOidb, type OidbSender } from '../../oidb-service';
import type { BridgeContext } from '../../bridge-context';
export namespace SendGroupSign {
export const command = 0xEB7;
export const subCommand = 1;
/** Override the default lowercase wire-name to preserve the
* historic `OidbSvcTrpcTcp.0xEB7_1` byte-for-byte. */
export const wireName = (): string => 'OidbSvcTrpcTcp.0xEB7_1';
export interface Params {
groupId: number;
}
export type Deps = OidbSender & Pick<BridgeContext, 'identity'>;
export const serialize = (p: Params, uin: string): Oidb0xeb7Req => ({
signInInfo: {
uin,
groupId: String(p.groupId),
version: '9.0.90',
},
});
export const deserialize = (_: Oidb0xeb7Resp): void => {};
export const encode = (env: OidbBase<Oidb0xeb7Req>): Uint8Array =>
protobuf_encode<OidbBase<Oidb0xeb7Req>>(env);
export const decode = (bytes: Uint8Array): OidbBase<Oidb0xeb7Resp> =>
protobuf_decode<OidbBase<Oidb0xeb7Resp>>(bytes);
export const invoke = (deps: Deps, params: Params): Promise<void> => {
const uin = String(deps.identity.uin);
return invokeOidb(deps, {
...SendGroupSign,
serialize: p => serialize(p, uin),
}, params);
};
}
@@ -0,0 +1,45 @@
// 0x990_2 — server-side English → Chinese translation. Returns the
// translated `dstWords` 1:1 paired with the input `words`. Magic
// constants `tag10=1` / `tag12=1` are documented as "always 1" in
// production traffic (purpose unknown).
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type { Oidb0x990Req, Oidb0x990Resp } from '@snowluma/proto-defs/oidb-actions/base';
import { invokeOidb, type OidbSender } from '../../oidb-service';
export namespace TranslateEnToZh {
export const command = 0x990;
export const subCommand = 2;
export interface Params {
words: string[];
}
export type Deps = OidbSender;
export const serialize = (p: Params): Oidb0x990Req => ({
translateReq: {
srcLang: 'en',
dstLang: 'zh',
words: p.words,
},
tag10: 1,
tag12: 1,
});
export const deserialize = (body: Oidb0x990Resp): string[] => {
const resp = body.translateResp;
if (!resp) throw new Error('translate response empty');
return resp.dstWords || [];
};
export const encode = (env: OidbBase<Oidb0x990Req>): Uint8Array =>
protobuf_encode<OidbBase<Oidb0x990Req>>(env);
export const decode = (bytes: Uint8Array): OidbBase<Oidb0x990Resp> =>
protobuf_decode<OidbBase<Oidb0x990Resp>>(bytes);
export const invoke = (deps: Deps, params: Params): Promise<string[]> =>
invokeOidb(deps, TranslateEnToZh, params);
}