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

+13 -1
View File
@@ -12615,7 +12615,7 @@
"name": "get_stranger_info",
"aliases": [],
"summary": "获取陌生人信息",
"returns": "用户资料,含账号标识、等级别名和可用的注册时间、会员信息。注册时间或会员信息未返回时省略对应字段;登录天数暂无可靠来源,不返回占位值。",
"returns": "用户资料,含账号标识、等级别名和可用的注册时间、生日、会员信息。注册时间、生日或会员信息未返回时省略对应字段,出生年份未公开时只省略年份;登录天数暂无可靠来源,不返回占位值。",
"returnsSchema": {
"type": "object",
"properties": {
@@ -12663,6 +12663,18 @@
"type": "integer",
"description": "注册时间戳(秒),不可用时省略"
},
"birthday_year": {
"type": "integer",
"description": "生日年份,兼容 NapCat;未公开或不可用时省略"
},
"birthday_month": {
"type": "integer",
"description": "生日月份(1-12),兼容 NapCat;不可用时省略"
},
"birthday_day": {
"type": "integer",
"description": "生日日期(1-31),兼容 NapCat;不可用时省略"
},
"is_vip": {
"type": "boolean",
"description": "超级会员状态,兼容 NapCat;不可用时省略"
+13 -1
View File
@@ -12618,7 +12618,7 @@ export const ACTIONS: CatalogAction[] = [
"name": "get_stranger_info",
"aliases": [],
"summary": "获取陌生人信息",
"returns": "用户资料,含账号标识、等级别名和可用的注册时间、会员信息。注册时间或会员信息未返回时省略对应字段;登录天数暂无可靠来源,不返回占位值。",
"returns": "用户资料,含账号标识、等级别名和可用的注册时间、生日、会员信息。注册时间、生日或会员信息未返回时省略对应字段,出生年份未公开时只省略年份;登录天数暂无可靠来源,不返回占位值。",
"returnsSchema": {
"type": "object",
"properties": {
@@ -12666,6 +12666,18 @@ export const ACTIONS: CatalogAction[] = [
"type": "integer",
"description": "注册时间戳(秒),不可用时省略"
},
"birthday_year": {
"type": "integer",
"description": "生日年份,兼容 NapCat;未公开或不可用时省略"
},
"birthday_month": {
"type": "integer",
"description": "生日月份(1-12),兼容 NapCat;不可用时省略"
},
"birthday_day": {
"type": "integer",
"description": "生日日期(1-31),兼容 NapCat;不可用时省略"
},
"is_vip": {
"type": "boolean",
"description": "超级会员状态,兼容 NapCat;不可用时省略"
+13 -1
View File
@@ -49,7 +49,7 @@ export const actions = [
summary: '获取陌生人信息',
readOnly: true,
returns:
'用户资料,含账号标识、等级别名和可用的注册时间、会员信息。注册时间或会员信息未返回时省略对应字段;登录天数暂无可靠来源,不返回占位值。',
'用户资料,含账号标识、等级别名和可用的注册时间、生日、会员信息。注册时间、生日或会员信息未返回时省略对应字段,出生年份未公开时只省略年份;登录天数暂无可靠来源,不返回占位值。',
returnsSchema: {
type: 'object',
properties: {
@@ -64,6 +64,18 @@ export const actions = [
qq_level: { type: 'integer', description: 'QQ 等级(仅查到资料时返回)' },
qqLevel: { type: 'integer', description: 'QQ 等级,同 qq_level' },
reg_time: { type: 'integer', description: '注册时间戳(秒),不可用时省略' },
birthday_year: {
type: 'integer',
description: '生日年份,兼容 NapCat;未公开或不可用时省略',
},
birthday_month: {
type: 'integer',
description: '生日月份(1-12),兼容 NapCat;不可用时省略',
},
birthday_day: {
type: 'integer',
description: '生日日期(1-31),兼容 NapCat;不可用时省略',
},
is_vip: { type: 'boolean', description: '超级会员状态,兼容 NapCat;不可用时省略' },
is_years_vip: { type: 'boolean', description: '年费会员状态,不可用时省略' },
vip_level: { type: 'integer', description: '会员等级,不可用时省略' },
@@ -387,6 +387,9 @@ function formatStrangerInfo(p: UserProfileInfo, corp?: QidianCorpInfo | null): J
qqLevel: p.level,
level: p.level,
...(p.regTime !== undefined ? { reg_time: p.regTime } : {}),
...(p.birthdayYear !== undefined ? { birthday_year: p.birthdayYear } : {}),
...(p.birthdayMonth !== undefined ? { birthday_month: p.birthdayMonth } : {}),
...(p.birthdayDay !== undefined ? { birthday_day: p.birthdayDay } : {}),
...(p.svipFlag !== undefined ? { is_vip: p.svipFlag } : {}),
...(p.yearVipFlag !== undefined ? { is_years_vip: p.yearVipFlag } : {}),
...(p.vipLevel !== undefined ? { vip_level: p.vipLevel } : {}),
+28 -1
View File
@@ -739,6 +739,9 @@ describe('onebot/contact-actions / getStrangerInfo', () => {
qid: 'my_qid',
level: 64,
regTime: 1_200_000_000,
birthdayYear: 2000,
birthdayMonth: 3,
birthdayDay: 15,
svipFlag: true,
yearVipFlag: false,
vipLevel: 7,
@@ -752,6 +755,9 @@ describe('onebot/contact-actions / getStrangerInfo', () => {
qqLevel: 64,
level: 64,
reg_time: 1_200_000_000,
birthday_year: 2000,
birthday_month: 3,
birthday_day: 15,
is_vip: true,
is_years_vip: false,
vip_level: 7,
@@ -765,11 +771,32 @@ describe('onebot/contact-actions / getStrangerInfo', () => {
});
const out = await getStrangerInfo(bridge, 55555);
for (const field of ['reg_time', 'is_vip', 'is_years_vip', 'vip_level']) {
for (const field of [
'reg_time',
'birthday_year',
'birthday_month',
'birthday_day',
'is_vip',
'is_years_vip',
'vip_level',
]) {
expect(out).not.toHaveProperty(field);
}
});
it('omits only birthday_year when the birth year is hidden', async () => {
const bridge = fakeBridge({
fetchUserProfile: vi.fn(async () => ({
...makeProfile(55555, 'member'),
birthdayMonth: 12,
birthdayDay: 31,
})),
});
const out = await getStrangerInfo(bridge, 55555);
expect(out).toMatchObject({ birthday_month: 12, birthday_day: 31 });
expect(out).not.toHaveProperty('birthday_year');
});
it('returns a fetched profile', async () => {
const bridge = fakeBridge({
fetchUserProfile: vi.fn(async () =>
@@ -45,4 +45,13 @@ describe('get_stranger_info action', () => {
expect(schema?.required).toContain('remark');
expect(schema?.required).toContain('long_nick');
});
it('documents the NapCat-compatible birthday fields as optional integers', () => {
const schema = getStrangerInfo.describe().returnsSchema;
for (const field of ['birthday_year', 'birthday_month', 'birthday_day']) {
expect(schema?.properties?.[field]).toMatchObject({ type: 'integer' });
expect(schema?.required).not.toContain(field);
}
});
});
@@ -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 (企点主号标志)
});