From f750d955455736126483e403a48e6d5a14dacae5 Mon Sep 17 00:00:00 2001 From: Shxiao Date: Wed, 7 Oct 2026 23:05:16 +0900 Subject: [PATCH] =?UTF-8?q?fix(onebot):=20=E6=81=A2=E5=A4=8D=20set=5Fgroup?= =?UTF-8?q?=5Fleave=20=E7=9A=84=20is=5Fdismiss=20=E8=A7=A3=E6=95=A3?= =?UTF-8?q?=E7=BE=A4=E8=81=8A=E6=94=AF=E6=8C=81=20(#2094)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit payloadSchema 声明了 is_dismiss(是否解散),该字段也会出现在 build:openapi 生成的接口文档中,但 _handle 始终只调用 quitGroup:群主传 is_dismiss=true 期望解散群聊时,实际只把账号退出群聊——群没解散,账号却已经不在群里。 同一问题曾在 #1694(deae7fd4)修复过。该 PR 随后被 #1701(e6f646837, 2026-03-13)整包回滚,54 个文件全部撤销;触发原因记录在 #1700(v4.17.48 无法正常发送 JSON 卡片消息),回滚后 v4.17.49 确认修复。回滚一并删掉了 destroyGroup 与 is_dismiss 分支,本次只恢复这一条分支。 本补丁不触碰任何 schema、描述与示例字段。 --- packages/napcat-core/apis/group.ts | 4 ++ .../action/group/SetGroupLeave.ts | 8 ++- .../napcat-test/setGroupLeaveDismiss.test.ts | 66 +++++++++++++++++++ 3 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 packages/napcat-test/setGroupLeaveDismiss.test.ts diff --git a/packages/napcat-core/apis/group.ts b/packages/napcat-core/apis/group.ts index 51d0733a5..8ec8fa9d5 100644 --- a/packages/napcat-core/apis/group.ts +++ b/packages/napcat-core/apis/group.ts @@ -562,6 +562,10 @@ export class NTQQGroupApi { return this.context.session.getGroupService().quitGroup(groupCode); } + async destroyGroup (groupCode: string) { + return this.context.session.getGroupService().destroyGroup(groupCode); + } + async kickMember (groupCode: string, kickUids: string[], refuseForever: boolean = false, kickReason: string = '') { return this.context.session.getGroupService().kickMember(groupCode, kickUids, refuseForever, kickReason); } diff --git a/packages/napcat-onebot/action/group/SetGroupLeave.ts b/packages/napcat-onebot/action/group/SetGroupLeave.ts index b7f0dc010..d9187657e 100644 --- a/packages/napcat-onebot/action/group/SetGroupLeave.ts +++ b/packages/napcat-onebot/action/group/SetGroupLeave.ts @@ -26,7 +26,13 @@ export default class SetGroupLeave extends OneBotAction override returnExample = GroupActionsExamples.SetGroupLeave.response; async _handle (payload: PayloadType): Promise { - await this.core.apis.GroupApi.quitGroup(payload.group_id.toString()); + const groupCode = payload.group_id.toString(); + // is_dismiss 既可能是布尔值,也可能是字符串 'true'(与 approve 等字段保持一致) + if (payload.is_dismiss === true || payload.is_dismiss === 'true') { + await this.core.apis.GroupApi.destroyGroup(groupCode); + } else { + await this.core.apis.GroupApi.quitGroup(groupCode); + } return null; } } diff --git a/packages/napcat-test/setGroupLeaveDismiss.test.ts b/packages/napcat-test/setGroupLeaveDismiss.test.ts new file mode 100644 index 000000000..eb64fa82a --- /dev/null +++ b/packages/napcat-test/setGroupLeaveDismiss.test.ts @@ -0,0 +1,66 @@ +// StreamBasic must be evaluated before OneBotAction: the two modules import each other, +// and loading OneBotAction first leaves BasicStream extending an uninitialized binding. +import '../napcat-onebot/action/stream/StreamBasic'; +import { describe, expect, test, vi } from 'vitest'; +import SetGroupLeave from '../napcat-onebot/action/group/SetGroupLeave'; + +function createAction () { + const quitGroup = vi.fn().mockResolvedValue(undefined); + const destroyGroup = vi.fn().mockResolvedValue(undefined); + const action = new SetGroupLeave( + undefined as never, + { + apis: { + GroupApi: { quitGroup, destroyGroup }, + }, + } as never + ); + return { action, quitGroup, destroyGroup }; +} + +describe('set_group_leave is_dismiss', () => { + test('leaves the group when is_dismiss is absent', async () => { + const { action, quitGroup, destroyGroup } = createAction(); + + await action._handle({ group_id: '123' }); + + expect(quitGroup).toHaveBeenCalledWith('123'); + expect(destroyGroup).not.toHaveBeenCalled(); + }); + + test('leaves the group when is_dismiss is false', async () => { + const { action, quitGroup, destroyGroup } = createAction(); + + await action._handle({ group_id: '123', is_dismiss: false }); + + expect(quitGroup).toHaveBeenCalledWith('123'); + expect(destroyGroup).not.toHaveBeenCalled(); + }); + + test("leaves the group when is_dismiss is the string 'false'", async () => { + const { action, quitGroup, destroyGroup } = createAction(); + + await action._handle({ group_id: '123', is_dismiss: 'false' }); + + expect(quitGroup).toHaveBeenCalledWith('123'); + expect(destroyGroup).not.toHaveBeenCalled(); + }); + + test('destroys the group when is_dismiss is true', async () => { + const { action, quitGroup, destroyGroup } = createAction(); + + await action._handle({ group_id: '123', is_dismiss: true }); + + expect(destroyGroup).toHaveBeenCalledWith('123'); + expect(quitGroup).not.toHaveBeenCalled(); + }); + + test("destroys the group when is_dismiss is the string 'true'", async () => { + const { action, quitGroup, destroyGroup } = createAction(); + + await action._handle({ group_id: '123', is_dismiss: 'true' }); + + expect(destroyGroup).toHaveBeenCalledWith('123'); + expect(quitGroup).not.toHaveBeenCalled(); + }); +});