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:
DrSmoothl committed 2026-05-23 23:31:03 +08:00
1 parent 98296fcec5
commit c16064d7e3
238 files changed
+247 -284

No files matched your search

@@ -0,0 +1,58 @@
// 0x8A7_0 — query "@everyone" remaining-use budget for the bot in
// the given group. Server returns two independent counters: a
// per-uin budget (the bot's daily allowance) and a per-group budget
// (the group's shared allowance). The OneBot action surfaces both
// alongside a single `can_at_all` boolean.
//
// The req's `basic{1,2,3}` triplet (1/2/1) is the wire-known
// validation cookie NTQQ emits; the server rejects requests with
// different values. `type = 0` means "query" (no other type seen).
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type { Oidb0x8a7Req, Oidb0x8a7Resp } from '@snowluma/proto-defs/oidb-actions/base';
import { invokeOidb, type OidbSender } from '../../oidb-service';
import type { BridgeContext } from '../../bridge-context';
export interface AtAllRemain {
can_at_all: boolean;
remain_at_all_count_for_group: number;
remain_at_all_count_for_uin: number;
}
export namespace GetAtAllRemain {
export const command = 0x8A7;
export const subCommand = 0;
export interface Params { groupId: number; }
export type Deps = OidbSender & Pick<BridgeContext, 'identity'>;
export const serialize = (ctx: Deps, p: Params): Oidb0x8a7Req => ({
basic1: 1,
basic2: 2,
basic3: 1,
uin: BigInt(ctx.identity.uin),
groupId: BigInt(p.groupId),
type: 0,
});
export const deserialize = (_ctx: Deps, body: Oidb0x8a7Resp): AtAllRemain => {
// Cast numbers to plain Number: the OIDB layer may surface uint32
// as BigInt and the WebUI JSON serializer chokes on those.
return {
can_at_all: !!body.canAtAll,
remain_at_all_count_for_group: Number(body.groupRemain ?? 0),
remain_at_all_count_for_uin: Number(body.uinRemain ?? 0),
};
};
export const encode = (env: OidbBase<Oidb0x8a7Req>): Uint8Array =>
protobuf_encode<OidbBase<Oidb0x8a7Req>>(env);
export const decode = (bytes: Uint8Array): OidbBase<Oidb0x8a7Resp> =>
protobuf_decode<OidbBase<Oidb0x8a7Resp>>(bytes);
export const invoke = (deps: Deps, params: Params): Promise<AtAllRemain> =>
invokeOidb(deps, GetAtAllRemain, params);
}
@@ -0,0 +1,42 @@
// 0x8A0_1 — single-member kick. The batch variant (kickMembers) uses
// the same cmd but a different proto body shape; kept as a separate
// namespace because proton needs distinct types per call site.
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase, OidbEmpty } from '@snowluma/proto-defs/oidb';
import type { OidbKickMember } from '@snowluma/proto-defs/oidb-actions/base';
import { invokeOidb, type OidbSender } from '../../oidb-service';
import type { BridgeContext } from '../../bridge-context';
export namespace KickMember {
export const command = 0x8A0;
export const subCommand = 1;
export interface Params {
groupId: number;
userId: number;
/** Reject the kicked user's future join requests. */
reject: boolean;
reason?: string;
}
export type Deps = OidbSender & Pick<BridgeContext, 'resolveUserUid'>;
export const serialize = async (ctx: Deps, p: Params): Promise<OidbKickMember> => ({
groupUin: p.groupId,
targetUid: await ctx.resolveUserUid(p.userId, p.groupId),
rejectAddRequest: p.reject,
reason: p.reason ?? '',
});
export const deserialize = (_ctx: Deps, _: OidbEmpty): void => {};
export const encode = (env: OidbBase<OidbKickMember>): Uint8Array =>
protobuf_encode<OidbBase<OidbKickMember>>(env);
export const decode = (bytes: Uint8Array): OidbBase<OidbEmpty> =>
protobuf_decode<OidbBase<OidbEmpty>>(bytes);
export const invoke = (deps: Deps, params: Params): Promise<void> =>
invokeOidb(deps, KickMember, params);
}
@@ -0,0 +1,41 @@
// 0x8A0_1 — batch member kick (repeated targetUids). Same cmd+subcmd
// as KickMember (single) but a different proto body shape; separate
// namespace so proton can monomorphize independently.
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase, OidbEmpty } from '@snowluma/proto-defs/oidb';
import type { Oidb0x8a0Req } from '@snowluma/proto-defs/oidb-actions/base';
import { invokeOidb, type OidbSender } from '../../oidb-service';
import type { BridgeContext } from '../../bridge-context';
export namespace KickMembers {
export const command = 0x8A0;
export const subCommand = 1;
export interface Params {
groupId: number;
userIds: number[];
reject: boolean;
}
export type Deps = OidbSender & Pick<BridgeContext, 'resolveUserUid'>;
export const serialize = async (ctx: Deps, p: Params): Promise<Oidb0x8a0Req> => ({
groupId: BigInt(p.groupId),
targetUids: await Promise.all(p.userIds.map(uid => ctx.resolveUserUid(uid, p.groupId))),
rejectAddRequest: p.reject ? 1 : 0,
kickReason: new Uint8Array(0),
field12: 0,
});
export const deserialize = (_ctx: Deps, _: OidbEmpty): void => {};
export const encode = (env: OidbBase<Oidb0x8a0Req>): Uint8Array =>
protobuf_encode<OidbBase<Oidb0x8a0Req>>(env);
export const decode = (bytes: Uint8Array): OidbBase<OidbEmpty> =>
protobuf_decode<OidbBase<OidbEmpty>>(bytes);
export const invoke = (deps: Deps, params: Params): Promise<void> =>
invokeOidb(deps, KickMembers, params);
}
@@ -0,0 +1,23 @@
// 0x1097_1 — leave a group (退群).
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase, OidbEmpty } from '@snowluma/proto-defs/oidb';
import type { OidbLeaveGroup } from '@snowluma/proto-defs/oidb-actions/base';
import { invokeOidb, type OidbSender } from '../../oidb-service';
export namespace LeaveGroup {
export const command = 0x1097;
export const subCommand = 1;
export interface Params { groupId: number; }
export type Deps = OidbSender;
export const serialize = (_ctx: Deps, p: Params): OidbLeaveGroup => ({ groupUin: p.groupId });
export const deserialize = (_ctx: Deps, _: OidbEmpty): void => {};
export const encode = (env: OidbBase<OidbLeaveGroup>): Uint8Array =>
protobuf_encode<OidbBase<OidbLeaveGroup>>(env);
export const decode = (bytes: Uint8Array): OidbBase<OidbEmpty> =>
protobuf_decode<OidbBase<OidbEmpty>>(bytes);
export const invoke = (deps: Deps, params: Params): Promise<void> =>
invokeOidb(deps, LeaveGroup, params);
}
@@ -0,0 +1,34 @@
// 0x89A_0 — toggle group全员禁言. `state` is the duration multiplier
// (0xFFFFFFFF for permanent mute, 0 for unmute). Multiple OIDB cmds
// share the (0x89A, 0) tuple — see also SetAddOption / SetSearch /
// SetName — disambiguated by the body proto shape.
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase, OidbEmpty } from '@snowluma/proto-defs/oidb';
import type { OidbMuteAll } from '@snowluma/proto-defs/oidb-actions/base';
import { invokeOidb, type OidbSender } from '../../oidb-service';
export namespace MuteAll {
export const command = 0x89A;
export const subCommand = 0;
export interface Params { groupId: number; enable: boolean; }
export type Deps = OidbSender;
export const serialize = (_ctx: Deps, p: Params): OidbMuteAll => ({
groupUin: p.groupId,
muteState: { state: p.enable ? 0xFFFFFFFF : 0 },
});
export const deserialize = (_ctx: Deps, _: OidbEmpty): void => {};
export const encode = (env: OidbBase<OidbMuteAll>): Uint8Array =>
protobuf_encode<OidbBase<OidbMuteAll>>(env);
export const decode = (bytes: Uint8Array): OidbBase<OidbEmpty> =>
protobuf_decode<OidbBase<OidbEmpty>>(bytes);
export const invoke = (deps: Deps, params: Params): Promise<void> =>
invokeOidb(deps, MuteAll, params);
}
@@ -0,0 +1,36 @@
// 0x1253_1 — mute a single group member for `duration` seconds.
// Server treats duration = 0 as "unmute now".
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase, OidbEmpty } from '@snowluma/proto-defs/oidb';
import type { OidbMuteMember } from '@snowluma/proto-defs/oidb-actions/base';
import { invokeOidb, type OidbSender } from '../../oidb-service';
import type { BridgeContext } from '../../bridge-context';
export namespace MuteMember {
export const command = 0x1253;
export const subCommand = 1;
export interface Params { groupId: number; userId: number; duration: number; }
export type Deps = OidbSender & Pick<BridgeContext, 'resolveUserUid'>;
export const serialize = async (ctx: Deps, p: Params): Promise<OidbMuteMember> => ({
groupUin: p.groupId, type: 1,
body: {
targetUid: await ctx.resolveUserUid(p.userId, p.groupId),
duration: p.duration,
},
});
export const deserialize = (_ctx: Deps, _: OidbEmpty): void => {};
export const encode = (env: OidbBase<OidbMuteMember>): Uint8Array =>
protobuf_encode<OidbBase<OidbMuteMember>>(env);
export const decode = (bytes: Uint8Array): OidbBase<OidbEmpty> =>
protobuf_decode<OidbBase<OidbEmpty>>(bytes);
export const invoke = (deps: Deps, params: Params): Promise<void> =>
invokeOidb(deps, MuteMember, params);
}
@@ -0,0 +1,34 @@
// 0x89A_0 — set group "how to join" option (anyone / verification /
// owner-only / etc). Same cmd+subcmd as MuteAll / SetSearch / SetName
// — disambiguated by the body proto shape.
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase, OidbEmpty } from '@snowluma/proto-defs/oidb';
import type { Oidb0x89a_0AddOption } from '@snowluma/proto-defs/oidb-actions/base';
import { invokeOidb, type OidbSender } from '../../oidb-service';
export namespace SetAddOption {
export const command = 0x89A;
export const subCommand = 0;
export interface Params { groupId: number; addType: number; }
export type Deps = OidbSender;
export const serialize = (_ctx: Deps, p: Params): Oidb0x89a_0AddOption => ({
groupUin: BigInt(p.groupId),
settings: { addType: p.addType },
field12: 0,
});
export const deserialize = (_ctx: Deps, _: OidbEmpty): void => {};
export const encode = (env: OidbBase<Oidb0x89a_0AddOption>): Uint8Array =>
protobuf_encode<OidbBase<Oidb0x89a_0AddOption>>(env);
export const decode = (bytes: Uint8Array): OidbBase<OidbEmpty> =>
protobuf_decode<OidbBase<OidbEmpty>>(bytes);
export const invoke = (deps: Deps, params: Params): Promise<void> =>
invokeOidb(deps, SetAddOption, params);
}
@@ -0,0 +1,49 @@
// 0x10C8 — approve/reject a pending group join request.
// subCommand 1 = main inbox, 2 = filtered inbox
//
// `uinForm=true` matches the request shape NTQQ emits. `accept: 1`
// is the server discriminator for approve; `2` for reject.
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase, OidbEmpty } from '@snowluma/proto-defs/oidb';
import type { OidbGroupRequestAction } from '@snowluma/proto-defs/oidb-actions/base';
import { invokeOidb, type OidbSender } from '../../oidb-service';
export namespace SetAddRequest {
export const command = 0x10C8;
export const uinForm = true;
export interface Params {
groupId: number;
sequence: number;
eventType: number;
approve: boolean;
reason?: string;
filtered?: boolean;
}
export type Deps = OidbSender;
export const resolveSubCommand = (p: Params): number => p.filtered ? 2 : 1;
export const serialize = (_ctx: Deps, p: Params): OidbGroupRequestAction => ({
accept: p.approve ? 1 : 2,
body: {
sequence: BigInt(p.sequence),
eventType: p.eventType,
groupUin: p.groupId,
message: p.reason ?? '',
},
});
export const deserialize = (_ctx: Deps, _: OidbEmpty): void => {};
export const encode = (env: OidbBase<OidbGroupRequestAction>): Uint8Array =>
protobuf_encode<OidbBase<OidbGroupRequestAction>>(env);
export const decode = (bytes: Uint8Array): OidbBase<OidbEmpty> =>
protobuf_decode<OidbBase<OidbEmpty>>(bytes);
export const invoke = (deps: Deps, params: Params): Promise<void> =>
invokeOidb(deps, SetAddRequest, params);
}
@@ -0,0 +1,30 @@
// 0x1096_1 — promote / demote a member to/from group administrator.
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase, OidbEmpty } from '@snowluma/proto-defs/oidb';
import type { OidbSetAdmin } from '@snowluma/proto-defs/oidb-actions/base';
import { invokeOidb, type OidbSender } from '../../oidb-service';
import type { BridgeContext } from '../../bridge-context';
export namespace SetAdmin {
export const command = 0x1096;
export const subCommand = 1;
export interface Params { groupId: number; userId: number; enable: boolean; }
export type Deps = OidbSender & Pick<BridgeContext, 'resolveUserUid'>;
export const serialize = async (ctx: Deps, p: Params): Promise<OidbSetAdmin> => ({
groupUin: p.groupId,
uid: await ctx.resolveUserUid(p.userId, p.groupId),
isAdmin: p.enable,
});
export const deserialize = (_ctx: Deps, _: OidbEmpty): void => {};
export const encode = (env: OidbBase<OidbSetAdmin>): Uint8Array =>
protobuf_encode<OidbBase<OidbSetAdmin>>(env);
export const decode = (bytes: Uint8Array): OidbBase<OidbEmpty> =>
protobuf_decode<OidbBase<OidbEmpty>>(bytes);
export const invoke = (deps: Deps, params: Params): Promise<void> =>
invokeOidb(deps, SetAdmin, params);
}
@@ -0,0 +1,27 @@
// 0x89A_15 — rename the group.
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase, OidbEmpty } from '@snowluma/proto-defs/oidb';
import type { OidbRenameGroup } from '@snowluma/proto-defs/oidb-actions/base';
import { invokeOidb, type OidbSender } from '../../oidb-service';
export namespace SetGroupName {
export const command = 0x89A;
export const subCommand = 15;
export interface Params { groupId: number; name: string; }
export type Deps = OidbSender;
export const serialize = (_ctx: Deps, p: Params): OidbRenameGroup => ({
groupUin: p.groupId, body: { targetName: p.name },
});
export const deserialize = (_ctx: Deps, _: OidbEmpty): void => {};
export const encode = (env: OidbBase<OidbRenameGroup>): Uint8Array =>
protobuf_encode<OidbBase<OidbRenameGroup>>(env);
export const decode = (bytes: Uint8Array): OidbBase<OidbEmpty> =>
protobuf_decode<OidbBase<OidbEmpty>>(bytes);
export const invoke = (deps: Deps, params: Params): Promise<void> =>
invokeOidb(deps, SetGroupName, params);
}
@@ -0,0 +1,29 @@
// 0xF16_1 — set the bot's local-only label/remark for a group (only
// the bot sees this — the group's actual name is untouched).
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase, OidbEmpty } from '@snowluma/proto-defs/oidb';
import type { Oidb0xf16Req } from '@snowluma/proto-defs/oidb-actions/base';
import { invokeOidb, type OidbSender } from '../../oidb-service';
export namespace SetGroupRemark {
export const command = 0xF16;
export const subCommand = 1;
export interface Params { groupId: number; remark: string; }
export type Deps = OidbSender;
export const serialize = (_ctx: Deps, p: Params): Oidb0xf16Req => ({
inner: { groupId: BigInt(p.groupId), remark: p.remark },
field12: 0,
});
export const deserialize = (_ctx: Deps, _: OidbEmpty): void => {};
export const encode = (env: OidbBase<Oidb0xf16Req>): Uint8Array =>
protobuf_encode<OidbBase<Oidb0xf16Req>>(env);
export const decode = (bytes: Uint8Array): OidbBase<OidbEmpty> =>
protobuf_decode<OidbBase<OidbEmpty>>(bytes);
export const invoke = (deps: Deps, params: Params): Promise<void> =>
invokeOidb(deps, SetGroupRemark, params);
}
@@ -0,0 +1,32 @@
// 0x8FC_3 — set a member's group-card (群名片).
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase, OidbEmpty } from '@snowluma/proto-defs/oidb';
import type { OidbRenameMember } from '@snowluma/proto-defs/oidb-actions/base';
import { invokeOidb, type OidbSender } from '../../oidb-service';
import type { BridgeContext } from '../../bridge-context';
export namespace SetMemberCard {
export const command = 0x8FC;
export const subCommand = 3;
export interface Params { groupId: number; userId: number; card: string; }
export type Deps = OidbSender & Pick<BridgeContext, 'resolveUserUid'>;
export const serialize = async (ctx: Deps, p: Params): Promise<OidbRenameMember> => ({
groupUin: p.groupId,
body: {
targetUid: await ctx.resolveUserUid(p.userId, p.groupId),
targetName: p.card,
},
});
export const deserialize = (_ctx: Deps, _: OidbEmpty): void => {};
export const encode = (env: OidbBase<OidbRenameMember>): Uint8Array =>
protobuf_encode<OidbBase<OidbRenameMember>>(env);
export const decode = (bytes: Uint8Array): OidbBase<OidbEmpty> =>
protobuf_decode<OidbBase<OidbEmpty>>(bytes);
export const invoke = (deps: Deps, params: Params): Promise<void> =>
invokeOidb(deps, SetMemberCard, params);
}
@@ -0,0 +1,33 @@
// 0x89A_0 — toggle group "searchable" flag. Same cmd+subcmd shape as
// MuteAll / SetAddOption / SetName.
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase, OidbEmpty } from '@snowluma/proto-defs/oidb';
import type { Oidb0x89a_0Search } from '@snowluma/proto-defs/oidb-actions/base';
import { invokeOidb, type OidbSender } from '../../oidb-service';
export namespace SetSearch {
export const command = 0x89A;
export const subCommand = 0;
export interface Params { groupId: number; }
export type Deps = OidbSender;
export const serialize = (_ctx: Deps, p: Params): Oidb0x89a_0Search => ({
groupUin: BigInt(p.groupId),
settings: new Uint8Array(0),
field12: 0,
});
export const deserialize = (_ctx: Deps, _: OidbEmpty): void => {};
export const encode = (env: OidbBase<Oidb0x89a_0Search>): Uint8Array =>
protobuf_encode<OidbBase<Oidb0x89a_0Search>>(env);
export const decode = (bytes: Uint8Array): OidbBase<OidbEmpty> =>
protobuf_decode<OidbBase<OidbEmpty>>(bytes);
export const invoke = (deps: Deps, params: Params): Promise<void> =>
invokeOidb(deps, SetSearch, params);
}
@@ -0,0 +1,34 @@
// 0x8FC_2 — assign a member a "special title" (群头衔). `expireTime=-1`
// is the wire constant for "permanent".
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase, OidbEmpty } from '@snowluma/proto-defs/oidb';
import type { OidbSpecialTitle } from '@snowluma/proto-defs/oidb-actions/base';
import { invokeOidb, type OidbSender } from '../../oidb-service';
import type { BridgeContext } from '../../bridge-context';
export namespace SetSpecialTitle {
export const command = 0x8FC;
export const subCommand = 2;
export interface Params { groupId: number; userId: number; title: string; }
export type Deps = OidbSender & Pick<BridgeContext, 'resolveUserUid'>;
export const serialize = async (ctx: Deps, p: Params): Promise<OidbSpecialTitle> => ({
groupUin: p.groupId,
body: {
targetUid: await ctx.resolveUserUid(p.userId, p.groupId),
specialTitle: p.title,
expireTime: -1,
},
});
export const deserialize = (_ctx: Deps, _: OidbEmpty): void => {};
export const encode = (env: OidbBase<OidbSpecialTitle>): Uint8Array =>
protobuf_encode<OidbBase<OidbSpecialTitle>>(env);
export const decode = (bytes: Uint8Array): OidbBase<OidbEmpty> =>
protobuf_decode<OidbBase<OidbEmpty>>(bytes);
export const invoke = (deps: Deps, params: Params): Promise<void> =>
invokeOidb(deps, SetSpecialTitle, params);
}