feat(contacts): resolve non-member group name via 0x88D_0 (group invites)

A group invite push carries no group name (confirmed across SnowLuma / Lagrange
/ NapCat — all three invite protos only have groupUin + invitorUid), and
get_group_info only resolved joined groups (fetchGroupList → roster), so an
invited group rendered "未知群名". Add a by-id server lookup so the name
resolves even when the bot isn't a member.

- proto-defs: 0x88D_0 request (field1 + config.uin + a request-mask `flags`
  block) + response (groupInfo.results: name / member counts / owner / …),
  field tags transcribed from
  dev/Lagrange.Core/.../OidbSvcTrpcTcp0x88D_0{,Response}.cs.
- protocol: FetchGroupDetail oidb-service. Envelope reserved=0 (NO uinForm) —
  Lagrange's GetGroupInfoService builds it with isUid=false.
- core: ContactsApi.fetchGroupDetail(gid) → QQGroupInfo | null; deliberately
  NOT remembered into the joined-groups roster (mustn't pollute get_group_list).
- onebot: get_group_info falls back to fetchGroupDetail for non-member groups,
  behind a 5-min per-id TTL cache so a burst of invites for one group can't
  hammer 0x88D_0 (rate-limit / kick risk). noCache bypasses it.
- tests: request/envelope round-trip (reserved=0, uin, command), response
  decode; + non-member resolve / cache-hit / noCache-bypass at the onebot layer.

Live note: byte-identical to Lagrange's 0x88D_0, but not verified against a real
account on this host.
This commit is contained in:
DrSmoothl committed 2026-06-15 14:33:06 +08:00
1 parent 7e59dbf79b
commit b0bfb9e6a7
8 files changed
+281 -8

No files matched your search

+38 -7
View File
@@ -53,6 +53,13 @@ export async function getGroupList(
}));
}
// 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
// same group doesn't hammer 0x88D_0 (which would risk a rate-limit / kick).
const NON_MEMBER_GROUP_TTL_MS = 5 * 60 * 1000;
const nonMemberGroupCache = new Map<number, { info: JsonObject; at: number }>();
export async function getGroupInfo(
bridge: BridgeInterface,
groupId: number,
@@ -66,13 +73,37 @@ export async function getGroupInfo(
}
}
const g = bridge.identity.findGroup(groupId);
if (!g) return null;
return {
group_id: g.groupId,
group_name: g.groupName,
member_count: g.memberCount,
max_member_count: g.memberMax,
};
if (g) {
return {
group_id: g.groupId,
group_name: g.groupName,
member_count: g.memberCount,
max_member_count: g.memberMax,
};
}
// Not a joined group — fall back to the by-id server lookup so a group invite
// can still resolve its name. Cached with a short TTL (skipped when noCache).
if (!noCache) {
const cached = nonMemberGroupCache.get(groupId);
if (cached && Date.now() - cached.at < NON_MEMBER_GROUP_TTL_MS) return { ...cached.info };
}
try {
const detail = await bridge.apis.contacts.fetchGroupDetail(groupId);
if (detail) {
const info: JsonObject = {
group_id: detail.groupId,
group_name: detail.groupName,
member_count: detail.memberCount,
max_member_count: detail.memberMax,
};
nonMemberGroupCache.set(groupId, { info, at: Date.now() });
return { ...info };
}
} catch {
// Server lookup failed (no such group / denied) — fall through to null.
}
return null;
}
export async function getGroupMemberList(