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:
1 parent
6b8362e049
commit
947af4b22c
10 files changed
+192
-6
No files matched your search
@@ -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 } : {}),
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user