fix(onebot): restore group and doubt request accounts

get_group_system_msg now keeps join and invite records, reports the
inviter, and fills a missing requester nick from the user profile.
get_doubt_friends_add_request returns the QQ number plus the request
message, source, and time that QQ actually sends.

Closes #400
Closes #401
Closes #402
Closes #403
This commit is contained in:
DrSmoothl committed 2026-08-19 21:45:15 +08:00
1 parent 5a10fc4c9c
commit 8fdd41ea22
13 files changed
+418 -79

No files matched your search

@@ -1,7 +1,7 @@
import { describe, expect, it, vi } from 'vitest';
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 { OidbBase, OidbSvcTrpcTcp0x10C0Response } from '@snowluma/proto-defs/oidb';
import type { OidbGroupRequestList } from '@snowluma/proto-defs/oidb-actions/base';
import type { SendPacketResult } from '@snowluma/common/packet-sender';
@@ -47,6 +47,8 @@ describe('FetchGroupRequests namespace', () => {
expect(groupRequestOperationType(1)).toBe(2);
expect(groupRequestOperationType(7)).toBe(1);
expect(groupRequestOperationType(17)).toBe(100);
expect(groupRequestOperationType(5)).toBe(22);
expect(groupRequestOperationType(22)).toBe(22);
expect(groupRequestOperationType(99)).toBeNull();
});
@@ -135,13 +137,43 @@ describe('FetchGroupRequests namespace', () => {
const response = await FetchGroupRequests.invoke(sender, { filtered: false });
expect(response.requests?.[0]).toMatchObject({
target: { uin: 1_234_567_890, name: 'requester' },
invitor: { uin: 2_345_678_901, name: 'inviter' },
operatorUser: { uin: 3_456_789_012, name: 'operator' },
target: { uin: 1_234_567_890, uid: '', name: 'requester' },
invitor: { uin: 2_345_678_901, uid: '', name: 'inviter' },
operatorUser: { uin: 3_456_789_012, uid: '', name: 'operator' },
});
expect(response.field2).toBe(1_785_406_628_779_279n);
});
it('keeps string account identifiers from the native reply', async () => {
const responseData = Buffer.from(protobuf_encode<OidbBase<OidbSvcTrpcTcp0x10C0Response>>({
body: {
requests: [{
sequence: 99n,
eventType: 5,
state: 1,
group: { groupUin: 1001, groupName: 'group' },
target: { uid: 'u_target', name: 'invitee' },
invitor: { uid: 'u_inviter', name: 'inviter' },
comment: 'join us',
}],
},
}));
const sender = {
sendRawPacket: vi.fn(async () => ({
success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData,
})),
};
const response = await FetchGroupRequests.invoke(sender, { filtered: false });
expect(response.requests?.[0]).toMatchObject({
eventType: 5,
target: { uid: 'u_target', uin: 0, name: 'invitee' },
invitor: { uid: 'u_inviter', uin: 0, name: 'inviter' },
comment: 'join us',
});
});
it('keeps the UID response path on the non-native envelope', async () => {
const sender = makeSender();
await FetchGroupRequestsByUid.invoke(sender, { filtered: false });
@@ -10,7 +10,10 @@ function makeSender(): { sendRawPacket: ReturnType<typeof vi.fn> } {
const respEnv: OidbBase<OidbDoubtGetResp> = {
command: 0xD69, subCommand: 0,
body: { status: 1, body: { list: [
{ uid: 'u_alice', nick: 'Alice', source: '可能认识', msg: 'hi', reqTime: 1700000000n },
{
uid: 'u_alice', nick: 'Alice', source: '可能认识', reason: '',
msg: 'hi', uin: 12345n, groupCode: '', reqTime: 1700000000n,
},
], reason: '' } },
};
const r: SendPacketResult = {
@@ -46,7 +49,10 @@ describe('GetDoubtBuddyReq namespace', () => {
it('deserializes the item list to the OneBot shape (uid + reqTime high-confidence)', async () => {
const list = await GetDoubtBuddyReq.invoke(makeSender(), { count: 10 });
expect(list).toEqual([
{ uid: 'u_alice', nick: 'Alice', source: '可能认识', msg: 'hi', reqTime: 1700000000 },
{
uid: 'u_alice', user_id: 12345, nick: 'Alice', source: '可能认识',
reason: '', msg: 'hi', group_code: '', reqTime: 1700000000,
},
]);
});