feat(onebot): expose birthdays in stranger profiles (#594)

Include available birthday information in stranger profiles and preserve hidden birth years.
This commit is contained in:
C₂₂H₂₅NO₆ authored and GitHub committed 2026-10-31 18:01:16 +08:00
1 parent 6b8362e049
commit 947af4b22c
10 files changed
+192 -6

No files matched your search

@@ -22,7 +22,7 @@ import type {
OidbUserInfoResponse,
} from '@snowluma/proto-defs/oidb-actions/base';
import type { UserProfileInfo } from '../../qq-info';
import { applyOnlineStatus, applyProfileDetails } from './fetch-user-profile';
import { applyBirthday, applyOnlineStatus, applyProfileDetails } from './fetch-user-profile';
import { invokeOidb, type OidbSender } from '../../oidb-service';
const REQUESTED_KEYS = [
@@ -109,6 +109,7 @@ export namespace FetchUserProfileByUid {
info.level = numMap.get(105) ?? 0;
applyOnlineStatus(info, bytesMap, numMap);
applyProfileDetails(info, numMap);
applyBirthday(info, bytesMap);
// 企点标志:40410 / 42031,服务器仅在返回时才出现(普通账号缺省 → 0)
info.qidianMasterFlag = numMap.get(42031) ?? 0;
info.qidianCrewFlag = numMap.get(40410) ?? 0;
@@ -14,6 +14,7 @@
// 105 — QQ level (numeric)
// 20002 — nickname
// 20009 — gender (1 male / 2 female / 255 unknown)
// 20031 — birthday (4 bytes: uint16 BE year, month, day)
// 20037 — age
// 27394 — QID
@@ -85,6 +86,35 @@ export function applyProfileDetails(info: UserProfileInfo, numMap: Map<number, n
}
}
/**
* 生日(bytes-property 20031):年 uint16 大端 + 月 + 日,与 Lagrange.Core
* `FetchStrangerService.cs` 的解析一致。月或日为 0 表示未设置生日;
* 年份为 0 表示未公开出生年份,此时只省略年份。
*/
export function applyBirthday(info: UserProfileInfo, bytesMap: Map<number, Uint8Array>): void {
const raw = bytesMap.get(20031);
if (!raw || raw.length < 4) {
return;
}
const bytes = Buffer.from(raw);
const year = bytes.readUInt16BE(0);
const month = bytes.readUInt8(2);
const day = bytes.readUInt8(3);
if (month < 1 || month > 12 || day < 1 || day > 31) {
return;
}
if (year > 0) {
info.birthdayYear = year;
}
info.birthdayMonth = month;
info.birthdayDay = day;
}
const REQUESTED_KEYS = [
20002, 27394, 20009, 20031, 101, 103, 102, 20020, 20003, 20026, 105, 27372, 27406, 20037, 41756,
41757, 42241,
@@ -174,6 +204,7 @@ export namespace FetchUserProfile {
info.level = numMap.get(105) ?? 0;
applyOnlineStatus(info, bytesMap, numMap);
applyProfileDetails(info, numMap);
applyBirthday(info, bytesMap);
// 企点标志:40410 / 42031,服务器仅在返回时才出现(普通账号缺省 → 0)
info.qidianMasterFlag = numMap.get(42031) ?? 0;
info.qidianCrewFlag = numMap.get(40410) ?? 0;
+7
View File
@@ -13,6 +13,13 @@ export interface UserProfileInfo {
* `FetchStrangerService.cs` confirms `// Level`. */
level: number;
regTime?: number;
/**
* 生日 — OIDB 0xFE1_2 bytes-property key 20031。
* 月日未设置时三项均缺省;出生年份未公开(年份为 0)时仅缺省 birthdayYear。
*/
birthdayYear?: number;
birthdayMonth?: number;
birthdayDay?: number;
vipFlag?: boolean;
yearVipFlag?: boolean;
svipFlag?: boolean;
@@ -108,7 +108,78 @@ describe('FetchUserProfile namespace', () => {
uin: 10001,
});
for (const name of ['regTime', 'vipFlag', 'yearVipFlag', 'svipFlag', 'vipLevel']) {
for (const name of [
'regTime',
'vipFlag',
'yearVipFlag',
'svipFlag',
'vipLevel',
'birthdayYear',
'birthdayMonth',
'birthdayDay',
]) {
expect(profile).not.toHaveProperty(name);
}
});
it.each(['uin', 'uid'])(
'decodes the birthday bytes-property through the %s request',
async (form) => {
const sender = makeSender({
body: {
uin: 10001,
uid: 'u_test',
properties: {
bytesProperties: [
{ code: 20031, value: new Uint8Array([0x07, 0xd0, 3, 15]) },
],
},
},
});
const profile =
form === 'uin'
? await FetchUserProfile.invoke(sender, { uin: 10001 })
: await FetchUserProfileByUid.invoke(sender, { uid: 'u_test' });
expect(profile).toMatchObject({
birthdayYear: 2000,
birthdayMonth: 3,
birthdayDay: 15,
});
},
);
it('omits only the birth year when the year is hidden', async () => {
const sender = makeSender({
body: {
uin: 10001,
properties: {
bytesProperties: [{ code: 20031, value: new Uint8Array([0, 0, 12, 31]) }],
},
},
});
const profile = await FetchUserProfile.invoke(sender, { uin: 10001 });
expect(profile).toMatchObject({ birthdayMonth: 12, birthdayDay: 31 });
expect(profile).not.toHaveProperty('birthdayYear');
});
it.each([
['an unset birthday', [0x07, 0xd0, 0, 0]],
['an all-zero value', [0, 0, 0, 0]],
['an out-of-range month', [0x07, 0xd0, 13, 1]],
['an out-of-range day', [0x07, 0xd0, 1, 32]],
['a truncated value', [0x07, 0xd0, 3]],
])('leaves the birthday unavailable for %s', async (_case, value) => {
const sender = makeSender({
body: {
uin: 10001,
properties: {
bytesProperties: [{ code: 20031, value: new Uint8Array(value) }],
},
},
});
const profile = await FetchUserProfile.invoke(sender, { uin: 10001 });
for (const name of ['birthdayYear', 'birthdayMonth', 'birthdayDay']) {
expect(profile).not.toHaveProperty(name);
}
});
@@ -133,6 +204,7 @@ describe('FetchUserProfile namespace', () => {
expect(keys).toContain(101); // avatar
expect(keys).toContain(102); // sign
expect(keys).toContain(103); // remark
expect(keys).toContain(20031); // birthday
expect(keys).toContain(40410); // qidian crew flag (企点员工标志)
expect(keys).toContain(42031); // qidian master flag (企点主号标志)
});