diff --git a/packages/mcp/src/generated/catalog.json b/packages/mcp/src/generated/catalog.json index abf58e1c..23b1ef07 100644 --- a/packages/mcp/src/generated/catalog.json +++ b/packages/mcp/src/generated/catalog.json @@ -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;不可用时省略" diff --git a/packages/mcp/src/generated/catalog.ts b/packages/mcp/src/generated/catalog.ts index 0c23e4c4..24a66906 100644 --- a/packages/mcp/src/generated/catalog.ts +++ b/packages/mcp/src/generated/catalog.ts @@ -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;不可用时省略" diff --git a/packages/onebot/src/actions/friend.ts b/packages/onebot/src/actions/friend.ts index fb8dd0d4..af7e4773 100644 --- a/packages/onebot/src/actions/friend.ts +++ b/packages/onebot/src/actions/friend.ts @@ -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: '会员等级,不可用时省略' }, diff --git a/packages/onebot/src/modules/contact-actions.ts b/packages/onebot/src/modules/contact-actions.ts index 2662bb8f..a7be276d 100644 --- a/packages/onebot/src/modules/contact-actions.ts +++ b/packages/onebot/src/modules/contact-actions.ts @@ -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 } : {}), diff --git a/packages/onebot/tests/contact-actions.test.ts b/packages/onebot/tests/contact-actions.test.ts index f8b21766..7159486e 100644 --- a/packages/onebot/tests/contact-actions.test.ts +++ b/packages/onebot/tests/contact-actions.test.ts @@ -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 () => diff --git a/packages/onebot/tests/friend-actions.test.ts b/packages/onebot/tests/friend-actions.test.ts index 249732d3..6a901ece 100644 --- a/packages/onebot/tests/friend-actions.test.ts +++ b/packages/onebot/tests/friend-actions.test.ts @@ -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); + } + }); }); diff --git a/packages/protocol/src/oidb-services/contacts/fetch-user-profile-by-uid.ts b/packages/protocol/src/oidb-services/contacts/fetch-user-profile-by-uid.ts index 05257a17..3a3d480d 100644 --- a/packages/protocol/src/oidb-services/contacts/fetch-user-profile-by-uid.ts +++ b/packages/protocol/src/oidb-services/contacts/fetch-user-profile-by-uid.ts @@ -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; diff --git a/packages/protocol/src/oidb-services/contacts/fetch-user-profile.ts b/packages/protocol/src/oidb-services/contacts/fetch-user-profile.ts index 3391d187..37bcd980 100644 --- a/packages/protocol/src/oidb-services/contacts/fetch-user-profile.ts +++ b/packages/protocol/src/oidb-services/contacts/fetch-user-profile.ts @@ -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): 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; diff --git a/packages/protocol/src/qq-info.ts b/packages/protocol/src/qq-info.ts index 2ceefc2d..a45c2a78 100644 --- a/packages/protocol/src/qq-info.ts +++ b/packages/protocol/src/qq-info.ts @@ -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; diff --git a/packages/protocol/tests/oidb-services/contacts/fetch-user-profile.test.ts b/packages/protocol/tests/oidb-services/contacts/fetch-user-profile.test.ts index 9f40af16..0a313cb3 100644 --- a/packages/protocol/tests/oidb-services/contacts/fetch-user-profile.test.ts +++ b/packages/protocol/tests/oidb-services/contacts/fetch-user-profile.test.ts @@ -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 (企点主号标志) });