feat(onebot): configure group invite policy

Add validated group member invite policy updates with post-write verification.

Fixes #334
This commit is contained in:
DrSmoothl committed 2026-08-09 11:46:04 +08:00
1 parent 597a4c05f3
commit cd6fcadea4
11 files changed
+343 -6

No files matched your search

+17 -1
View File
@@ -65,6 +65,23 @@ export const actions = [
},
}),
groupAction({
name: 'set_group_member_invite_policy',
summary: '设置群成员邀请策略',
params: {
policy: f.enum(
'disabled',
'require_approval',
'no_approval',
'no_approval_under_100',
),
},
run: async (p, ctx) => {
await ctx.bridge.apis.groupAdmin.setMemberInvitePolicy(p.group_id, p.policy);
return okResponse();
},
}),
groupUserAction({
name: 'set_group_admin',
summary: '设置/取消管理员',
@@ -128,4 +145,3 @@ export const actions = [
},
}),
];
@@ -90,9 +90,9 @@ describe('compileActionRegistry namespace conflicts', () => {
});
describe('compiled production Action registry', () => {
it('preserves all 186 canonical Action docs', () => {
expect(ACTION_REGISTRY.actions).toHaveLength(186);
expect(collectActionDocs()).toHaveLength(186);
it('preserves all 187 canonical Action docs', () => {
expect(ACTION_REGISTRY.actions).toHaveLength(187);
expect(collectActionDocs()).toHaveLength(187);
});
it('resolves every executable name to exactly one canonical doc', () => {
@@ -1453,6 +1453,34 @@ describe('extended-actions / fetch_custom_face_detail', () => {
});
});
describe('extended-actions / set_group_member_invite_policy', () => {
it('forwards the validated policy to the group-admin API', async () => {
const setMemberInvitePolicy = vi.fn(async () => undefined);
const bridge = fakeBridge({ apis: { groupAdmin: { setMemberInvitePolicy } } });
const response = await makeHandler(fakeCtx(bridge)).handle(
'set_group_member_invite_policy',
{ group_id: '12345', policy: 'no_approval_under_100' },
);
expect(response).toMatchObject({ status: 'ok', retcode: 0 });
expect(setMemberInvitePolicy).toHaveBeenCalledWith(12345, 'no_approval_under_100');
});
it('rejects an unknown policy before calling the bridge', async () => {
const setMemberInvitePolicy = vi.fn();
const bridge = fakeBridge({ apis: { groupAdmin: { setMemberInvitePolicy } } });
const response = await makeHandler(fakeCtx(bridge)).handle(
'set_group_member_invite_policy',
{ group_id: 12345, policy: 'anything' },
);
expect(response).toMatchObject({ status: 'failed', retcode: 1400 });
expect(setMemberInvitePolicy).not.toHaveBeenCalled();
});
});
// ─── Wave 1: get_group_shut_list ───
describe('extended-actions / get_group_shut_list', () => {