fix(onebot): restore doubt-request account ids from the native list

get_doubt_friends_add_request was rereading the uid as a number, so
uid came back empty and user_id was wrong. Keep the uid string and
the account number as separate fields.

Fixes #410
This commit is contained in:
DrSmoothl
2026-08-21 18:26:02 +08:00
parent 3045525e37
commit 6ec368f4b5
2 changed files with 27 additions and 27 deletions
@@ -1,27 +1,17 @@
// 0xd69_0 — getDoubtBuddyReq: list the "doubtful" friend-add requests
// (可能认识的人 / 被过滤的好友申请). RE'd from QQNT doubt_codec.cc.
// Request {1:1, 2:{1:num, 2:uk}} (reqId is NOT on the wire). Response body
// holds a repeated item list; we surface the fields NapCat exposes.
// READ-only: the string field names (nick/source/msg) are MEDIUM confidence
// (generic serializer), so a mislabel is cosmetic, never a wire/ban risk.
// uid (tag1) and reqTime (tag9) are HIGH confidence.
// holds a repeated item list. DecodePullDoubtReq maps uid as a string and
// the account number as a separate integer field; do not reread the uid
// field as a number. String names (nick/source/msg) are MEDIUM confidence.
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { pb, pb_repeated, uint_32, uint_64 } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type {
OidbDoubtGetReq, OidbDoubtGetResp,
} from '@snowluma/proto-defs/oidb-actions/doubt-buddy';
import { invokeOidb, type OidbSender } from '../../oidb-service';
interface OidbDoubtItemAccountOnTag1 {
uin?: pb<1, uint_64>;
}
interface OidbDoubtGetRespAccountOnTag1 {
status?: pb<1, uint_32>;
body?: pb<2, { list?: pb_repeated<1, OidbDoubtItemAccountOnTag1> }>;
}
export interface DoubtBuddyRequest {
[key: string]: import('@snowluma/common/json').JsonValue;
/** Opaque uid — pass back as `flag` to set_doubt_friends_add_request. */
@@ -63,20 +53,8 @@ export namespace GetDoubtBuddyReq {
export const encode = (env: OidbBase<OidbDoubtGetReq>): Uint8Array =>
protobuf_encode<OidbBase<OidbDoubtGetReq>>(env);
export const decode = (bytes: Uint8Array): OidbBase<OidbDoubtGetResp> => {
const decoded = protobuf_decode<OidbBase<OidbDoubtGetResp>>(bytes);
const numeric = protobuf_decode<OidbBase<OidbDoubtGetRespAccountOnTag1>>(bytes);
const items = decoded.body?.body?.list ?? [];
const numericItems = numeric.body?.body?.list ?? [];
for (let i = 0; i < items.length; i++) {
const item = items[i];
if (!item) continue;
if ((item.uin ?? 0n) === 0n && numericItems[i]?.uin) {
item.uin = numericItems[i]!.uin;
}
}
return decoded;
};
export const decode = (bytes: Uint8Array): OidbBase<OidbDoubtGetResp> =>
protobuf_decode<OidbBase<OidbDoubtGetResp>>(bytes);
export const invoke = (deps: Deps, params: Params): Promise<DoubtBuddyRequest[]> =>
invokeOidb(deps, GetDoubtBuddyReq, params);
@@ -59,4 +59,26 @@ describe('GetDoubtBuddyReq namespace', () => {
it('deserialize returns [] when the body has no list', () => {
expect(GetDoubtBuddyReq.deserialize({} as any, { status: 1 })).toEqual([]);
});
it('keeps the uid string and does not reread it as the account number', async () => {
const respEnv: OidbBase<OidbDoubtGetResp> = {
command: 0xD69, subCommand: 0,
body: { status: 1, body: { list: [
{ uid: 'u_alice', nick: 'Alice', msg: 'hi', source: 'QQ号查找', reason: 'caution' },
] } },
};
const sender = {
sendRawPacket: vi.fn(async () => ({
success: true, gotResponse: true, errorCode: 0, errorMessage: '',
responseData: Buffer.from(protobuf_encode<OidbBase<OidbDoubtGetResp>>(respEnv)),
})),
};
const list = await GetDoubtBuddyReq.invoke(sender, { count: 10 });
expect(list).toEqual([
{
uid: 'u_alice', user_id: 0, nick: 'Alice', source: 'QQ号查找',
reason: 'caution', msg: 'hi', group_code: '', reqTime: 0,
},
]);
});
});