fix(events): surface verify-text on group_invite ("你们好" → comment)
User report:
SnowLuma's group_invite event renders to OneBot with empty
`comment`, so the bot's approval-prompt template shows nickname
+ uin + flag but loses the requester's verify message.
NapCat's same flow shows the verify text:
【进群申请】批准/驳回:
昵称:KitaIkuyo
QQ:1957003260
flag:1779543612823906
等级:7
你们好 ← only NapCat shows this line
Root cause:
The OIDB push (GroupRequestJoinNotice subType=84) only carries
`(groupUin, targetUid)` and a few opaque numeric fields — no
string for the verify text. NapCat doesn't use the push directly;
they poll `nodeIKernelGroupService.getGroupNotifies` (= our OIDB
0x10C0 pending-request queue at `FetchGroupRequests`) which
returns each pending row with `postscript` (the verify text) and
`seq` (server sequence id). Reference:
dev/NapCatQQ/packages/napcat-onebot/index.ts:483-498
(`flag = notify.seq`, `comment = notify.postscript`).
Our pipeline didn't enrich. The decoder set `message: ''` and
emitted, so OneBot's `comment` was empty.
Fix:
- Extend `PacketPipelineDeps` with a `resolveGroupJoinRequest(
groupId, uid, subType)` hook. Bridge.ts wires it to
`fetchGroupRequests` and matches on `(groupId, uid)` —
targetUid for `subType='add'`, invitorUid for
`subType='invite'`.
- `dispatchAfterStrangerResolve` now fires the profile + request
lookups in PARALLEL via `Promise.allSettled` so a flake on one
path doesn't kill the other. The request lookup's `comment`
lands on `event.message`; OneBot converts that to `comment`.
Decisions:
- Kept the existing `add:<groupId>:<uid>` flag format (consumer
bots already parse it). Switching to NapCat's sequence-form
flag would break callers and is a separate breaking change.
- Both lookups fail-open: if either rejects, the event still
emits with whatever info we did get, so the bot at least sees
the request and can render the bare nickname.
Regression tests:
- `populates event.message from the pending-request queue` — pins
the user-reported "你们好" case end-to-end through the pipeline.
- `runs lookups in parallel` — profile resolves, request fails;
event still ships with the resolved uin and an empty message.
- `invite subtype matches the request on invitorUid` — explicit
contract for the invite-forwarded-to-admin case where the
pending row's REQUESTER is `invitorUid`, not `targetUid`.
345 bridge tests pass (was 342 + 3 new); typecheck + lint clean.
This commit is contained in:
3 files changed
+154
-12
No files matched your search
@@ -43,6 +43,20 @@ export interface PacketPipelineDeps {
|
||||
* uid-only event.
|
||||
*/
|
||||
resolveStrangerProfile(uid: string): Promise<{ uin: number; nickname: string } | null>;
|
||||
/**
|
||||
* Resolve the verify message ("postscript") + server sequence number
|
||||
* for a pending group-join / group-invite. The OIDB push only
|
||||
* carries the requester's UID + group uin — the actual verify text
|
||||
* the user typed ("你们好" etc.) lives on the pending-request queue
|
||||
* fetched via OIDB 0x10C0. NapCat surfaces this as
|
||||
* `notify.postscript` from `nodeIKernelGroupService.getGroupNotifies`;
|
||||
* we mirror that with an `fetchGroupRequests` lookup matched on
|
||||
* `(groupId, uid, subType)`. Returns null when no matching pending
|
||||
* request exists (e.g. it was already handled by another client).
|
||||
*/
|
||||
resolveGroupJoinRequest(
|
||||
groupId: number, uid: string, subType: 'add' | 'invite',
|
||||
): Promise<{ comment: string; sequence: number } | null>;
|
||||
}
|
||||
|
||||
export class IncomingPacketPipeline {
|
||||
@@ -151,18 +165,35 @@ export class IncomingPacketPipeline {
|
||||
|
||||
private async dispatchAfterStrangerResolve(event: Extract<QQEventVariant, { kind: 'group_invite' }>): Promise<void> {
|
||||
const uid = event.fromUid;
|
||||
try {
|
||||
if (uid) {
|
||||
const profile = await this.deps.resolveStrangerProfile(uid);
|
||||
if (profile && profile.uin > 0) {
|
||||
event.fromUin = profile.uin;
|
||||
}
|
||||
if (uid) {
|
||||
// Fire profile + pending-request lookups in PARALLEL — they're
|
||||
// independent OIDB calls (0xFE1_2 stranger profile + 0x10C0
|
||||
// pending request queue). Both `Promise.allSettled` so a flake
|
||||
// on one path doesn't kill the other.
|
||||
const subType = event.subType === 'invite' ? 'invite' : 'add';
|
||||
const [profileR, requestR] = await Promise.allSettled([
|
||||
this.deps.resolveStrangerProfile(uid),
|
||||
this.deps.resolveGroupJoinRequest(event.groupId, uid, subType),
|
||||
]);
|
||||
|
||||
if (profileR.status === 'fulfilled' && profileR.value && profileR.value.uin > 0) {
|
||||
event.fromUin = profileR.value.uin;
|
||||
} else if (profileR.status === 'rejected') {
|
||||
this.log.warn('failed to resolve stranger profile: uid=%s err=%s',
|
||||
uid, profileR.reason instanceof Error ? profileR.reason.message : String(profileR.reason));
|
||||
}
|
||||
|
||||
if (requestR.status === 'fulfilled' && requestR.value) {
|
||||
// NapCat surfaces the verify text as `comment` on the OneBot
|
||||
// event (`postscript` server-side). Without this the bot's
|
||||
// approval-prompt template renders an empty body line — see
|
||||
// `dev/NapCatQQ/.../napcat-onebot/index.ts:496-498`.
|
||||
event.message = requestR.value.comment;
|
||||
} else if (requestR.status === 'rejected') {
|
||||
this.log.warn('failed to resolve group join request: groupId=%d uid=%s err=%s',
|
||||
event.groupId, uid,
|
||||
requestR.reason instanceof Error ? requestR.reason.message : String(requestR.reason));
|
||||
}
|
||||
} catch (e) {
|
||||
// Fail open — emit the event with the bare uid so bots can at
|
||||
// least see the join request, even if they can't render a name.
|
||||
this.log.warn('failed to resolve stranger profile: uid=%s err=%s',
|
||||
uid ?? '', e instanceof Error ? e.message : String(e));
|
||||
}
|
||||
|
||||
this.handleSideEffects(event);
|
||||
|
||||
Reference in new issue
Block a user