fix(protocol): make set_group_search actually apply search flags (#191)

旧实现走 OIDB 0x89a_0 但 settings 发空字节 → 服务端返 ok 却 no-op;action 也只收
group_id,没有设置搜索方式的参数(报告属实)。

真机 RE 定稿(tempserver,bot 为管理员的实群逐字段扫描 + GET 读回):
- 修改命令 = 0x89a_0(全量抓包确认,与 MuteAll 同命令,靠 body 形状区分)。结构
  = {1:groupUin, 2: 只含被改字段的 GroupDetailInfo modify 子消息}。这是与 0x88D_0
  群详情 GET **不同的消息域**(mute/shutUpTime 在此=tag17,在 GET 里却是字符串),
  所以标签不能照搬 GET。
- 在 modify 子消息里逐 tag 试写、经 0x88D_0 GET 读回效果,定位:
  noFingerOpen(关键词/群指纹搜索)=tag 35,noCodeFingerOpen(群号搜索/总开关)=tag 36;
  再对照客户端「被搜索方式」三选下拉(私密/群号/群号+关键词)核实语义与 0/1 取值。
- proto-defs:settings 改为 Oidb0x89a_0SearchSettings 子消息,两 flag 用 pb_optional
  (显式存在)——否则 proto3 丢 0 值,导致关闭(=0)被静默忽略。undefined 仍省略。
- set-search/bridge/action:透传 no_finger_open / no_code_finger_open;只下发提供的
  字段(同 NapCat filter 机制、与 modify-group-ext-info 一致)。catalog regen。
- 编码测试锁定:0 值必发 tag 35/36、未提供则省略、命令为 0x89a_0。

typecheck 12 包干净;protocol 585 / onebot 521 / core 472 全绿。
This commit is contained in:
DrSmoothl committed 2026-07-03 17:37:55 +08:00
1 parent 884db940df
commit 7744e24af2
7 files changed
+152 -16

No files matched your search

@@ -1,24 +1,36 @@
// 0x89A_0 — toggle group "searchable" flag. Same cmd+subcmd shape as
// MuteAll / SetAddOption / SetName.
// 0x89A_0 — set a group's "被搜索方式" (searchability). Same cmd+subcmd shape as
// MuteAll / SetAddOption / SetName; the `settings` submessage carries the two
// search flags. Empty settings is a no-op (why the earlier version silently
// did nothing) — a real change must emit at least one flag. Command + tags
// (noFingerOpen=35, noCodeFingerOpen=36) RE'd empirically on a live group by
// sweeping the modify sub-message and reading the effect back through the
// 0x88D_0 GET (see Oidb0x89a_0SearchSettings for the full derivation).
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 type { Oidb0x89a_0Search, Oidb0x89a_0SearchSettings } 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 interface Params {
groupId: number;
/** 群指纹(关键词)搜索开关。undefined → 不改(不下发该字段)。 */
noFingerOpen?: number;
/** 群号搜索开关。undefined → 不改(不下发该字段)。 */
noCodeFingerOpen?: 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 serialize = (_ctx: Deps, p: Params): Oidb0x89a_0Search => {
const settings: Oidb0x89a_0SearchSettings = {};
if (p.noFingerOpen !== undefined) settings.noFingerOpen = p.noFingerOpen;
if (p.noCodeFingerOpen !== undefined) settings.noCodeFingerOpen = p.noCodeFingerOpen;
return { groupUin: BigInt(p.groupId), settings, field12: 0 };
};
export const deserialize = (_ctx: Deps, _: OidbEmpty): void => {};
@@ -0,0 +1,48 @@
import { describe, expect, it, vi } from 'vitest';
import type { SendPacketResult } from '@snowluma/common/packet-sender';
import { SetSearch } from '../../src/oidb-services/group-admin/set-search';
// Capture the exact OIDB request bytes SetSearch sends, via a fake sender.
async function sentHex(params: SetSearch.Params): Promise<string> {
let body: Uint8Array | undefined;
const deps = {
sendRawPacket: vi.fn(async (_cmd: string, b: Uint8Array): Promise<SendPacketResult> => {
body = b;
return { success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData: Buffer.alloc(0) };
}),
};
await SetSearch.invoke(deps as never, params);
return Buffer.from(body!).toString('hex');
}
// settings (field2) sub-message: noFingerOpen = tag 35 (35<<3 = 280 → varint
// "98 02"), noCodeFingerOpen = tag 36 (36<<3 = 288 → "a0 02"). Tags RE'd
// empirically on a live group (#191, see Oidb0x89a_0SearchSettings).
describe('SetSearch (0x89a_0) settings encoding (#191)', () => {
it('emits BOTH flags even at value 0 — toggle-off must not be dropped', async () => {
const h = await sentHex({ groupId: 941657197, noFingerOpen: 0, noCodeFingerOpen: 0 });
// field2 = { 35: 0, 36: 0 } → 12 06 980200 a00200
expect(h).toContain('1206980200a00200');
});
it('emits value 1 correctly', async () => {
const h = await sentHex({ groupId: 941657197, noFingerOpen: 1, noCodeFingerOpen: 1 });
expect(h).toContain('1206980201a00201');
});
it('elides an unprovided flag (undefined → not sent)', async () => {
const h = await sentHex({ groupId: 941657197, noCodeFingerOpen: 0 });
expect(h).toContain('a00200'); // tag 36 (noCodeFingerOpen) present, value 0
expect(h).not.toContain('980200'); // tag 35 (noFingerOpen) absent
});
it('carries the group uin + command 0x89a_0', async () => {
const deps = {
sendRawPacket: vi.fn(async (): Promise<SendPacketResult> => ({
success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData: Buffer.alloc(0),
})),
};
await SetSearch.invoke(deps as never, { groupId: 941657197, noFingerOpen: 1 });
expect(deps.sendRawPacket).toHaveBeenCalledWith('OidbSvcTrpcTcp.0x89a_0', expect.anything(), undefined);
});
});