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