diff --git a/packages/mcp/src/generated/catalog.json b/packages/mcp/src/generated/catalog.json index 3073f5fe..c91eade9 100644 --- a/packages/mcp/src/generated/catalog.json +++ b/packages/mcp/src/generated/catalog.json @@ -5751,7 +5751,7 @@ "name": "get_stranger_info", "aliases": [], "summary": "获取陌生人信息", - "returns": "陌生人资料:QQ 号、昵称、性别、年龄,命中资料时另含等级。", + "returns": "陌生人资料:QQ 号、昵称、性别、年龄与个性签名,命中资料时另含等级。", "returnsSchema": { "type": "object", "properties": { @@ -5771,6 +5771,10 @@ "type": "integer", "description": "年龄" }, + "long_nick": { + "type": "string", + "description": "个性签名" + }, "qq_level": { "type": "integer", "description": "QQ 等级(仅查到资料时返回)" @@ -5784,7 +5788,8 @@ "user_id", "nickname", "sex", - "age" + "age", + "long_nick" ] }, "readOnly": true, diff --git a/packages/mcp/src/generated/catalog.ts b/packages/mcp/src/generated/catalog.ts index 8922d44b..286fb53b 100644 --- a/packages/mcp/src/generated/catalog.ts +++ b/packages/mcp/src/generated/catalog.ts @@ -5754,7 +5754,7 @@ export const ACTIONS: CatalogAction[] = [ "name": "get_stranger_info", "aliases": [], "summary": "获取陌生人信息", - "returns": "陌生人资料:QQ 号、昵称、性别、年龄,命中资料时另含等级。", + "returns": "陌生人资料:QQ 号、昵称、性别、年龄与个性签名,命中资料时另含等级。", "returnsSchema": { "type": "object", "properties": { @@ -5774,6 +5774,10 @@ export const ACTIONS: CatalogAction[] = [ "type": "integer", "description": "年龄" }, + "long_nick": { + "type": "string", + "description": "个性签名" + }, "qq_level": { "type": "integer", "description": "QQ 等级(仅查到资料时返回)" @@ -5787,7 +5791,8 @@ export const ACTIONS: CatalogAction[] = [ "user_id", "nickname", "sex", - "age" + "age", + "long_nick" ] }, "readOnly": true, diff --git a/packages/onebot/src/actions/friend.ts b/packages/onebot/src/actions/friend.ts index f9279239..3d27ce19 100644 --- a/packages/onebot/src/actions/friend.ts +++ b/packages/onebot/src/actions/friend.ts @@ -32,7 +32,7 @@ export const actions = [ name: 'get_stranger_info', summary: '获取陌生人信息', readOnly: true, - returns: '陌生人资料:QQ 号、昵称、性别、年龄,命中资料时另含等级。', + returns: '陌生人资料:QQ 号、昵称、性别、年龄与个性签名,命中资料时另含等级。', returnsSchema: { type: 'object', properties: { @@ -40,19 +40,24 @@ export const actions = [ nickname: { type: 'string', description: '昵称' }, sex: { type: 'string', description: '性别(male/female/unknown)' }, age: { type: 'integer', description: '年龄' }, + long_nick: { type: 'string', description: '个性签名' }, qq_level: { type: 'integer', description: 'QQ 等级(仅查到资料时返回)' }, level: { type: 'integer', description: 'QQ 等级,同 qq_level(仅查到资料时返回)' }, }, - required: ['user_id', 'nickname', 'sex', 'age'], + required: ['user_id', 'nickname', 'sex', 'age', 'long_nick'], }, params: { user_id: f.userId().describe('QQ 号') }, run: async (p, ctx) => { const userId = p.user_id; if (ctx.getStrangerInfo) { const info = await ctx.getStrangerInfo(userId); - return okResponse(info ?? { user_id: userId, nickname: '', sex: 'unknown', age: 0 }); + return okResponse(info ?? { + user_id: userId, nickname: '', sex: 'unknown', age: 0, long_nick: '', + }); } - return okResponse({ user_id: userId, nickname: '', sex: 'unknown', age: 0 }); + return okResponse({ + user_id: userId, nickname: '', sex: 'unknown', age: 0, long_nick: '', + }); }, }), @@ -66,4 +71,3 @@ export const actions = [ }, }), ]; - diff --git a/packages/onebot/src/modules/contact-actions.ts b/packages/onebot/src/modules/contact-actions.ts index 10d50554..9a172365 100644 --- a/packages/onebot/src/modules/contact-actions.ts +++ b/packages/onebot/src/modules/contact-actions.ts @@ -225,6 +225,7 @@ export async function getStrangerInfo( nickname: p.nickname, sex: p.sex, age: p.age, + long_nick: p.sign, qq_level: p.level, level: p.level, }; @@ -236,6 +237,7 @@ export async function getStrangerInfo( nickname: p.nickname, sex: p.sex, age: p.age, + long_nick: p.sign, qq_level: p.level, level: p.level, }; diff --git a/packages/onebot/tests/contact-actions.test.ts b/packages/onebot/tests/contact-actions.test.ts index 213e3878..299c20ec 100644 --- a/packages/onebot/tests/contact-actions.test.ts +++ b/packages/onebot/tests/contact-actions.test.ts @@ -89,9 +89,15 @@ function makeMember(uin: number, nickname: string, card = ''): GroupMemberInfo { }; } -function makeProfile(uin: number, nickname: string, sex: 'male' | 'female' | 'unknown' = 'unknown', age = 0): UserProfileInfo { +function makeProfile( + uin: number, + nickname: string, + sex: 'male' | 'female' | 'unknown' = 'unknown', + age = 0, + sign = '', +): UserProfileInfo { return { - uin, uid: `u_${uin}`, nickname, remark: '', qid: '', sex, age, sign: '', avatar: '', + uin, uid: `u_${uin}`, nickname, remark: '', qid: '', sex, age, sign, avatar: '', }; } @@ -353,10 +359,16 @@ describe('onebot/contact-actions / getGroupMemberInfo', () => { describe('onebot/contact-actions / getStrangerInfo', () => { it('returns a fetched profile', async () => { const bridge = fakeBridge({ - fetchUserProfile: vi.fn(async () => makeProfile(55555, 'Eve', 'female', 25)), + fetchUserProfile: vi.fn(async () => makeProfile(55555, 'Eve', 'female', 25, 'Stay curious')), }); const out = await getStrangerInfo(bridge, 55555); - expect(out).toMatchObject({ user_id: 55555, nickname: 'Eve', sex: 'female', age: 25 }); + expect(out).toMatchObject({ + user_id: 55555, + nickname: 'Eve', + sex: 'female', + age: 25, + long_nick: 'Stay curious', + }); }); it('falls back to identity.findUserProfile when fetch fails but the profile is cached', async () => { @@ -364,11 +376,15 @@ describe('onebot/contact-actions / getStrangerInfo', () => { fetchUserProfile: vi.fn(async () => { throw new Error('net'); }), identity: fakeIdentity({ findUserProfile: (uin: number) => - uin === 66666 ? makeProfile(66666, 'Frank', 'male', 30) : null, + uin === 66666 ? makeProfile(66666, 'Frank', 'male', 30, 'Cached signature') : null, }), }); const out = await getStrangerInfo(bridge, 66666); - expect(out).toMatchObject({ user_id: 66666, nickname: 'Frank' }); + expect(out).toMatchObject({ + user_id: 66666, + nickname: 'Frank', + long_nick: 'Cached signature', + }); }); it('returns null when neither fetch nor cache produces a profile', async () => { diff --git a/packages/onebot/tests/friend-actions.test.ts b/packages/onebot/tests/friend-actions.test.ts new file mode 100644 index 00000000..b02b197a --- /dev/null +++ b/packages/onebot/tests/friend-actions.test.ts @@ -0,0 +1,36 @@ +import { describe, expect, it } from 'vitest'; +import type { ApiActionContext } from '../src/api-handler'; +import { actions } from '../src/actions/friend'; + +const getStrangerInfo = actions.find((action) => action.names[0] === 'get_stranger_info'); +if (!getStrangerInfo) throw new Error('get_stranger_info action missing'); + +describe('get_stranger_info action', () => { + it('returns an empty long_nick when no profile provider is available', async () => { + const response = await getStrangerInfo.toHandler({} as ApiActionContext)({ user_id: 123456 }); + + expect(response).toMatchObject({ + status: 'ok', + retcode: 0, + data: { + user_id: 123456, + nickname: '', + sex: 'unknown', + age: 0, + long_nick: '', + }, + }); + }); + + it('documents long_nick as a required string response field', () => { + const schema = getStrangerInfo.describe().returnsSchema; + + expect(schema).toMatchObject({ + type: 'object', + properties: { + long_nick: { type: 'string', description: '个性签名' }, + }, + }); + expect(schema?.required).toContain('long_nick'); + }); +});