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:
7 files changed
+183
-2
No files matched your search
@@ -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,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user