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:
8 files changed
+281
-8
No files matched your search
@@ -34,6 +34,7 @@ const APIS_ROUTING: Record<string, string> = {
|
||||
fetchFriendList: 'contacts', fetchGroupList: 'contacts',
|
||||
fetchGroupMemberList: 'contacts', fetchUserProfile: 'contacts',
|
||||
fetchGroupRequests: 'contacts', fetchDownloadRKeys: 'contacts',
|
||||
fetchGroupDetail: 'contacts',
|
||||
};
|
||||
|
||||
function fakeBridge(overrides: Record<string, any> = {}): BridgeInterface {
|
||||
@@ -211,13 +212,52 @@ describe('onebot/contact-actions / getGroupInfo', () => {
|
||||
expect(out).toMatchObject({ group_id: 600, group_name: 'Group F' });
|
||||
});
|
||||
|
||||
it('returns null when the group remains unknown after fetch', async () => {
|
||||
it('returns null when the group remains unknown after fetch and the server has no such group', async () => {
|
||||
const bridge = fakeBridge({
|
||||
fetchGroupList: vi.fn(async () => []),
|
||||
fetchGroupDetail: vi.fn(async () => null),
|
||||
identity: fakeIdentity({ findGroup: () => null }),
|
||||
});
|
||||
expect(await getGroupInfo(bridge, 700)).toBeNull();
|
||||
});
|
||||
|
||||
it('resolves a non-member group via the by-id server lookup (e.g. a group invite name)', async () => {
|
||||
const fetchGroupDetail = vi.fn(async () => makeGroup(7100, '邀请来的群'));
|
||||
const bridge = fakeBridge({
|
||||
fetchGroupList: vi.fn(async () => []),
|
||||
fetchGroupDetail,
|
||||
identity: fakeIdentity({ findGroup: () => null }),
|
||||
});
|
||||
const out = await getGroupInfo(bridge, 7100);
|
||||
expect(fetchGroupDetail).toHaveBeenCalledWith(7100);
|
||||
expect(out).toMatchObject({ group_id: 7100, group_name: '邀请来的群' });
|
||||
});
|
||||
|
||||
it('caches the non-member lookup — a second call within TTL does not re-fetch', async () => {
|
||||
const fetchGroupDetail = vi.fn(async () => makeGroup(7200, 'Cached Invite Group'));
|
||||
const bridge = fakeBridge({
|
||||
fetchGroupList: vi.fn(async () => []),
|
||||
fetchGroupDetail,
|
||||
identity: fakeIdentity({ findGroup: () => null }),
|
||||
});
|
||||
const a = await getGroupInfo(bridge, 7200);
|
||||
const b = await getGroupInfo(bridge, 7200);
|
||||
expect(a).toMatchObject({ group_name: 'Cached Invite Group' });
|
||||
expect(b).toMatchObject({ group_name: 'Cached Invite Group' });
|
||||
expect(fetchGroupDetail).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('noCache bypasses the non-member cache', async () => {
|
||||
const fetchGroupDetail = vi.fn(async () => makeGroup(7300, 'NoCache Group'));
|
||||
const bridge = fakeBridge({
|
||||
fetchGroupList: vi.fn(async () => []),
|
||||
fetchGroupDetail,
|
||||
identity: fakeIdentity({ findGroup: () => null }),
|
||||
});
|
||||
await getGroupInfo(bridge, 7300);
|
||||
await getGroupInfo(bridge, 7300, true);
|
||||
expect(fetchGroupDetail).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('onebot/contact-actions / getGroupMemberList', () => {
|
||||
|
||||
Reference in new issue
Block a user