refactor(packages): rename @snowluma/bridge → @snowluma/protocol
The package previously named "bridge" houses the protocol-byte layer (OIDB cmds, msg-push decoders, highway uploaders, element-builder, event bus). The name "bridge" suggested transport/lifecycle, which it isn't — that role lives in core/hook and core/bridge/manager. Rename to match what's actually inside. This is a pure rename: zero logic changes, all 73 import sites updated mechanically and TS-verified. core/onebot dependencies key updated. ESLint override path adjusted for the moved oidb-services directory. Rename detection threshold: git log --find-renames=20% recommended when following history across this commit — content-replacement (@snowluma/bridge → @snowluma/protocol) dropped per-file similarity below git's default 50% on import-heavy files.
This commit is contained in:
238 files changed
+247
-284
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 = (_ctx: Deps, 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 = (_ctx: Deps, 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,48 @@
|
||||
// 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 = (ctx: Deps, p: Params): Oidb0xeb7Req => ({
|
||||
signInInfo: {
|
||||
uin: String(ctx.identity.uin),
|
||||
groupId: String(p.groupId),
|
||||
version: '9.0.90',
|
||||
},
|
||||
});
|
||||
|
||||
export const deserialize = (_ctx: Deps, _: 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> =>
|
||||
invokeOidb(deps, SendGroupSign, 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 = (_ctx: Deps, p: Params): Oidb0x990Req => ({
|
||||
translateReq: {
|
||||
srcLang: 'en',
|
||||
dstLang: 'zh',
|
||||
words: p.words,
|
||||
},
|
||||
tag10: 1,
|
||||
tag12: 1,
|
||||
});
|
||||
|
||||
export const deserialize = (_ctx: Deps, 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);
|
||||
}
|
||||
Reference in new issue
Block a user