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
@@ -139,6 +139,10 @@
|
||||
"types": "./src/oidb-services/contacts/fetch-friend-list-page.ts",
|
||||
"default": "./src/oidb-services/contacts/fetch-friend-list-page.ts"
|
||||
},
|
||||
"./oidb-services/contacts/fetch-group-detail": {
|
||||
"types": "./src/oidb-services/contacts/fetch-group-detail.ts",
|
||||
"default": "./src/oidb-services/contacts/fetch-group-detail.ts"
|
||||
},
|
||||
"./oidb-services/contacts/fetch-group-list": {
|
||||
"types": "./src/oidb-services/contacts/fetch-group-list.ts",
|
||||
"default": "./src/oidb-services/contacts/fetch-group-list.ts"
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
// 0x88D_0 — fetch a single group's detail by group uin.
|
||||
//
|
||||
// Unlike 0xFE5_2 (the bot's joined-groups list), this resolves ANY group by id,
|
||||
// including ones the bot hasn't joined — used to put a name on a group invite
|
||||
// (where the invite push itself carries no group name). The `flags` block is a
|
||||
// request mask: a present bool(true)/string("") asks the server to include that
|
||||
// field in the response. Cross-checked against
|
||||
// dev/Lagrange.Core/.../GetGroupInfoService.cs — note it builds the envelope
|
||||
// with isUid=false, i.e. reserved=0 (NO uinForm), unlike the 0xFE5_2 list query.
|
||||
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase, OidbSvcTrpcTcp0x88D_0Response } from '@snowluma/proto-defs/oidb';
|
||||
import type { OidbGroupDetailRequest } from '@snowluma/proto-defs/oidb-actions/base';
|
||||
import { invokeOidb, type OidbSender } from '../../oidb-service';
|
||||
|
||||
export namespace FetchGroupDetail {
|
||||
export const command = 0x88D;
|
||||
export const subCommand = 0;
|
||||
// NOTE: deliberately no `uinForm` — Lagrange sends this with reserved=0.
|
||||
|
||||
export interface Params { groupUin: number; }
|
||||
|
||||
export type Deps = OidbSender;
|
||||
|
||||
const on = true;
|
||||
|
||||
export const serialize = (_ctx: Deps, p: Params): OidbGroupDetailRequest => ({
|
||||
field1: 537099973,
|
||||
config: {
|
||||
uin: BigInt(p.groupUin),
|
||||
// Mirror Lagrange's flag set so the server returns the full detail block.
|
||||
flags: {
|
||||
ownerUid: on, createTime: on, maxMemberCount: on, memberCount: on,
|
||||
level: on, name: '', noticePreview: '', uin: on, lastSequence: on,
|
||||
lastMessageTime: on, question: on, answer: '', maxAdminCount: '',
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const deserialize = (_ctx: Deps, body: OidbSvcTrpcTcp0x88D_0Response): OidbSvcTrpcTcp0x88D_0Response => body;
|
||||
|
||||
export const encode = (env: OidbBase<OidbGroupDetailRequest>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<OidbGroupDetailRequest>>(env);
|
||||
|
||||
export const decode = (bytes: Uint8Array): OidbBase<OidbSvcTrpcTcp0x88D_0Response> =>
|
||||
protobuf_decode<OidbBase<OidbSvcTrpcTcp0x88D_0Response>>(bytes);
|
||||
|
||||
export const invoke = (deps: Deps, p: Params): Promise<OidbSvcTrpcTcp0x88D_0Response> =>
|
||||
invokeOidb(deps, FetchGroupDetail, p);
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
// 0x88D_0 — fetch a single group's detail by uin (resolves non-member groups,
|
||||
// e.g. to name a group invite). Verifies the request mask + envelope (reserved=0,
|
||||
// matching Lagrange's GetGroupInfoService) and the response decode.
|
||||
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase, OidbSvcTrpcTcp0x88D_0Response } from '@snowluma/proto-defs/oidb';
|
||||
import type { OidbGroupDetailRequest } from '@snowluma/proto-defs/oidb-actions/base';
|
||||
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
||||
|
||||
import { FetchGroupDetail } from '../../../src/oidb-services/contacts/fetch-group-detail';
|
||||
|
||||
function makeSender(body?: OidbSvcTrpcTcp0x88D_0Response) {
|
||||
const responseData = body !== undefined
|
||||
? Buffer.from(protobuf_encode<OidbBase<OidbSvcTrpcTcp0x88D_0Response>>({ body }))
|
||||
: Buffer.alloc(0);
|
||||
const r: SendPacketResult = { success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData };
|
||||
return { sendRawPacket: vi.fn(async () => r) };
|
||||
}
|
||||
|
||||
describe('FetchGroupDetail namespace', () => {
|
||||
it('declares 0x88D_0 with no uinForm (reserved stays 0, per Lagrange)', () => {
|
||||
expect(FetchGroupDetail.command).toBe(0x88D);
|
||||
expect(FetchGroupDetail.subCommand).toBe(0);
|
||||
expect((FetchGroupDetail as { uinForm?: boolean }).uinForm).toBeUndefined();
|
||||
});
|
||||
|
||||
describe('serialize', () => {
|
||||
it('builds the field1 + uin + request-mask flags', () => {
|
||||
const out = FetchGroupDetail.serialize({} as any, { groupUin: 601692726 });
|
||||
expect(out.field1).toBe(537099973);
|
||||
expect(out.config?.uin).toBe(BigInt(601692726));
|
||||
expect(out.config?.flags?.name).toBe(''); // string mask → request the name
|
||||
expect(out.config?.flags?.memberCount).toBe(true);
|
||||
expect(out.config?.flags?.maxMemberCount).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('deserialize', () => {
|
||||
it('passes the response body through', () => {
|
||||
const body = { groupInfo: { uin: 1n, results: { name: 'X' } } } as any;
|
||||
expect(FetchGroupDetail.deserialize({} as any, body)).toBe(body);
|
||||
});
|
||||
});
|
||||
|
||||
describe('invoke (e2e)', () => {
|
||||
it('routes to OidbSvcTrpcTcp.0x88d_0 and round-trips the uin in the request', async () => {
|
||||
const sender = makeSender({ groupInfo: { uin: 601692726n, results: { name: 'g' } } });
|
||||
await FetchGroupDetail.invoke(sender, { groupUin: 601692726 });
|
||||
|
||||
const [cmd, bytes] = sender.sendRawPacket.mock.calls[0]!;
|
||||
expect(cmd).toBe('OidbSvcTrpcTcp.0x88d_0');
|
||||
const env = protobuf_decode<OidbBase<OidbGroupDetailRequest>>(bytes);
|
||||
expect(env.command).toBe(0x88D);
|
||||
expect(env.subCommand ?? 0).toBe(0); // proto3 omits the 0 default on the wire
|
||||
expect(env.reserved ?? 0).toBe(0); // NOT uin-form
|
||||
expect(env.body?.config?.uin).toBe(BigInt(601692726));
|
||||
});
|
||||
|
||||
it('returns the decoded group detail (name + counts)', async () => {
|
||||
const sender = makeSender({
|
||||
groupInfo: { uin: 601692726n, results: { name: '测试群', memberCount: 42n, maxMemberCount: 500n } },
|
||||
});
|
||||
const out = await FetchGroupDetail.invoke(sender, { groupUin: 601692726 });
|
||||
expect(out.groupInfo?.results?.name).toBe('测试群');
|
||||
expect(out.groupInfo?.results?.memberCount).toBe(42n);
|
||||
expect(out.groupInfo?.results?.maxMemberCount).toBe(500n);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user