fix(onebot): 恢复 set_group_leave 的 is_dismiss 解散群聊支持 (#2094)
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、描述与示例字段。
This commit is contained in:
1 parent
ec6aadaeea
commit
f750d95545
3 files changed
+77
-1
No files matched your search
@@ -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);
|
||||
}
|
||||
|
||||
@@ -26,7 +26,13 @@ export default class SetGroupLeave extends OneBotAction<PayloadType, ReturnType>
|
||||
override returnExample = GroupActionsExamples.SetGroupLeave.response;
|
||||
|
||||
async _handle (payload: PayloadType): Promise<null> {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user