feat(onebot): expose friend remarks in stranger info

Return the already-decoded profile remark from fetched and cached get_stranger_info results, document its fallback shape, and regenerate the MCP action catalog.

Fixes #290
This commit is contained in:
DrSmoothl committed 2026-07-28 23:59:25 +08:00
1 parent eeaa5436fd
commit 19e3135e63
6 files changed
+38 -10

No files matched your search

+6 -1
View File
@@ -6384,7 +6384,7 @@
"name": "get_stranger_info",
"aliases": [],
"summary": "获取陌生人信息",
"returns": "陌生人资料:QQ 号、昵称、性别、年龄与个性签名,命中资料时另含等级。",
"returns": "用户资料:QQ 号、昵称、好友备注、性别、年龄与个性签名,命中资料时另含等级。",
"returnsSchema": {
"type": "object",
"properties": {
@@ -6396,6 +6396,10 @@
"type": "string",
"description": "昵称"
},
"remark": {
"type": "string",
"description": "好友备注;非好友或未设置时为空字符串"
},
"sex": {
"type": "string",
"description": "性别(male/female/unknown)"
@@ -6420,6 +6424,7 @@
"required": [
"user_id",
"nickname",
"remark",
"sex",
"age",
"long_nick"
+6 -1
View File
@@ -6387,7 +6387,7 @@ export const ACTIONS: CatalogAction[] = [
"name": "get_stranger_info",
"aliases": [],
"summary": "获取陌生人信息",
"returns": "陌生人资料:QQ 号、昵称、性别、年龄与个性签名,命中资料时另含等级。",
"returns": "用户资料:QQ 号、昵称、好友备注、性别、年龄与个性签名,命中资料时另含等级。",
"returnsSchema": {
"type": "object",
"properties": {
@@ -6399,6 +6399,10 @@ export const ACTIONS: CatalogAction[] = [
"type": "string",
"description": "昵称"
},
"remark": {
"type": "string",
"description": "好友备注;非好友或未设置时为空字符串"
},
"sex": {
"type": "string",
"description": "性别(male/female/unknown)"
@@ -6423,6 +6427,7 @@ export const ACTIONS: CatalogAction[] = [
"required": [
"user_id",
"nickname",
"remark",
"sex",
"age",
"long_nick"
+5 -4
View File
@@ -32,19 +32,20 @@ export const actions = [
name: 'get_stranger_info',
summary: '获取陌生人信息',
readOnly: true,
returns: '陌生人资料:QQ 号、昵称、性别、年龄与个性签名,命中资料时另含等级。',
returns: '用户资料:QQ 号、昵称、好友备注、性别、年龄与个性签名,命中资料时另含等级。',
returnsSchema: {
type: 'object',
properties: {
user_id: { type: 'integer', description: 'QQ 号' },
nickname: { type: 'string', description: '昵称' },
remark: { 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', 'long_nick'],
required: ['user_id', 'nickname', 'remark', 'sex', 'age', 'long_nick'],
},
params: { user_id: f.userId().describe('QQ 号') },
run: async (p, ctx) => {
@@ -52,11 +53,11 @@ export const actions = [
if (ctx.getStrangerInfo) {
const info = await ctx.getStrangerInfo(userId);
return okResponse(info ?? {
user_id: userId, nickname: '', sex: 'unknown', age: 0, long_nick: '',
user_id: userId, nickname: '', remark: '', sex: 'unknown', age: 0, long_nick: '',
});
}
return okResponse({
user_id: userId, nickname: '', sex: 'unknown', age: 0, long_nick: '',
user_id: userId, nickname: '', remark: '', sex: 'unknown', age: 0, long_nick: '',
});
},
}),
@@ -248,6 +248,7 @@ export async function getStrangerInfo(
return {
user_id: p.uin,
nickname: p.nickname,
remark: p.remark,
sex: p.sex,
age: p.age,
long_nick: p.sign,
@@ -260,6 +261,7 @@ export async function getStrangerInfo(
return {
user_id: p.uin,
nickname: p.nickname,
remark: p.remark,
sex: p.sex,
age: p.age,
long_nick: p.sign,
+15 -3
View File
@@ -101,9 +101,10 @@ function makeProfile(
sex: 'male' | 'female' | 'unknown' = 'unknown',
age = 0,
sign = '',
remark = '',
): UserProfileInfo {
return {
uin, uid: `u_${uin}`, nickname, remark: '', qid: '', sex, age, sign, avatar: '',
uin, uid: `u_${uin}`, nickname, remark, qid: '', sex, age, sign, avatar: '',
};
}
@@ -448,7 +449,14 @@ 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, 'Stay curious')),
fetchUserProfile: vi.fn(async () => makeProfile(
55555,
'Eve',
'female',
25,
'Stay curious',
'Teammate',
)),
});
const out = await getStrangerInfo(bridge, 55555);
expect(out).toMatchObject({
@@ -456,6 +464,7 @@ describe('onebot/contact-actions / getStrangerInfo', () => {
nickname: 'Eve',
sex: 'female',
age: 25,
remark: 'Teammate',
long_nick: 'Stay curious',
});
});
@@ -465,13 +474,16 @@ 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, 'Cached signature') : null,
uin === 66666
? makeProfile(66666, 'Frank', 'male', 30, 'Cached signature', 'Cached remark')
: null,
}),
});
const out = await getStrangerInfo(bridge, 66666);
expect(out).toMatchObject({
user_id: 66666,
nickname: 'Frank',
remark: 'Cached remark',
long_nick: 'Cached signature',
});
});
+4 -1
View File
@@ -15,6 +15,7 @@ describe('get_stranger_info action', () => {
data: {
user_id: 123456,
nickname: '',
remark: '',
sex: 'unknown',
age: 0,
long_nick: '',
@@ -22,15 +23,17 @@ describe('get_stranger_info action', () => {
});
});
it('documents long_nick as a required string response field', () => {
it('documents remark and long_nick as required string response fields', () => {
const schema = getStrangerInfo.describe().returnsSchema;
expect(schema).toMatchObject({
type: 'object',
properties: {
remark: { type: 'string', description: '好友备注;非好友或未设置时为空字符串' },
long_nick: { type: 'string', description: '个性签名' },
},
});
expect(schema?.required).toContain('remark');
expect(schema?.required).toContain('long_nick');
});
});