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
This commit is contained in:
3 files changed
+30
-7
No files matched your search
@@ -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);
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 () => {
|
||||
|
||||
Reference in new issue
Block a user