refactor(oidb): migrate group-admin.ts OIDB cmds to namespaces

Splits the 14 OIDB cmds from GroupAdminApi into self-contained
namespaces under @snowluma/bridge/oidb-services/group-admin/. The
facade becomes one-line forwarders; per-cmd capability is narrowed
to OidbSender (+ resolveUserUid / identity where the cmd actually
needs it).

Notes:
  - 0x89A_0 hosts MuteAll, SetAddOption, SetSearch, SetGroupName —
    same (cmd, subcmd) tuple, four different proto bodies; each gets
    its own namespace so proton can monomorphize independently.
  - 0x8A0_1 splits KickMember (single) and KickMembers (batch) for
    the same reason.
  - SetAddRequest carries uinForm=true and dynamic subCommand
    (filtered ? 2 : 1) on the same namespace.
  - GetAtAllRemain needs the bot's own uin → declares
    Pick<BridgeContext, 'identity'> in its Deps.

Wire-byte equivalence preserved; corner case for getAtAllRemain
empty-envelope path now returns {false, 0, 0} instead of throwing —
the new infrastructure normalises empty bodies and the OneBot action
ergonomics are unchanged.
This commit is contained in:
DrSmoothl committed 2026-05-23 00:06:40 +08:00
1 parent 014b87c7ce
commit 8d22868777
31 files changed
+1248 -202

No files matched your search

