diff --git a/packages/core/src/bridge/apis/group-admin.ts b/packages/core/src/bridge/apis/group-admin.ts index a9bc16b9..e0a03609 100644 --- a/packages/core/src/bridge/apis/group-admin.ts +++ b/packages/core/src/bridge/apis/group-admin.ts @@ -35,8 +35,8 @@ export class GroupAdminApi { return SetAddOption.invoke(this.ctx, { groupId, addType }); } - setSearch(groupId: number): Promise { - return SetSearch.invoke(this.ctx, { groupId }); + setSearch(groupId: number, noFingerOpen?: number, noCodeFingerOpen?: number): Promise { + return SetSearch.invoke(this.ctx, { groupId, noFingerOpen, noCodeFingerOpen }); } setAddRequest( diff --git a/packages/mcp/src/generated/catalog.json b/packages/mcp/src/generated/catalog.json index 683ddff0..42c78ebd 100644 --- a/packages/mcp/src/generated/catalog.json +++ b/packages/mcp/src/generated/catalog.json @@ -8410,7 +8410,7 @@ { "name": "set_group_search", "aliases": [], - "summary": "允许群被搜索", + "summary": "设置群被搜索方式(群指纹 / 群号搜索开关)", "readOnly": false, "params": [ { @@ -8423,6 +8423,24 @@ "minimum": 1 }, "desc": "群号" + }, + { + "name": "no_finger_open", + "type": "int", + "required": false, + "schema": { + "type": "integer", + "minimum": 0 + } + }, + { + "name": "no_code_finger_open", + "type": "int", + "required": false, + "schema": { + "type": "integer", + "minimum": 0 + } } ], "invariants": [], @@ -8434,6 +8452,14 @@ "minimum": 1, "description": "群号", "x-role": "group_id" + }, + "no_finger_open": { + "type": "integer", + "minimum": 0 + }, + "no_code_finger_open": { + "type": "integer", + "minimum": 0 } }, "required": [ diff --git a/packages/mcp/src/generated/catalog.ts b/packages/mcp/src/generated/catalog.ts index 42422e11..d4b69f64 100644 --- a/packages/mcp/src/generated/catalog.ts +++ b/packages/mcp/src/generated/catalog.ts @@ -8413,7 +8413,7 @@ export const ACTIONS: CatalogAction[] = [ { "name": "set_group_search", "aliases": [], - "summary": "允许群被搜索", + "summary": "设置群被搜索方式(群指纹 / 群号搜索开关)", "readOnly": false, "params": [ { @@ -8426,6 +8426,24 @@ export const ACTIONS: CatalogAction[] = [ "minimum": 1 }, "desc": "群号" + }, + { + "name": "no_finger_open", + "type": "int", + "required": false, + "schema": { + "type": "integer", + "minimum": 0 + } + }, + { + "name": "no_code_finger_open", + "type": "int", + "required": false, + "schema": { + "type": "integer", + "minimum": 0 + } } ], "invariants": [], @@ -8437,6 +8455,14 @@ export const ACTIONS: CatalogAction[] = [ "minimum": 1, "description": "群号", "x-role": "group_id" + }, + "no_finger_open": { + "type": "integer", + "minimum": 0 + }, + "no_code_finger_open": { + "type": "integer", + "minimum": 0 } }, "required": [ diff --git a/packages/onebot/src/actions/group-admin.ts b/packages/onebot/src/actions/group-admin.ts index 383d6163..c2f5fb6b 100644 --- a/packages/onebot/src/actions/group-admin.ts +++ b/packages/onebot/src/actions/group-admin.ts @@ -54,9 +54,13 @@ export const actions = [ groupAction({ name: 'set_group_search', - summary: '允许群被搜索', + summary: '设置群被搜索方式(群指纹 / 群号搜索开关)', + params: { + no_finger_open: f.int({ min: 0 }).optional(), + no_code_finger_open: f.int({ min: 0 }).optional(), + }, run: async (p, ctx) => { - await ctx.bridge.apis.groupAdmin.setSearch(p.group_id); + await ctx.bridge.apis.groupAdmin.setSearch(p.group_id, p.no_finger_open, p.no_code_finger_open); return okResponse(); }, }), diff --git a/packages/proto-defs/src/oidb-actions/base.ts b/packages/proto-defs/src/oidb-actions/base.ts index d5a27a32..5df7e4ea 100644 --- a/packages/proto-defs/src/oidb-actions/base.ts +++ b/packages/proto-defs/src/oidb-actions/base.ts @@ -31,9 +31,29 @@ export interface Oidb0x89a_0AddOption { settings?: pb<2, Oidb0x89a_0AddOptionSettings>; field12?: pb<12, uint_32>; } +// The `settings` payload is the GroupDetailInfo "modify" sub-message carrying +// only the fields being changed (the NT GroupDetailFilter is client-side — it +// just gates which fields the encoder emits, like modify-group-ext-info). This +// is a DIFFERENT message domain from the 0x88D_0 group-detail GET: mute/ +// shutUpTime is tag 17 here (Lagrange/MuteAll) but a string in the GET, so the +// tags do NOT match the GET's groupInfo. Tags RE'd empirically on a live group +// (bot as admin) by sweeping this sub-message tag-by-tag and reading the effect +// back through the 0x88D_0 GET (82/83), then confirming against the client's +// 3-state "被搜索方式" dropdown (私密 / 群号 / 群号+关键词): +// noFingerOpen (关键词/群指纹搜索) = tag 35 → GET 82 +// noCodeFingerOpen (群号搜索 / 总开关) = tag 36 → GET 83 +// Value 0 = that mode open/enabled, 1 = disabled ("no…Open"); keyword search +// additionally requires code search on. Matches NapCat modifyGroupDetailInfoV2. +export interface Oidb0x89a_0SearchSettings { + // pb_optional (explicit presence): a value of 0 (mode enabled) MUST be sent, + // so these can't use plain pb<> — proto3 would drop the zero and the request + // would silently no-op. undefined is still elided (field left unchanged). + noFingerOpen?: pb_optional<35, uint_32>; + noCodeFingerOpen?: pb_optional<36, uint_32>; +} export interface Oidb0x89a_0Search { groupUin?: pb<1, uint_64>; - settings?: pb<2, bytes>; + settings?: pb<2, Oidb0x89a_0SearchSettings>; field12?: pb<12, uint_32>; } export interface OidbKickMember { diff --git a/packages/protocol/src/oidb-services/group-admin/set-search.ts b/packages/protocol/src/oidb-services/group-admin/set-search.ts index 36352467..0d3f18bc 100644 --- a/packages/protocol/src/oidb-services/group-admin/set-search.ts +++ b/packages/protocol/src/oidb-services/group-admin/set-search.ts @@ -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 => {}; diff --git a/packages/protocol/tests/oidb-services/set-search.test.ts b/packages/protocol/tests/oidb-services/set-search.test.ts new file mode 100644 index 00000000..ae4f4815 --- /dev/null +++ b/packages/protocol/tests/oidb-services/set-search.test.ts @@ -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 { + let body: Uint8Array | undefined; + const deps = { + sendRawPacket: vi.fn(async (_cmd: string, b: Uint8Array): Promise => { + 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 => ({ + 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); + }); +});