feat(onebot): enrich group/member info fields (#197)

Round out the OneBot v11 group-profile fields the issue asked for.

Group (get_group_info / get_group_list, inherited by get_group_info_ex /
get_group_detail_info):
- group_create_time + group_memo come free from the 0xFE5_2 list
  (createdTime / announcement), verified live (createdTime=1729505343,
  announcement populated).
- group_level lives only in the 0x88D_0 detail; get_group_info fetches it
  (memoized 5min) so a joined group doesn't hit the detail every call.
  get_group_list leaves it 0 — a per-group detail fetch across the whole
  list would be far too costly.

Member (get_group_member_info / get_group_member_list):
- Add area / unfriendly / title_expire_time / card_changeable. QQ NT does
  not expose these, so they're fixed placeholders ('' / false / 0 / true),
  matching go-cqhttp / NapCat. sex/age stay unknown/0 (real values need a
  per-member profile fetch — out of scope here).

typecheck 12 packages; onebot 523 / core 472 green.
This commit is contained in:
DrSmoothl committed 2026-07-04 13:04:32 +08:00
1 parent b20ed12761
commit 07c08ed74d
7 files changed
+183 -2

No files matched your search

+17 -2
View File
@@ -18,6 +18,9 @@ export const actions = [
group_name: { 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'],
},
@@ -44,6 +47,9 @@ export const actions = [
group_name: { 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'],
},
@@ -51,11 +57,12 @@ export const actions = [
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: '' };
if (ctx.getGroupInfo) {
const info = await ctx.getGroupInfo(groupId, noCache);
return okResponse(info ?? { group_id: groupId, group_name: '', member_count: 0, max_member_count: 0 });
return okResponse(info ?? fallback);
}
return okResponse({ group_id: groupId, group_name: '', member_count: 0, max_member_count: 0 });
return okResponse(fallback);
},
}),
@@ -80,6 +87,10 @@ export const actions = [
level: { type: 'string', description: '群等级' },
role: { type: 'string', enum: ['owner', 'admin', 'member'], description: '角色' },
title: { type: 'string', description: '专属头衔' },
area: { type: 'string', description: '地区(QQ NT 不提供,恒空)' },
unfriendly: { type: 'boolean', description: '是否不良记录(QQ NT 不提供,恒 false)' },
title_expire_time: { type: 'integer', description: '头衔过期时间戳(QQ NT 不提供,恒 0)' },
card_changeable: { type: 'boolean', description: '是否可改名片(占位,恒 true)' },
},
required: ['group_id', 'user_id', 'nickname', 'role'],
},
@@ -114,6 +125,10 @@ export const actions = [
level: { type: 'string', description: '群等级' },
role: { type: 'string', enum: ['owner', 'admin', 'member'], description: '角色' },
title: { type: 'string', description: '专属头衔' },
area: { type: 'string', description: '地区(QQ NT 不提供,恒空)' },
unfriendly: { type: 'boolean', description: '是否不良记录(QQ NT 不提供,恒 false)' },
title_expire_time: { type: 'integer', description: '头衔过期时间戳(QQ NT 不提供,恒 0)' },
card_changeable: { type: 'boolean', description: '是否可改名片(占位,恒 true)' },
},
required: ['group_id', 'user_id', 'nickname', 'role'],
},
@@ -50,9 +50,34 @@ export async function getGroupList(
group_name: g.groupName,
member_count: g.memberCount,
max_member_count: g.memberMax,
// #197: create_time + memo come free from the list; group_level is only in
// the per-group 0x88D_0 detail, so it stays 0 here (a per-group fetch across
// the whole list would be far too expensive). get_group_info fills it in.
group_create_time: g.createTime ?? 0,
group_level: g.level ?? 0,
group_memo: g.memo ?? '',
}));
}
// group_level lives only in the 0x88D_0 detail. Memoize it (short TTL) so a
// joined-group get_group_info doesn't fetch the detail on every call (#197).
const GROUP_LEVEL_TTL_MS = 5 * 60 * 1000;
const groupLevelCache = new Map<number, { level: number; at: number }>();
async function getGroupLevel(bridge: BridgeInterface, groupId: number, noCache?: boolean): Promise<number> {
if (!noCache) {
const c = groupLevelCache.get(groupId);
if (c && Date.now() - c.at < GROUP_LEVEL_TTL_MS) return c.level;
}
try {
const detail = await bridge.apis.contacts.fetchGroupDetail(groupId);
const level = detail?.level ?? 0;
groupLevelCache.set(groupId, { level, at: Date.now() });
return level;
} catch {
return 0;
}
}
// Short-TTL cache for the non-member group lookup (0x88D_0). Joined groups come
// from the identity roster (kept fresh by fetchGroupList) and are NOT cached
// here; this only memoizes the per-id server query so a burst of invites for the
@@ -79,6 +104,9 @@ export async function getGroupInfo(
group_name: g.groupName,
member_count: g.memberCount,
max_member_count: g.memberMax,
group_create_time: g.createTime ?? 0,
group_level: await getGroupLevel(bridge, groupId, noCache),
group_memo: g.memo ?? '',
};
}
@@ -96,6 +124,9 @@ export async function getGroupInfo(
group_name: detail.groupName,
member_count: detail.memberCount,
max_member_count: detail.memberMax,
group_create_time: detail.createTime ?? 0,
group_level: detail.level ?? 0,
group_memo: detail.memo ?? '',
};
nonMemberGroupCache.set(groupId, { info, at: Date.now() });
return { ...info };
@@ -264,5 +295,12 @@ function formatGroupMember(
level: String(member.level),
role: member.role,
title: member.title,
// OneBot v11 completeness (#197). QQ NT doesn't expose these, so they're
// fixed placeholders — matching go-cqhttp / NapCat, which also hardcode
// them: area='', unfriendly=false, title_expire_time=0, card_changeable=true.
area: '',
unfriendly: false,
title_expire_time: 0,
card_changeable: true,
};
}
@@ -151,6 +151,7 @@ describe('onebot/contact-actions / getGroupList', () => {
expect(out).toEqual([{
group_id: 100, group_name: 'Group A',
member_count: 0, max_member_count: 500,
group_create_time: 0, group_level: 0, group_memo: '',
}]);
});