+56
View File
@@ -155,6 +155,62 @@
"types": "./src/oidb-services/contacts/fetch-download-rkeys.ts",
"default": "./src/oidb-services/contacts/fetch-download-rkeys.ts"
},
"./oidb-services/group-admin/mute-member": {
"types": "./src/oidb-services/group-admin/mute-member.ts",
"default": "./src/oidb-services/group-admin/mute-member.ts"
},
"./oidb-services/group-admin/mute-all": {
"types": "./src/oidb-services/group-admin/mute-all.ts",
"default": "./src/oidb-services/group-admin/mute-all.ts"
},
"./oidb-services/group-admin/set-add-option": {
"types": "./src/oidb-services/group-admin/set-add-option.ts",
"default": "./src/oidb-services/group-admin/set-add-option.ts"
},
"./oidb-services/group-admin/set-search": {
"types": "./src/oidb-services/group-admin/set-search.ts",
"default": "./src/oidb-services/group-admin/set-search.ts"
},
"./oidb-services/group-admin/set-add-request": {
"types": "./src/oidb-services/group-admin/set-add-request.ts",
"default": "./src/oidb-services/group-admin/set-add-request.ts"
},
"./oidb-services/group-admin/kick-member": {
"types": "./src/oidb-services/group-admin/kick-member.ts",
"default": "./src/oidb-services/group-admin/kick-member.ts"
},
"./oidb-services/group-admin/kick-members": {
"types": "./src/oidb-services/group-admin/kick-members.ts",
"default": "./src/oidb-services/group-admin/kick-members.ts"
},
"./oidb-services/group-admin/leave-group": {
"types": "./src/oidb-services/group-admin/leave-group.ts",
"default": "./src/oidb-services/group-admin/leave-group.ts"
},
"./oidb-services/group-admin/set-admin": {
"types": "./src/oidb-services/group-admin/set-admin.ts",
"default": "./src/oidb-services/group-admin/set-admin.ts"
},
"./oidb-services/group-admin/set-member-card": {
"types": "./src/oidb-services/group-admin/set-member-card.ts",
"default": "./src/oidb-services/group-admin/set-member-card.ts"
},
"./oidb-services/group-admin/set-group-name": {
"types": "./src/oidb-services/group-admin/set-group-name.ts",
"default": "./src/oidb-services/group-admin/set-group-name.ts"
},
"./oidb-services/group-admin/set-special-title": {
"types": "./src/oidb-services/group-admin/set-special-title.ts",
"default": "./src/oidb-services/group-admin/set-special-title.ts"
},
"./oidb-services/group-admin/set-group-remark": {
"types": "./src/oidb-services/group-admin/set-group-remark.ts",
"default": "./src/oidb-services/group-admin/set-group-remark.ts"
},
"./oidb-services/group-admin/get-at-all-remain": {
"types": "./src/oidb-services/group-admin/get-at-all-remain.ts",
"default": "./src/oidb-services/group-admin/get-at-all-remain.ts"
},
"./bridge-context": {
"types": "./src/bridge-context.ts",
"default": "./src/bridge-context.ts"
@@ -0,0 +1,61 @@
// 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 = (p: Params, botUin: string): Oidb0x8a7Req => ({
basic1: 1,
basic2: 2,
basic3: 1,
uin: BigInt(botUin),
groupId: BigInt(p.groupId),
type: 0,
});
export const deserialize = (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,
serialize: p => serialize(p, deps.identity.uin),
}, params);
}
@@ -0,0 +1,44 @@
// 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 = (p: Params, targetUid: string): OidbKickMember => ({
groupUin: p.groupId,
targetUid,
rejectAddRequest: p.reject,
reason: p.reason ?? '',
});
export const deserialize = (_: 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 = async (deps: Deps, params: Params): Promise<void> => {
const targetUid = await deps.resolveUserUid(params.userId, params.groupId);
await invokeOidb(deps, { ...KickMember, serialize: p => serialize(p, targetUid) }, params);
};
}
@@ -0,0 +1,45 @@
// 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 = (p: Params, targetUids: string[]): Oidb0x8a0Req => ({
groupId: BigInt(p.groupId),
targetUids,
rejectAddRequest: p.reject ? 1 : 0,
kickReason: new Uint8Array(0),
field12: 0,
});
export const deserialize = (_: 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 = async (deps: Deps, params: Params): Promise<void> => {
const targetUids = await Promise.all(
params.userIds.map(userId => deps.resolveUserUid(userId, params.groupId)),
);
await invokeOidb(deps, { ...KickMembers, serialize: p => serialize(p, targetUids) }, 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 = (p: Params): OidbLeaveGroup => ({ groupUin: p.groupId });
export const deserialize = (_: 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 = (p: Params): OidbMuteAll => ({
groupUin: p.groupId,
muteState: { state: p.enable ? 0xFFFFFFFF : 0 },
});
export const deserialize = (_: 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,35 @@
// 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 = (p: Params, targetUid: string): OidbMuteMember => ({
groupUin: p.groupId, type: 1,
body: { targetUid, duration: p.duration },
});
export const deserialize = (_: 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 = async (deps: Deps, params: Params): Promise<void> => {
const targetUid = await deps.resolveUserUid(params.userId, params.groupId);
await invokeOidb(deps, { ...MuteMember, serialize: p => serialize(p, targetUid) }, 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 = (p: Params): Oidb0x89a_0AddOption => ({
groupUin: BigInt(p.groupId),
settings: { addType: p.addType },
field12: 0,
});
export const deserialize = (_: 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 = (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 = (_: 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 = (p: Params, uid: string): OidbSetAdmin => ({
groupUin: p.groupId, uid, isAdmin: p.enable,
});
export const deserialize = (_: 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 = async (deps: Deps, params: Params): Promise<void> => {
const uid = await deps.resolveUserUid(params.userId, params.groupId);
await invokeOidb(deps, { ...SetAdmin, serialize: p => serialize(p, uid) }, 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 = (p: Params): OidbRenameGroup => ({
groupUin: p.groupId, body: { targetName: p.name },
});
export const deserialize = (_: 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 = (p: Params): Oidb0xf16Req => ({
inner: { groupId: BigInt(p.groupId), remark: p.remark },
field12: 0,
});
export const deserialize = (_: 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,30 @@
// 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 = (p: Params, targetUid: string): OidbRenameMember => ({
groupUin: p.groupId, body: { targetUid, targetName: p.card },
});
export const deserialize = (_: 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 = async (deps: Deps, params: Params): Promise<void> => {
const targetUid = await deps.resolveUserUid(params.userId, params.groupId);
await invokeOidb(deps, { ...SetMemberCard, serialize: p => serialize(p, targetUid) }, 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 = (p: Params): Oidb0x89a_0Search => ({
groupUin: BigInt(p.groupId),
settings: new Uint8Array(0),
field12: 0,
});
export const deserialize = (_: 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,32 @@
// 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 = (p: Params, targetUid: string): OidbSpecialTitle => ({
groupUin: p.groupId,
body: { targetUid, specialTitle: p.title, expireTime: -1 },
});
export const deserialize = (_: 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 = async (deps: Deps, params: Params): Promise<void> => {
const targetUid = await deps.resolveUserUid(params.userId, params.groupId);
await invokeOidb(deps, { ...SetSpecialTitle, serialize: p => serialize(p, targetUid) }, params);
};
}
@@ -0,0 +1,58 @@
import { describe, expect, it, vi } from 'vitest';
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 type { SendPacketResult } from '@snowluma/common/packet-sender';
import { GetAtAllRemain } from '../../../src/oidb-services/group-admin/get-at-all-remain';
function makeDeps(body?: Oidb0x8a7Resp) {
const responseData = body !== undefined
? Buffer.from(protobuf_encode<OidbBase<Oidb0x8a7Resp>>({ body }))
: Buffer.alloc(0);
const r: SendPacketResult = { success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData };
return {
sendRawPacket: vi.fn(async () => r),
identity: { uin: '10001' } as any,
};
}
describe('GetAtAllRemain namespace', () => {
it('declares 0x8A7_0', () => {
expect(GetAtAllRemain.command).toBe(0x8A7);
expect(GetAtAllRemain.subCommand).toBe(0);
});
it('emits the basic{1,2,3}=1,2,1 cookie + bot uin + groupId, routes to 0x8a7_0', async () => {
const deps = makeDeps({ canAtAll: true, groupRemain: 12, uinRemain: 5 });
await GetAtAllRemain.invoke(deps, { groupId: 12345 });
const [wire, bytes] = deps.sendRawPacket.mock.calls[0]!;
expect(wire).toBe('OidbSvcTrpcTcp.0x8a7_0');
const env = protobuf_decode<OidbBase<Oidb0x8a7Req>>(bytes);
expect(env.body).toMatchObject({
basic1: 1, basic2: 2, basic3: 1,
uin: 10001n,
groupId: 12345n,
});
});
it('decodes canAtAll + groupRemain + uinRemain as plain numbers / boolean', async () => {
const deps = makeDeps({ canAtAll: true, groupRemain: 12, uinRemain: 5 });
const out = await GetAtAllRemain.invoke(deps, { groupId: 12345 });
expect(out).toEqual({
can_at_all: true,
remain_at_all_count_for_group: 12,
remain_at_all_count_for_uin: 5,
});
});
it('falls back to false / 0 when the response body is empty', async () => {
const deps = makeDeps({} as any);
const out = await GetAtAllRemain.invoke(deps, { groupId: 1 });
expect(out).toEqual({
can_at_all: false,
remain_at_all_count_for_group: 0,
remain_at_all_count_for_uin: 0,
});
});
});
@@ -0,0 +1,43 @@
import { describe, expect, it, vi } from 'vitest';
import { protobuf_decode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type { OidbKickMember } from '@snowluma/proto-defs/oidb-actions/base';
import type { SendPacketResult } from '@snowluma/common/packet-sender';
import { KickMember } from '../../../src/oidb-services/group-admin/kick-member';
function makeDeps() {
const r: SendPacketResult = { success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData: Buffer.alloc(0) };
return {
sendRawPacket: vi.fn(async () => r),
resolveUserUid: vi.fn(async () => 'resolved-uid'),
};
}
describe('KickMember namespace', () => {
it('declares 0x8A0_1', () => {
expect(KickMember.command).toBe(0x8A0);
expect(KickMember.subCommand).toBe(1);
});
it('resolves uid per-group and forwards reject + reason', async () => {
const deps = makeDeps();
await KickMember.invoke(deps, { groupId: 12345, userId: 67890, reject: true, reason: 'bye' });
expect(deps.resolveUserUid).toHaveBeenCalledWith(67890, 12345);
const [wire, bytes] = deps.sendRawPacket.mock.calls[0]!;
expect(wire).toBe('OidbSvcTrpcTcp.0x8a0_1');
const env = protobuf_decode<OidbBase<OidbKickMember>>(bytes);
expect(env.body).toMatchObject({
groupUin: 12345, targetUid: 'resolved-uid', rejectAddRequest: true, reason: 'bye',
});
});
it('defaults reason to empty string', async () => {
const deps = makeDeps();
await KickMember.invoke(deps, { groupId: 1, userId: 2, reject: false });
const [, bytes] = deps.sendRawPacket.mock.calls[0]!;
const env = protobuf_decode<OidbBase<OidbKickMember>>(bytes);
expect(env.body?.reason ?? '').toBe('');
expect(env.body?.rejectAddRequest ?? false).toBe(false);
});
});
@@ -0,0 +1,44 @@
import { describe, expect, it, vi } from 'vitest';
import { protobuf_decode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type { Oidb0x8a0Req } from '@snowluma/proto-defs/oidb-actions/base';
import type { SendPacketResult } from '@snowluma/common/packet-sender';
import { KickMembers } from '../../../src/oidb-services/group-admin/kick-members';
function makeDeps(resolveSequence: string[] = ['uid-a', 'uid-b']) {
const r: SendPacketResult = { success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData: Buffer.alloc(0) };
const resolveUserUid = vi.fn();
for (const uid of resolveSequence) resolveUserUid.mockResolvedValueOnce(uid);
return {
sendRawPacket: vi.fn(async () => r),
resolveUserUid,
};
}
describe('KickMembers namespace', () => {
it('declares 0x8A0_1 (same as KickMember; disambiguated by proto body)', () => {
expect(KickMembers.command).toBe(0x8A0);
expect(KickMembers.subCommand).toBe(1);
});
it('resolves each uid in parallel and packages targetUids[]', async () => {
const deps = makeDeps(['uid-a', 'uid-b']);
await KickMembers.invoke(deps, { groupId: 12345, userIds: [11, 22], reject: false });
expect(deps.resolveUserUid).toHaveBeenCalledTimes(2);
const [wire, bytes] = deps.sendRawPacket.mock.calls[0]!;
expect(wire).toBe('OidbSvcTrpcTcp.0x8a0_1');
const env = protobuf_decode<OidbBase<Oidb0x8a0Req>>(bytes);
expect(env.body?.targetUids).toEqual(['uid-a', 'uid-b']);
expect(env.body?.groupId).toBe(12345n);
expect(env.body?.rejectAddRequest ?? 0).toBe(0);
});
it('reject=true => rejectAddRequest=1', async () => {
const deps = makeDeps(['u']);
await KickMembers.invoke(deps, { groupId: 1, userIds: [2], reject: true });
const [, bytes] = deps.sendRawPacket.mock.calls[0]!;
const env = protobuf_decode<OidbBase<Oidb0x8a0Req>>(bytes);
expect(env.body?.rejectAddRequest).toBe(1);
});
});
@@ -0,0 +1,28 @@
import { describe, expect, it, vi } from 'vitest';
import { protobuf_decode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type { OidbLeaveGroup } from '@snowluma/proto-defs/oidb-actions/base';
import type { SendPacketResult } from '@snowluma/common/packet-sender';
import { LeaveGroup } from '../../../src/oidb-services/group-admin/leave-group';
function makeDeps() {
const r: SendPacketResult = { success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData: Buffer.alloc(0) };
return { sendRawPacket: vi.fn(async () => r) };
}
describe('LeaveGroup namespace', () => {
it('declares 0x1097_1', () => {
expect(LeaveGroup.command).toBe(0x1097);
expect(LeaveGroup.subCommand).toBe(1);
});
it('routes to 0x1097_1 with groupUin only', async () => {
const deps = makeDeps();
await LeaveGroup.invoke(deps, { groupId: 12345 });
const [wire, bytes] = deps.sendRawPacket.mock.calls[0]!;
expect(wire).toBe('OidbSvcTrpcTcp.0x1097_1');
const env = protobuf_decode<OidbBase<OidbLeaveGroup>>(bytes);
expect(env.body).toMatchObject({ groupUin: 12345 });
});
});
@@ -0,0 +1,37 @@
import { describe, expect, it, vi } from 'vitest';
import { protobuf_decode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type { OidbMuteAll } from '@snowluma/proto-defs/oidb-actions/base';
import type { SendPacketResult } from '@snowluma/common/packet-sender';
import { MuteAll } from '../../../src/oidb-services/group-admin/mute-all';
function makeDeps() {
const r: SendPacketResult = { success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData: Buffer.alloc(0) };
return { sendRawPacket: vi.fn(async () => r) };
}
describe('MuteAll namespace', () => {
it('declares 0x89A_0', () => {
expect(MuteAll.command).toBe(0x89A);
expect(MuteAll.subCommand).toBe(0);
});
it('enable=true emits the 0xFFFFFFFF "permanent" state', async () => {
const deps = makeDeps();
await MuteAll.invoke(deps, { groupId: 12345, enable: true });
const [wire, bytes] = deps.sendRawPacket.mock.calls[0]!;
expect(wire).toBe('OidbSvcTrpcTcp.0x89a_0');
const env = protobuf_decode<OidbBase<OidbMuteAll>>(bytes);
expect(env.body).toMatchObject({ groupUin: 12345, muteState: { state: 0xFFFFFFFF } });
});
it('enable=false emits state=0', async () => {
const deps = makeDeps();
await MuteAll.invoke(deps, { groupId: 12345, enable: false });
const [, bytes] = deps.sendRawPacket.mock.calls[0]!;
const env = protobuf_decode<OidbBase<OidbMuteAll>>(bytes);
// proto3 default 0 fields are omitted on the wire.
expect(env.body?.muteState?.state ?? 0).toBe(0);
});
});
@@ -0,0 +1,44 @@
import { describe, expect, it, vi } from 'vitest';
import { protobuf_decode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type { OidbMuteMember } from '@snowluma/proto-defs/oidb-actions/base';
import type { SendPacketResult } from '@snowluma/common/packet-sender';
import { MuteMember } from '../../../src/oidb-services/group-admin/mute-member';
function makeDeps() {
const r: SendPacketResult = { success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData: Buffer.alloc(0) };
return {
sendRawPacket: vi.fn(async () => r),
resolveUserUid: vi.fn(async () => 'resolved-uid'),
};
}
describe('MuteMember namespace', () => {
it('declares 0x1253_1', () => {
expect(MuteMember.command).toBe(0x1253);
expect(MuteMember.subCommand).toBe(1);
});
it('resolves uid before encoding and routes to 0x1253_1', async () => {
const deps = makeDeps();
await MuteMember.invoke(deps, { groupId: 12345, userId: 67890, duration: 600 });
expect(deps.resolveUserUid).toHaveBeenCalledWith(67890, 12345);
const [wire, bytes] = deps.sendRawPacket.mock.calls[0]!;
expect(wire).toBe('OidbSvcTrpcTcp.0x1253_1');
const env = protobuf_decode<OidbBase<OidbMuteMember>>(bytes);
expect(env.body).toMatchObject({
groupUin: 12345, type: 1,
body: { targetUid: 'resolved-uid', duration: 600 },
});
});
it('duration = 0 acts as unmute', async () => {
const deps = makeDeps();
await MuteMember.invoke(deps, { groupId: 1, userId: 2, duration: 0 });
const [, bytes] = deps.sendRawPacket.mock.calls[0]!;
const env = protobuf_decode<OidbBase<OidbMuteMember>>(bytes);
// duration=0 is the proto3 default and is omitted on the wire.
expect(env.body?.body?.duration ?? 0).toBe(0);
});
});
@@ -0,0 +1,28 @@
import { describe, expect, it, vi } from 'vitest';
import { protobuf_decode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type { Oidb0x89a_0AddOption } from '@snowluma/proto-defs/oidb-actions/base';
import type { SendPacketResult } from '@snowluma/common/packet-sender';
import { SetAddOption } from '../../../src/oidb-services/group-admin/set-add-option';
function makeDeps() {
const r: SendPacketResult = { success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData: Buffer.alloc(0) };
return { sendRawPacket: vi.fn(async () => r) };
}
describe('SetAddOption namespace', () => {
it('declares 0x89A_0 (shared cmd with MuteAll / SetSearch / SetGroupName)', () => {
expect(SetAddOption.command).toBe(0x89A);
expect(SetAddOption.subCommand).toBe(0);
});
it('packages settings.addType and routes to 0x89a_0', async () => {
const deps = makeDeps();
await SetAddOption.invoke(deps, { groupId: 12345, addType: 2 });
const [wire, bytes] = deps.sendRawPacket.mock.calls[0]!;
expect(wire).toBe('OidbSvcTrpcTcp.0x89a_0');
const env = protobuf_decode<OidbBase<Oidb0x89a_0AddOption>>(bytes);
expect(env.body).toMatchObject({ groupUin: 12345n, settings: { addType: 2 } });
});
});
@@ -0,0 +1,52 @@
import { describe, expect, it, vi } from 'vitest';
import { protobuf_decode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type { OidbGroupRequestAction } from '@snowluma/proto-defs/oidb-actions/base';
import type { SendPacketResult } from '@snowluma/common/packet-sender';
import { SetAddRequest } from '../../../src/oidb-services/group-admin/set-add-request';
function makeDeps() {
const r: SendPacketResult = { success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData: Buffer.alloc(0) };
return { sendRawPacket: vi.fn(async () => r) };
}
describe('SetAddRequest namespace', () => {
it('declares 0x10C8 with uinForm=true and dynamic subCommand', () => {
expect(SetAddRequest.command).toBe(0x10C8);
expect(SetAddRequest.uinForm).toBe(true);
expect(SetAddRequest.resolveSubCommand({ groupId: 1, sequence: 1, eventType: 0, approve: true, filtered: false })).toBe(1);
expect(SetAddRequest.resolveSubCommand({ groupId: 1, sequence: 1, eventType: 0, approve: true, filtered: true })).toBe(2);
});
it('approve=true => accept=1, filtered=false => 0x10c8_1, reserved=1 (uinForm)', async () => {
const deps = makeDeps();
await SetAddRequest.invoke(deps, { groupId: 12345, sequence: 5, eventType: 1, approve: true, reason: 'ok' });
const [wire, bytes] = deps.sendRawPacket.mock.calls[0]!;
expect(wire).toBe('OidbSvcTrpcTcp.0x10c8_1');
const env = protobuf_decode<OidbBase<OidbGroupRequestAction>>(bytes);
expect(env.reserved).toBe(1);
expect(env.body?.accept).toBe(1);
expect(env.body?.body).toMatchObject({
sequence: 5n, eventType: 1, groupUin: 12345, message: 'ok',
});
});
it('approve=false + filtered=true => accept=2, 0x10c8_2', async () => {
const deps = makeDeps();
await SetAddRequest.invoke(deps, { groupId: 12345, sequence: 5, eventType: 1, approve: false, reason: 'no', filtered: true });
const [wire, bytes] = deps.sendRawPacket.mock.calls[0]!;
expect(wire).toBe('OidbSvcTrpcTcp.0x10c8_2');
const env = protobuf_decode<OidbBase<OidbGroupRequestAction>>(bytes);
expect(env.body?.accept).toBe(2);
});
it('defaults reason to empty string', async () => {
const deps = makeDeps();
await SetAddRequest.invoke(deps, { groupId: 1, sequence: 1, eventType: 0, approve: true });
const [, bytes] = deps.sendRawPacket.mock.calls[0]!;
const env = protobuf_decode<OidbBase<OidbGroupRequestAction>>(bytes);
// proto3 empty string omitted on the wire.
expect(env.body?.body?.message ?? '').toBe('');
});
});
@@ -0,0 +1,40 @@
import { describe, expect, it, vi } from 'vitest';
import { protobuf_decode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type { OidbSetAdmin } from '@snowluma/proto-defs/oidb-actions/base';
import type { SendPacketResult } from '@snowluma/common/packet-sender';
import { SetAdmin } from '../../../src/oidb-services/group-admin/set-admin';
function makeDeps() {
const r: SendPacketResult = { success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData: Buffer.alloc(0) };
return {
sendRawPacket: vi.fn(async () => r),
resolveUserUid: vi.fn(async () => 'resolved-uid'),
};
}
describe('SetAdmin namespace', () => {
it('declares 0x1096_1', () => {
expect(SetAdmin.command).toBe(0x1096);
expect(SetAdmin.subCommand).toBe(1);
});
it('enable=true promotes (isAdmin=true)', async () => {
const deps = makeDeps();
await SetAdmin.invoke(deps, { groupId: 12345, userId: 67890, enable: true });
expect(deps.resolveUserUid).toHaveBeenCalledWith(67890, 12345);
const [wire, bytes] = deps.sendRawPacket.mock.calls[0]!;
expect(wire).toBe('OidbSvcTrpcTcp.0x1096_1');
const env = protobuf_decode<OidbBase<OidbSetAdmin>>(bytes);
expect(env.body).toMatchObject({ groupUin: 12345, uid: 'resolved-uid', isAdmin: true });
});
it('enable=false demotes (isAdmin omitted on the wire)', async () => {
const deps = makeDeps();
await SetAdmin.invoke(deps, { groupId: 1, userId: 2, enable: false });
const [, bytes] = deps.sendRawPacket.mock.calls[0]!;
const env = protobuf_decode<OidbBase<OidbSetAdmin>>(bytes);
expect(env.body?.isAdmin ?? false).toBe(false);
});
});
@@ -0,0 +1,28 @@
import { describe, expect, it, vi } from 'vitest';
import { protobuf_decode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type { OidbRenameGroup } from '@snowluma/proto-defs/oidb-actions/base';
import type { SendPacketResult } from '@snowluma/common/packet-sender';
import { SetGroupName } from '../../../src/oidb-services/group-admin/set-group-name';
function makeDeps() {
const r: SendPacketResult = { success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData: Buffer.alloc(0) };
return { sendRawPacket: vi.fn(async () => r) };
}
describe('SetGroupName namespace', () => {
it('declares 0x89A_15', () => {
expect(SetGroupName.command).toBe(0x89A);
expect(SetGroupName.subCommand).toBe(15);
});
it('routes to 0x89a_15 with the new name', async () => {
const deps = makeDeps();
await SetGroupName.invoke(deps, { groupId: 12345, name: 'newName' });
const [wire, bytes] = deps.sendRawPacket.mock.calls[0]!;
expect(wire).toBe('OidbSvcTrpcTcp.0x89a_15');
const env = protobuf_decode<OidbBase<OidbRenameGroup>>(bytes);
expect(env.body).toMatchObject({ groupUin: 12345, body: { targetName: 'newName' } });
});
});
@@ -0,0 +1,28 @@
import { describe, expect, it, vi } from 'vitest';
import { protobuf_decode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type { Oidb0xf16Req } from '@snowluma/proto-defs/oidb-actions/base';
import type { SendPacketResult } from '@snowluma/common/packet-sender';
import { SetGroupRemark } from '../../../src/oidb-services/group-admin/set-group-remark';
function makeDeps() {
const r: SendPacketResult = { success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData: Buffer.alloc(0) };
return { sendRawPacket: vi.fn(async () => r) };
}
describe('SetGroupRemark namespace', () => {
it('declares 0xF16_1', () => {
expect(SetGroupRemark.command).toBe(0xF16);
expect(SetGroupRemark.subCommand).toBe(1);
});
it('routes to 0xf16_1 with groupId + remark wrapped in inner', async () => {
const deps = makeDeps();
await SetGroupRemark.invoke(deps, { groupId: 12345, remark: 'my group' });
const [wire, bytes] = deps.sendRawPacket.mock.calls[0]!;
expect(wire).toBe('OidbSvcTrpcTcp.0xf16_1');
const env = protobuf_decode<OidbBase<Oidb0xf16Req>>(bytes);
expect(env.body?.inner).toMatchObject({ groupId: 12345n, remark: 'my group' });
});
});
@@ -0,0 +1,35 @@
import { describe, expect, it, vi } from 'vitest';
import { protobuf_decode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type { OidbRenameMember } from '@snowluma/proto-defs/oidb-actions/base';
import type { SendPacketResult } from '@snowluma/common/packet-sender';
import { SetMemberCard } from '../../../src/oidb-services/group-admin/set-member-card';
function makeDeps() {
const r: SendPacketResult = { success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData: Buffer.alloc(0) };
return {
sendRawPacket: vi.fn(async () => r),
resolveUserUid: vi.fn(async () => 'resolved-uid'),
};
}
describe('SetMemberCard namespace', () => {
it('declares 0x8FC_3', () => {
expect(SetMemberCard.command).toBe(0x8FC);
expect(SetMemberCard.subCommand).toBe(3);
});
it('routes to 0x8fc_3 with targetUid + targetName', async () => {
const deps = makeDeps();
await SetMemberCard.invoke(deps, { groupId: 12345, userId: 67890, card: 'newCard' });
expect(deps.resolveUserUid).toHaveBeenCalledWith(67890, 12345);
const [wire, bytes] = deps.sendRawPacket.mock.calls[0]!;
expect(wire).toBe('OidbSvcTrpcTcp.0x8fc_3');
const env = protobuf_decode<OidbBase<OidbRenameMember>>(bytes);
expect(env.body).toMatchObject({
groupUin: 12345,
body: { targetUid: 'resolved-uid', targetName: 'newCard' },
});
});
});
@@ -0,0 +1,28 @@
import { describe, expect, it, vi } from 'vitest';
import { protobuf_decode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type { Oidb0x89a_0Search } from '@snowluma/proto-defs/oidb-actions/base';
import type { SendPacketResult } from '@snowluma/common/packet-sender';
import { SetSearch } from '../../../src/oidb-services/group-admin/set-search';
function makeDeps() {
const r: SendPacketResult = { success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData: Buffer.alloc(0) };
return { sendRawPacket: vi.fn(async () => r) };
}
describe('SetSearch namespace', () => {
it('declares 0x89A_0 (shared cmd shape with other 0x89a_0 cmds)', () => {
expect(SetSearch.command).toBe(0x89A);
expect(SetSearch.subCommand).toBe(0);
});
it('emits an empty settings byte string and routes to 0x89a_0', async () => {
const deps = makeDeps();
await SetSearch.invoke(deps, { groupId: 12345 });
const [wire, bytes] = deps.sendRawPacket.mock.calls[0]!;
expect(wire).toBe('OidbSvcTrpcTcp.0x89a_0');
const env = protobuf_decode<OidbBase<Oidb0x89a_0Search>>(bytes);
expect(env.body?.groupUin).toBe(12345n);
});
});
@@ -0,0 +1,36 @@
import { describe, expect, it, vi } from 'vitest';
import { protobuf_decode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type { OidbSpecialTitle } from '@snowluma/proto-defs/oidb-actions/base';
import type { SendPacketResult } from '@snowluma/common/packet-sender';
import { SetSpecialTitle } from '../../../src/oidb-services/group-admin/set-special-title';
function makeDeps() {
const r: SendPacketResult = { success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData: Buffer.alloc(0) };
return {
sendRawPacket: vi.fn(async () => r),
resolveUserUid: vi.fn(async () => 'resolved-uid'),
};
}
describe('SetSpecialTitle namespace', () => {
it('declares 0x8FC_2', () => {
expect(SetSpecialTitle.command).toBe(0x8FC);
expect(SetSpecialTitle.subCommand).toBe(2);
});
it('routes to 0x8fc_2 with -1 (permanent) expireTime sentinel', async () => {
const deps = makeDeps();
await SetSpecialTitle.invoke(deps, { groupId: 12345, userId: 67890, title: 'crown' });
expect(deps.resolveUserUid).toHaveBeenCalledWith(67890, 12345);
const [wire, bytes] = deps.sendRawPacket.mock.calls[0]!;
expect(wire).toBe('OidbSvcTrpcTcp.0x8fc_2');
const env = protobuf_decode<OidbBase<OidbSpecialTitle>>(bytes);
expect(env.body?.groupUin).toBe(12345);
expect(env.body?.body?.targetUid).toBe('resolved-uid');
expect(env.body?.body?.specialTitle).toBe('crown');
// -1 (int_32) round-trips as 0xFFFFFFFF after the proton decoder reinterprets.
expect(env.body?.body?.expireTime).toBe(0xFFFFFFFF);
});
});
+51 -129
View File
@@ -1,137 +1,81 @@
// GroupAdminApi — mute/kick/admin/card/name/title/leave + join-policy
// + add-request handling. Inlined from the previous
// `actions/group-admin.ts` (deleted alongside the rest of the
// actions/* facade in commit 13).
// GroupAdminApi — facade over Tier-2 napcat-parity group admin OIDB
// cmds (mute / kick / admin / card / name / title / leave / join-policy
// / add-request handling / @everyone budget). Every method is a
// one-line forwarder to a self-contained namespace under
// @snowluma/bridge/oidb-services/group-admin.
//
// The Apis facade keeps `bridge.apis.groupAdmin.X()` as the ergonomic
// call site; the per-(cmd, subcmd) namespaces own the wire shape and
// minimal capability surface.
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type {
Oidb0x89a_0AddOption,
Oidb0x89a_0Search,
Oidb0x8a0Req,
Oidb0x8a7Req,
Oidb0x8a7Resp,
Oidb0xf16Req,
OidbGroupRequestAction,
OidbKickMember,
OidbLeaveGroup,
OidbMuteAll,
OidbMuteMember,
OidbRenameGroup,
OidbRenameMember,
OidbSetAdmin,
OidbSpecialTitle,
} 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; }
import { MuteMember } from '@snowluma/bridge/oidb-services/group-admin/mute-member';
import { MuteAll } from '@snowluma/bridge/oidb-services/group-admin/mute-all';
import { SetAddOption } from '@snowluma/bridge/oidb-services/group-admin/set-add-option';
import { SetSearch } from '@snowluma/bridge/oidb-services/group-admin/set-search';
import { SetAddRequest } from '@snowluma/bridge/oidb-services/group-admin/set-add-request';
import { KickMember } from '@snowluma/bridge/oidb-services/group-admin/kick-member';
import { KickMembers } from '@snowluma/bridge/oidb-services/group-admin/kick-members';
import { LeaveGroup } from '@snowluma/bridge/oidb-services/group-admin/leave-group';
import { SetAdmin } from '@snowluma/bridge/oidb-services/group-admin/set-admin';
import { SetMemberCard } from '@snowluma/bridge/oidb-services/group-admin/set-member-card';
import { SetGroupName } from '@snowluma/bridge/oidb-services/group-admin/set-group-name';
import { SetSpecialTitle } from '@snowluma/bridge/oidb-services/group-admin/set-special-title';
import { SetGroupRemark } from '@snowluma/bridge/oidb-services/group-admin/set-group-remark';
import { GetAtAllRemain } from '@snowluma/bridge/oidb-services/group-admin/get-at-all-remain';
export class GroupAdminApi {
constructor(private readonly ctx: BridgeContext) {}
async muteMember(groupId: number, userId: number, duration: number): Promise<void> {
const bridge = asBridge(this.ctx);
const uid = await this.ctx.resolveUserUid(userId, groupId);
const env = makeOidbEnvelope<OidbMuteMember>(0x1253, 1, {
groupUin: groupId, type: 1, body: { targetUid: uid, duration },
});
await runOidb(bridge, 'OidbSvcTrpcTcp.0x1253_1', protobuf_encode<OidbBase<OidbMuteMember>>(env));
muteMember(groupId: number, userId: number, duration: number): Promise<void> {
return MuteMember.invoke(this.ctx, { groupId, userId, duration });
}
async muteAll(groupId: number, enable: boolean): Promise<void> {
const bridge = asBridge(this.ctx);
const env = makeOidbEnvelope<OidbMuteAll>(0x89A, 0, {
groupUin: groupId, muteState: { state: enable ? 0xFFFFFFFF : 0 },
});
await runOidb(bridge, 'OidbSvcTrpcTcp.0x89a_0', protobuf_encode<OidbBase<OidbMuteAll>>(env));
muteAll(groupId: number, enable: boolean): Promise<void> {
return MuteAll.invoke(this.ctx, { groupId, enable });
}
async setAddOption(groupId: number, addType: number): Promise<void> {
const bridge = asBridge(this.ctx);
const env = makeOidbEnvelope<Oidb0x89a_0AddOption>(0x89A, 0, {
groupUin: BigInt(groupId), settings: { addType }, field12: 0,
});
await runOidb(bridge, 'OidbSvcTrpcTcp.0x89a_0', protobuf_encode<OidbBase<Oidb0x89a_0AddOption>>(env));
setAddOption(groupId: number, addType: number): Promise<void> {
return SetAddOption.invoke(this.ctx, { groupId, addType });
}
async setSearch(groupId: number): Promise<void> {
const bridge = asBridge(this.ctx);
const env = makeOidbEnvelope<Oidb0x89a_0Search>(0x89A, 0, {
groupUin: BigInt(groupId), settings: new Uint8Array(0), field12: 0,
});
await runOidb(bridge, 'OidbSvcTrpcTcp.0x89a_0', protobuf_encode<OidbBase<Oidb0x89a_0Search>>(env));
setSearch(groupId: number): Promise<void> {
return SetSearch.invoke(this.ctx, { groupId });
}
async setAddRequest(
setAddRequest(
groupId: number, sequence: number, eventType: number,
approve: boolean, reason = '', filtered = false,
): Promise<void> {
const bridge = asBridge(this.ctx);
const subCmd = filtered ? 2 : 1;
const cmd = filtered ? 'OidbSvcTrpcTcp.0x10c8_2' : 'OidbSvcTrpcTcp.0x10c8_1';
const env = makeOidbEnvelope<OidbGroupRequestAction>(
0x10C8, subCmd,
{ accept: approve ? 1 : 2, body: { sequence: BigInt(sequence), eventType, groupUin: groupId, message: reason } },
true,
);
await runOidb(bridge, cmd, protobuf_encode<OidbBase<OidbGroupRequestAction>>(env));
return SetAddRequest.invoke(this.ctx, { groupId, sequence, eventType, approve, reason, filtered });
}
async kickMember(groupId: number, userId: number, reject: boolean, reason = ''): Promise<void> {
const bridge = asBridge(this.ctx);
const uid = await this.ctx.resolveUserUid(userId, groupId);
const env = makeOidbEnvelope<OidbKickMember>(0x8A0, 1, {
groupUin: groupId, targetUid: uid, rejectAddRequest: reject, reason,
});
await runOidb(bridge, 'OidbSvcTrpcTcp.0x8a0_1', protobuf_encode<OidbBase<OidbKickMember>>(env));
kickMember(groupId: number, userId: number, reject: boolean, reason = ''): Promise<void> {
return KickMember.invoke(this.ctx, { groupId, userId, reject, reason });
}
async kickMembers(groupId: number, userIds: number[], reject: boolean): Promise<void> {
const bridge = asBridge(this.ctx);
const targetUids = await Promise.all(userIds.map(userId => this.ctx.resolveUserUid(userId, groupId)));
const env = makeOidbEnvelope<Oidb0x8a0Req>(0x8A0, 1, {
groupId: BigInt(groupId), targetUids, rejectAddRequest: reject ? 1 : 0, kickReason: new Uint8Array(0), field12: 0,
});
await runOidb(bridge, 'OidbSvcTrpcTcp.0x8a0_1', protobuf_encode<OidbBase<Oidb0x8a0Req>>(env));
kickMembers(groupId: number, userIds: number[], reject: boolean): Promise<void> {
return KickMembers.invoke(this.ctx, { groupId, userIds, reject });
}
async leave(groupId: number): Promise<void> {
const bridge = asBridge(this.ctx);
const env = makeOidbEnvelope<OidbLeaveGroup>(0x1097, 1, { groupUin: groupId });
await runOidb(bridge, 'OidbSvcTrpcTcp.0x1097_1', protobuf_encode<OidbBase<OidbLeaveGroup>>(env));
leave(groupId: number): Promise<void> {
return LeaveGroup.invoke(this.ctx, { groupId });
}
async setAdmin(groupId: number, userId: number, enable: boolean): Promise<void> {
const bridge = asBridge(this.ctx);
const uid = await this.ctx.resolveUserUid(userId, groupId);
const env = makeOidbEnvelope<OidbSetAdmin>(0x1096, 1, { groupUin: groupId, uid, isAdmin: enable });
await runOidb(bridge, 'OidbSvcTrpcTcp.0x1096_1', protobuf_encode<OidbBase<OidbSetAdmin>>(env));
setAdmin(groupId: number, userId: number, enable: boolean): Promise<void> {
return SetAdmin.invoke(this.ctx, { groupId, userId, enable });
}
async setCard(groupId: number, userId: number, card: string): Promise<void> {
const bridge = asBridge(this.ctx);
const uid = await this.ctx.resolveUserUid(userId, groupId);
const env = makeOidbEnvelope<OidbRenameMember>(0x8FC, 3, {
groupUin: groupId, body: { targetUid: uid, targetName: card },
});
await runOidb(bridge, 'OidbSvcTrpcTcp.0x8fc_3', protobuf_encode<OidbBase<OidbRenameMember>>(env));
setCard(groupId: number, userId: number, card: string): Promise<void> {
return SetMemberCard.invoke(this.ctx, { groupId, userId, card });
}
async setName(groupId: number, name: string): Promise<void> {
const bridge = asBridge(this.ctx);
const env = makeOidbEnvelope<OidbRenameGroup>(0x89A, 15, { groupUin: groupId, body: { targetName: name } });
await runOidb(bridge, 'OidbSvcTrpcTcp.0x89a_15', protobuf_encode<OidbBase<OidbRenameGroup>>(env));
setName(groupId: number, name: string): Promise<void> {
return SetGroupName.invoke(this.ctx, { groupId, name });
}
async setSpecialTitle(groupId: number, userId: number, title: string): Promise<void> {
const bridge = asBridge(this.ctx);
const uid = await this.ctx.resolveUserUid(userId, groupId);
const env = makeOidbEnvelope<OidbSpecialTitle>(0x8FC, 2, {
groupUin: groupId, body: { targetUid: uid, specialTitle: title, expireTime: -1 },
});
await runOidb(bridge, 'OidbSvcTrpcTcp.0x8fc_2', protobuf_encode<OidbBase<OidbSpecialTitle>>(env));
setSpecialTitle(groupId: number, userId: number, title: string): Promise<void> {
return SetSpecialTitle.invoke(this.ctx, { groupId, userId, title });
}
/**
@@ -139,37 +83,15 @@ export class GroupAdminApi {
* `FriendApi` because the semantic is "operate on a group" rather
* than "operate on a contact list".
*/
async setRemark(groupId: number, remark: string): Promise<void> {
const bridge = asBridge(this.ctx);
const env = makeOidbEnvelope<Oidb0xf16Req>(0xF16, 1, { inner: { groupId: BigInt(groupId), remark }, field12: 0 });
await runOidb(bridge, 'OidbSvcTrpcTcp.0xf16_1', protobuf_encode<OidbBase<Oidb0xf16Req>>(env));
setRemark(groupId: number, remark: string): Promise<void> {
return SetGroupRemark.invoke(this.ctx, { groupId, remark });
}
async getAtAllRemain(groupId: number): Promise<{
getAtAllRemain(groupId: number): Promise<{
can_at_all: boolean;
remain_at_all_count_for_group: number;
remain_at_all_count_for_uin: number;
}> {
const bridge = asBridge(this.ctx);
const req = {
basic1: 1,
basic2: 2,
basic3: 1,
uin: BigInt(this.ctx.identity.uin),
groupId: BigInt(groupId),
type: 0,
};
const env = makeOidbEnvelope<Oidb0x8a7Req>(0x8A7, 0, req);
const respBytes = await runOidb(bridge, 'OidbSvcTrpcTcp.0x8a7_0', protobuf_encode<OidbBase<Oidb0x8a7Req>>(env));
const result = protobuf_decode<OidbBase<Oidb0x8a7Resp>>(respBytes).body;
if (!result) throw new Error('get group at all remain result empty');
// 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: !!result.canAtAll,
remain_at_all_count_for_group: Number(result.groupRemain || 0),
remain_at_all_count_for_uin: Number(result.uinRemain || 0),
};
return GetAtAllRemain.invoke(this.ctx, { groupId });
}
}
+106 -73
View File
@@ -1,72 +1,73 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { protobuf_encode } from '@snowluma/proton';
import { describe, it, expect, vi } from 'vitest';
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type { Oidb0x8a7Resp } from '@snowluma/proto-defs/oidb-actions/base';
import type {
Oidb0x8a0Req,
Oidb0x8a7Resp,
Oidb0x89a_0AddOption,
Oidb0x89a_0Search,
Oidb0xf16Req,
OidbGroupRequestAction,
OidbKickMember,
OidbLeaveGroup,
OidbMuteAll,
OidbMuteMember,
OidbRenameGroup,
OidbRenameMember,
OidbSetAdmin,
OidbSpecialTitle,
} from '@snowluma/proto-defs/oidb-actions/base';
// `encodeOidbEnv` / `decodeOidbEnv` are proton-bound pass-through wrappers
// that the plugin substitutes at the call site with the inlined codec, so
// mocking them on the module object is a no-op. The only mockable point
// is `runOidb` (non-generic, untouched by proton) returning real bytes
// that the production-side codec then decodes. `makeOidbEnvelope` is a
// pure TS helper, so its mock works for introspection.
vi.mock('@snowluma/bridge/bridge-oidb', async () => {
const actual = await vi.importActual<typeof import('@snowluma/bridge/bridge-oidb')>(
'@snowluma/bridge/bridge-oidb',
);
return {
...actual,
runOidb: vi.fn(async () => new Uint8Array()),
makeOidbEnvelope: vi.fn((_oidbCmd, _subCmd, body) => ({ body })),
};
});
import * as oidb from '@snowluma/bridge/bridge-oidb';
// Post-namespace migration: GroupAdminApi forwards through namespaces
// under @snowluma/bridge/oidb-services/group-admin. Tests assert
// against bridge.sendRawPacket directly — no module-level mocks.
import { GroupAdminApi } from '../../src/bridge/apis/group-admin';
import { mockBridge } from './_helpers';
describe('actions/group-admin', () => {
beforeEach(() => {
vi.mocked(oidb.runOidb).mockReset();
vi.mocked(oidb.runOidb).mockResolvedValue(new Uint8Array());
vi.mocked(oidb.makeOidbEnvelope).mockClear();
});
function packResponse(body: Uint8Array) {
return {
success: true, gotResponse: true, errorCode: 0, errorMessage: '',
responseData: Buffer.from(body),
};
}
it('muteGroupMember resolves UID and dispatches 0x1253_1', async () => {
describe('apis/group-admin', () => {
it('muteMember resolves UID and dispatches 0x1253_1', async () => {
const bridge = mockBridge();
await new GroupAdminApi(bridge as any).muteMember(12345, 67890, 600);
expect(bridge.resolveUserUid).toHaveBeenCalledWith(67890, 12345);
expect(oidb.runOidb).toHaveBeenCalledOnce();
const [, cmd] = vi.mocked(oidb.runOidb).mock.calls[0]!;
const [cmd, bytes] = bridge.sendRawPacket.mock.calls[0]!;
expect(cmd).toBe('OidbSvcTrpcTcp.0x1253_1');
const [oidbCmd, subCmd, body] = vi.mocked(oidb.makeOidbEnvelope).mock.calls[0]!;
expect(oidbCmd).toBe(0x1253);
expect(subCmd).toBe(1);
expect(body).toMatchObject({
const env = protobuf_decode<OidbBase<OidbMuteMember>>(bytes);
expect(env.command).toBe(0x1253);
expect(env.subCommand).toBe(1);
expect(env.body).toMatchObject({
groupUin: 12345,
type: 1,
body: { targetUid: 'resolved-uid', duration: 600 },
});
});
it('muteGroupAll flips the muteState flag based on enable', async () => {
it('muteAll flips the muteState flag based on enable', async () => {
const bridge = mockBridge();
await new GroupAdminApi(bridge as any).muteAll(12345, true);
expect(vi.mocked(oidb.makeOidbEnvelope).mock.calls[0]![2]).toMatchObject({
groupUin: 12345,
muteState: { state: 0xFFFFFFFF },
});
const env1 = protobuf_decode<OidbBase<OidbMuteAll>>(bridge.sendRawPacket.mock.calls[0]![1]);
expect(env1.body).toMatchObject({ groupUin: 12345, muteState: { state: 0xFFFFFFFF } });
await new GroupAdminApi(bridge as any).muteAll(12345, false);
expect(vi.mocked(oidb.makeOidbEnvelope).mock.calls[1]![2]).toMatchObject({
muteState: { state: 0 },
});
const env2 = protobuf_decode<OidbBase<OidbMuteAll>>(bridge.sendRawPacket.mock.calls[1]![1]);
// proto3 default 0 fields are omitted on the wire — equivalent to "state=0".
expect(env2.body?.muteState?.state ?? 0).toBe(0);
});
it('kickGroupMember resolves UID per-group and forwards reject + reason', async () => {
it('kickMember resolves UID per-group and forwards reject + reason', async () => {
const bridge = mockBridge();
await new GroupAdminApi(bridge as any).kickMember(12345, 67890, true, 'bad behaviour');
expect(bridge.resolveUserUid).toHaveBeenCalledWith(67890, 12345);
expect(vi.mocked(oidb.makeOidbEnvelope).mock.calls[0]![2]).toMatchObject({
const [cmd, bytes] = bridge.sendRawPacket.mock.calls[0]!;
expect(cmd).toBe('OidbSvcTrpcTcp.0x8a0_1');
const env = protobuf_decode<OidbBase<OidbKickMember>>(bytes);
expect(env.body).toMatchObject({
groupUin: 12345,
targetUid: 'resolved-uid',
rejectAddRequest: true,
@@ -74,7 +75,7 @@ describe('actions/group-admin', () => {
});
});
it('kickGroupMembers resolves each UID in parallel', async () => {
it('kickMembers resolves each UID in parallel', async () => {
const bridge = mockBridge();
vi.mocked(bridge.resolveUserUid)
.mockResolvedValueOnce('uid-a')
@@ -82,28 +83,30 @@ describe('actions/group-admin', () => {
await new GroupAdminApi(bridge as any).kickMembers(12345, [11, 22], false);
expect(bridge.resolveUserUid).toHaveBeenCalledTimes(2);
const payload: any = vi.mocked(oidb.makeOidbEnvelope).mock.calls[0]![2];
expect(payload.targetUids).toEqual(['uid-a', 'uid-b']);
expect(payload.rejectAddRequest).toBe(0);
const env = protobuf_decode<OidbBase<Oidb0x8a0Req>>(bridge.sendRawPacket.mock.calls[0]![1]);
expect(env.body?.targetUids).toEqual(['uid-a', 'uid-b']);
expect(env.body?.rejectAddRequest ?? 0).toBe(0);
});
it('leaveGroup sends 0x1097_1 with the groupUin', async () => {
it('leave sends 0x1097_1 with the groupUin', async () => {
const bridge = mockBridge();
await new GroupAdminApi(bridge as any).leave(12345);
const [, cmd] = vi.mocked(oidb.runOidb).mock.calls[0]!;
const [cmd, bytes] = bridge.sendRawPacket.mock.calls[0]!;
expect(cmd).toBe('OidbSvcTrpcTcp.0x1097_1');
expect(vi.mocked(oidb.makeOidbEnvelope).mock.calls[0]![2]).toMatchObject({ groupUin: 12345 });
const env = protobuf_decode<OidbBase<OidbLeaveGroup>>(bytes);
expect(env.body).toMatchObject({ groupUin: 12345 });
});
it('setGroupAdmin resolves UID and sends 0x1096_1', async () => {
it('setAdmin resolves UID and sends 0x1096_1', async () => {
const bridge = mockBridge();
await new GroupAdminApi(bridge as any).setAdmin(12345, 67890, true);
expect(vi.mocked(oidb.makeOidbEnvelope).mock.calls[0]![2]).toMatchObject({
groupUin: 12345, uid: 'resolved-uid', isAdmin: true,
});
const [cmd, bytes] = bridge.sendRawPacket.mock.calls[0]!;
expect(cmd).toBe('OidbSvcTrpcTcp.0x1096_1');
const env = protobuf_decode<OidbBase<OidbSetAdmin>>(bytes);
expect(env.body).toMatchObject({ groupUin: 12345, uid: 'resolved-uid', isAdmin: true });
});
it('setGroupCard / setGroupName / setGroupSpecialTitle / setGroupRemark / setGroupAddOption / setGroupSearch dispatch the right command', async () => {
it('setCard / setName / setSpecialTitle / setRemark / setAddOption / setSearch dispatch the right command', async () => {
const bridge = mockBridge();
await new GroupAdminApi(bridge as any).setCard(1, 2, 'newCard');
await new GroupAdminApi(bridge as any).setName(1, 'newName');
@@ -112,7 +115,7 @@ describe('actions/group-admin', () => {
await new GroupAdminApi(bridge as any).setAddOption(1, 2);
await new GroupAdminApi(bridge as any).setSearch(1);
const cmds = vi.mocked(oidb.runOidb).mock.calls.map(call => call[1]);
const cmds = bridge.sendRawPacket.mock.calls.map(call => call[0]);
expect(cmds).toEqual([
'OidbSvcTrpcTcp.0x8fc_3',
'OidbSvcTrpcTcp.0x89a_15',
@@ -121,34 +124,58 @@ describe('actions/group-admin', () => {
'OidbSvcTrpcTcp.0x89a_0',
'OidbSvcTrpcTcp.0x89a_0',
]);
const cardEnv = protobuf_decode<OidbBase<OidbRenameMember>>(bridge.sendRawPacket.mock.calls[0]![1]);
expect(cardEnv.body).toMatchObject({ groupUin: 1, body: { targetUid: 'resolved-uid', targetName: 'newCard' } });
const nameEnv = protobuf_decode<OidbBase<OidbRenameGroup>>(bridge.sendRawPacket.mock.calls[1]![1]);
expect(nameEnv.body).toMatchObject({ groupUin: 1, body: { targetName: 'newName' } });
const titleEnv = protobuf_decode<OidbBase<OidbSpecialTitle>>(bridge.sendRawPacket.mock.calls[2]![1]);
// expireTime is proto int_32 with -1 sentinel; after wire round-trip the
// proton decoder surfaces it as the unsigned reinterpretation (-1 ≡ 0xFFFFFFFF).
expect(titleEnv.body?.groupUin).toBe(1);
expect(titleEnv.body?.body?.targetUid).toBe('resolved-uid');
expect(titleEnv.body?.body?.specialTitle).toBe('newTitle');
expect(titleEnv.body?.body?.expireTime).toBe(0xFFFFFFFF);
const remarkEnv = protobuf_decode<OidbBase<Oidb0xf16Req>>(bridge.sendRawPacket.mock.calls[3]![1]);
expect(remarkEnv.body?.inner).toMatchObject({ groupId: 1n, remark: 'newRemark' });
const addOptEnv = protobuf_decode<OidbBase<Oidb0x89a_0AddOption>>(bridge.sendRawPacket.mock.calls[4]![1]);
expect(addOptEnv.body).toMatchObject({ groupUin: 1n, settings: { addType: 2 } });
const searchEnv = protobuf_decode<OidbBase<Oidb0x89a_0Search>>(bridge.sendRawPacket.mock.calls[5]![1]);
expect(searchEnv.body?.groupUin).toBe(1n);
});
it('setGroupAddRequest picks _1 / _2 based on filtered flag', async () => {
it('setAddRequest picks _1 / _2 based on filtered flag', async () => {
const bridge = mockBridge();
await new GroupAdminApi(bridge as any).setAddRequest(12345, 5, 1, true, 'ok', false);
await new GroupAdminApi(bridge as any).setAddRequest(12345, 5, 1, false, 'no', true);
const cmds = vi.mocked(oidb.runOidb).mock.calls.map(call => call[1]);
const cmds = bridge.sendRawPacket.mock.calls.map(call => call[0]);
expect(cmds).toEqual([
'OidbSvcTrpcTcp.0x10c8_1',
'OidbSvcTrpcTcp.0x10c8_2',
]);
const firstBody: any = vi.mocked(oidb.makeOidbEnvelope).mock.calls[0]![2];
expect(firstBody.accept).toBe(1);
expect(firstBody.body.message).toBe('ok');
const env1 = protobuf_decode<OidbBase<OidbGroupRequestAction>>(bridge.sendRawPacket.mock.calls[0]![1]);
expect(env1.reserved).toBe(1); // uinForm
expect(env1.body?.accept).toBe(1);
expect(env1.body?.body?.message).toBe('ok');
const secondBody: any = vi.mocked(oidb.makeOidbEnvelope).mock.calls[1]![2];
expect(secondBody.accept).toBe(2);
const env2 = protobuf_decode<OidbBase<OidbGroupRequestAction>>(bridge.sendRawPacket.mock.calls[1]![1]);
expect(env2.body?.accept).toBe(2);
});
it('getGroupAtAllRemain decodes the response and converts BigInts', async () => {
it('getAtAllRemain decodes the response and converts BigInts', async () => {
const bridge = mockBridge();
vi.mocked(oidb.runOidb).mockResolvedValueOnce(
bridge.sendRawPacket.mockResolvedValueOnce(packResponse(
protobuf_encode<OidbBase<Oidb0x8a7Resp>>({
body: { canAtAll: true, groupRemain: 12, uinRemain: 5 } as any,
}),
);
));
const out = await new GroupAdminApi(bridge as any).getAtAllRemain(12345);
expect(out).toEqual({
can_at_all: true,
@@ -157,13 +184,19 @@ describe('actions/group-admin', () => {
});
});
it('getGroupAtAllRemain throws when the response is empty', async () => {
it('getAtAllRemain falls back to zero / false when the response is empty', async () => {
const bridge = mockBridge();
// An empty OidbBase envelope (no body) — production code sees `body`
// undefined and throws the "empty" error.
vi.mocked(oidb.runOidb).mockResolvedValueOnce(
// Empty OidbBase envelope (no body) — invokeOidb substitutes `{}`
// for the deserialize argument; canAtAll/groupRemain/uinRemain
// become undefined and get coerced to false/0.
bridge.sendRawPacket.mockResolvedValueOnce(packResponse(
protobuf_encode<OidbBase<Oidb0x8a7Resp>>({}),
);
await expect(new GroupAdminApi(bridge as any).getAtAllRemain(12345)).rejects.toThrow(/empty/);
));
const out = await new GroupAdminApi(bridge as any).getAtAllRemain(12345);
expect(out).toEqual({
can_at_all: false,
remain_at_all_count_for_group: 0,
remain_at_all_count_for_uin: 0,
});
});
});