From a3b790d47253b0150e37b70212fc31c0153728b6 Mon Sep 17 00:00:00 2001 From: DrSmoothl <1787882683@qq.com> Date: Thu, 30 Jul 2026 10:36:43 +0800 Subject: [PATCH] feat(onebot): expose group remarks in group queries Include each account's saved group remark in group list and detail responses. Keep joined-group, non-member, and fallback results shape-consistent when no remark is available. Document the field in the public response metadata and cover cached and refreshed query paths with regression tests. Closes #294 --- packages/onebot/src/actions/group-info.ts | 17 ++++++++++++++--- packages/onebot/src/modules/contact-actions.ts | 3 +++ packages/onebot/tests/contact-actions.test.ts | 17 +++++++++++++---- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/packages/onebot/src/actions/group-info.ts b/packages/onebot/src/actions/group-info.ts index 81f06a94..84de2d78 100644 --- a/packages/onebot/src/actions/group-info.ts +++ b/packages/onebot/src/actions/group-info.ts @@ -16,13 +16,14 @@ export const actions = [ properties: { group_id: { type: 'integer', description: '群号' }, group_name: { type: 'string', description: '群名' }, + group_remark: { type: 'string', description: '当前账号设置的群备注' }, member_count: { type: 'integer', description: '当前成员数' }, max_member_count: { type: 'integer', description: '成员上限' }, group_create_time: { type: 'integer', description: '建群时间戳(秒)' }, group_level: { type: 'integer', description: '群等级(列表批量场景恒 0,详见 get_group_info)' }, group_memo: { type: 'string', description: '群简介 / 公告预览' }, }, - required: ['group_id', 'group_name', 'member_count', 'max_member_count'], + required: ['group_id', 'group_name', 'group_remark', 'member_count', 'max_member_count'], }, }, params: { no_cache: f.bool().default(false) }, @@ -45,19 +46,29 @@ export const actions = [ properties: { group_id: { type: 'integer', description: '群号' }, group_name: { type: 'string', description: '群名' }, + group_remark: { type: 'string', description: '当前账号设置的群备注' }, member_count: { type: 'integer', description: '当前成员数' }, max_member_count: { type: 'integer', description: '成员上限' }, group_create_time: { type: 'integer', description: '建群时间戳(秒)' }, group_level: { type: 'integer', description: '群等级' }, group_memo: { type: 'string', description: '群简介 / 公告预览' }, }, - required: ['group_id', 'group_name', 'member_count', 'max_member_count'], + required: ['group_id', 'group_name', 'group_remark', 'member_count', 'max_member_count'], }, params: { no_cache: f.bool().default(false) }, run: async (p, ctx) => { const groupId = p.group_id; const noCache = p.no_cache; - const fallback = { group_id: groupId, group_name: '', member_count: 0, max_member_count: 0, group_create_time: 0, group_level: 0, group_memo: '' }; + const fallback = { + group_id: groupId, + group_name: '', + group_remark: '', + member_count: 0, + max_member_count: 0, + group_create_time: 0, + group_level: 0, + group_memo: '', + }; if (ctx.getGroupInfo) { const info = await ctx.getGroupInfo(groupId, noCache); return okResponse(info ?? fallback); diff --git a/packages/onebot/src/modules/contact-actions.ts b/packages/onebot/src/modules/contact-actions.ts index bc8734ee..4f5db86e 100644 --- a/packages/onebot/src/modules/contact-actions.ts +++ b/packages/onebot/src/modules/contact-actions.ts @@ -74,6 +74,7 @@ export async function getGroupList( return bridge.identity.groups.map(g => ({ group_id: g.groupId, group_name: g.groupName, + group_remark: g.remark, member_count: g.memberCount, max_member_count: g.memberMax, // #197: create_time + memo come free from the list; group_level is only in @@ -128,6 +129,7 @@ export async function getGroupInfo( return { group_id: g.groupId, group_name: g.groupName, + group_remark: g.remark, member_count: g.memberCount, max_member_count: g.memberMax, group_create_time: g.createTime ?? 0, @@ -148,6 +150,7 @@ export async function getGroupInfo( const info: JsonObject = { group_id: detail.groupId, group_name: detail.groupName, + group_remark: detail.remark, member_count: detail.memberCount, max_member_count: detail.memberMax, group_create_time: detail.createTime ?? 0, diff --git a/packages/onebot/tests/contact-actions.test.ts b/packages/onebot/tests/contact-actions.test.ts index d5259a82..e04ed3f0 100644 --- a/packages/onebot/tests/contact-actions.test.ts +++ b/packages/onebot/tests/contact-actions.test.ts @@ -202,7 +202,7 @@ describe('onebot/contact-actions / getGroupFiles', () => { describe('onebot/contact-actions / getGroupList', () => { it('triggers fetch when the in-memory roster is empty', async () => { - const fetched = [makeGroup(100, 'Group A')]; + const fetched = [{ ...makeGroup(100, 'Group A'), remark: '工作群' }]; // `groups` starts empty; the fetch callback flips it to mimic // bridge.apis.contacts.fetchGroupList writing back through identity.rememberGroups. let groups: QQGroupInfo[] = []; @@ -216,6 +216,7 @@ describe('onebot/contact-actions / getGroupList', () => { expect(bridge.apis.contacts.fetchGroupList).toHaveBeenCalledOnce(); expect(out).toEqual([{ group_id: 100, group_name: 'Group A', + group_remark: '工作群', member_count: 0, max_member_count: 500, group_create_time: 0, group_level: 0, group_memo: '', }]); @@ -254,14 +255,18 @@ describe('onebot/contact-actions / getGroupList', () => { describe('onebot/contact-actions / getGroupInfo', () => { it('returns the cached group without refreshing when group is known and noCache is false', async () => { - const cached = makeGroup(500, 'Group E'); + const cached = { ...makeGroup(500, 'Group E'), remark: '常用群' }; const findGroup = vi.fn((groupId: number) => groupId === 500 ? cached : null); const bridge = fakeBridge({ fetchGroupList: vi.fn(async () => []), identity: fakeIdentity({ findGroup }), }); const out = await getGroupInfo(bridge, 500); - expect(out).toMatchObject({ group_id: 500, group_name: 'Group E' }); + expect(out).toMatchObject({ + group_id: 500, + group_name: 'Group E', + group_remark: '常用群', + }); expect(bridge.apis.contacts.fetchGroupList).not.toHaveBeenCalled(); }); @@ -297,7 +302,11 @@ describe('onebot/contact-actions / getGroupInfo', () => { }); const out = await getGroupInfo(bridge, 7100); expect(fetchGroupDetail).toHaveBeenCalledWith(7100); - expect(out).toMatchObject({ group_id: 7100, group_name: '邀请来的群' }); + expect(out).toMatchObject({ + group_id: 7100, + group_name: '邀请来的群', + group_remark: '', + }); }); it('caches the non-member lookup — a second call within TTL does not re-fetch', async () => {