fix(onebot): return categorized friend lists

This commit is contained in:
DrSmoothl committed 2026-07-13 18:51:45 +08:00
1 parent 8cd7d51d80
commit b5452c59e6
6 files changed
+202 -5

No files matched your search

+54
View File
@@ -3019,6 +3019,60 @@
"name": "get_friends_with_category",
"aliases": [],
"summary": "获取分组好友列表",
"returns": "好友分组数组;每组包含 categoryId、categoryName、categoryMbCount 和 buddyList。",
"returnsSchema": {
"type": "array",
"description": "带分组的好友列表",
"items": {
"type": "object",
"properties": {
"categoryId": {
"type": "integer",
"description": "分组 ID"
},
"categoryName": {
"type": "string",
"description": "分组名称"
},
"categoryMbCount": {
"type": "integer",
"description": "服务端报告的分组好友数"
},
"buddyList": {
"type": "array",
"description": "该分组内的好友",
"items": {
"type": "object",
"properties": {
"user_id": {
"type": "integer",
"description": "QQ 号"
},
"nickname": {
"type": "string",
"description": "昵称"
},
"remark": {
"type": "string",
"description": "好友备注"
}
},
"required": [
"user_id",
"nickname",
"remark"
]
}
}
},
"required": [
"categoryId",
"categoryName",
"categoryMbCount",
"buddyList"
]
}
},
"readOnly": true,
"params": [],
"invariants": [],
+54
View File
@@ -3022,6 +3022,60 @@ export const ACTIONS: CatalogAction[] = [
"name": "get_friends_with_category",
"aliases": [],
"summary": "获取分组好友列表",
"returns": "好友分组数组;每组包含 categoryId、categoryName、categoryMbCount 和 buddyList。",
"returnsSchema": {
"type": "array",
"description": "带分组的好友列表",
"items": {
"type": "object",
"properties": {
"categoryId": {
"type": "integer",
"description": "分组 ID"
},
"categoryName": {
"type": "string",
"description": "分组名称"
},
"categoryMbCount": {
"type": "integer",
"description": "服务端报告的分组好友数"
},
"buddyList": {
"type": "array",
"description": "该分组内的好友",
"items": {
"type": "object",
"properties": {
"user_id": {
"type": "integer",
"description": "QQ 号"
},
"nickname": {
"type": "string",
"description": "昵称"
},
"remark": {
"type": "string",
"description": "好友备注"
}
},
"required": [
"user_id",
"nickname",
"remark"
]
}
}
},
"required": [
"categoryId",
"categoryName",
"categoryMbCount",
"buddyList"
]
}
},
"readOnly": true,
"params": [],
"invariants": [],
+38 -4
View File
@@ -1122,12 +1122,46 @@ export const actions = [
name: 'get_friends_with_category',
summary: '获取分组好友列表',
readOnly: true,
returns: '好友分组数组;每组包含 categoryId、categoryName、categoryMbCount 和 buddyList。',
returnsSchema: {
type: 'array',
description: '带分组的好友列表',
items: {
type: 'object',
properties: {
categoryId: { type: 'integer', description: '分组 ID' },
categoryName: { type: 'string', description: '分组名称' },
categoryMbCount: { type: 'integer', description: '服务端报告的分组好友数' },
buddyList: {
type: 'array',
description: '该分组内的好友',
items: {
type: 'object',
properties: {
user_id: { type: 'integer', description: 'QQ 号' },
nickname: { type: 'string', description: '昵称' },
remark: { type: 'string', description: '好友备注' },
},
required: ['user_id', 'nickname', 'remark'],
},
},
},
required: ['categoryId', 'categoryName', 'categoryMbCount', 'buddyList'],
},
},
params: {},
run: async (_p, ctx) => {
if (ctx.getFriendList) {
return okResponse(await ctx.getFriendList());
}
return okResponse([]);
const categories = await ctx.bridge.apis.contacts.fetchFriendCategories();
return okResponse(categories.map(category => ({
categoryId: category.categoryId,
categoryName: category.categoryName,
categoryMbCount: category.memberCount,
buddyList: category.friends.map(friend => ({
user_id: friend.uin,
nickname: friend.nickname,
remark: friend.remark,
})),
})));
},
}),
@@ -35,6 +35,7 @@ function fakeMeta(overrides: Partial<MessageMeta> = {}): MessageMeta {
// drops the redundant `Group`/`File` prefix.
const APIS_ROUTING: Record<string, [string, string]> = {
fetchFriendList: ['contacts', 'fetchFriendList'],
fetchFriendCategories: ['contacts', 'fetchFriendCategories'],
fetchGroupList: ['contacts', 'fetchGroupList'],
fetchGroupMemberList: ['contacts', 'fetchGroupMemberList'],
fetchUserProfile: ['contacts', 'fetchUserProfile'],
@@ -119,6 +120,46 @@ function makeHandler(ctx: ApiActionContext): ApiHandler {
return new ApiHandler(ctx);
}
describe('extended-actions / get_friends_with_category', () => {
it('returns the exact categorized friend contract', async () => {
const fetchFriendCategories = vi.fn(async () => [{
categoryId: 7,
categoryName: 'Work',
memberCount: 1,
sortId: 3,
friends: [{ uin: 10001, uid: 'u1', nickname: 'Alice', remark: 'A' }],
}]);
const bridge = fakeBridge({ fetchFriendCategories });
const response = await makeHandler(fakeCtx(bridge))
.handle('get_friends_with_category', {});
expect(fetchFriendCategories).toHaveBeenCalledOnce();
expect(response).toMatchObject({ status: 'ok', retcode: 0 });
expect(response.data).toEqual([{
categoryId: 7,
categoryName: 'Work',
categoryMbCount: 1,
buddyList: [{ user_id: 10001, nickname: 'Alice', remark: 'A' }],
}]);
});
it('surfaces categorized fetch failures', async () => {
const bridge = fakeBridge({
fetchFriendCategories: vi.fn(async () => {
throw new Error('repeated friend-list cookie aa');
}),
});
const response = await makeHandler(fakeCtx(bridge))
.handle('get_friends_with_category', {});
expect(response).toMatchObject({
status: 'failed',
retcode: 100,
wording: 'repeated friend-list cookie aa',
});
});
});
// ─── Tier 1: send_packet / .send_packet ───
describe('extended-actions / send_packet', () => {
+2 -1
View File
@@ -77,6 +77,7 @@ import type {
DownloadFileResult,
EmptyData,
ForwardMessageResult,
FriendCategoryResult,
FriendMessageHistory,
GroupAtAllRemainInfo,
GroupFileSystemInfo,
@@ -196,7 +197,7 @@ export interface SnowLumaActionMap {
fetch_custom_face: { params: FetchCustomFaceParams; data: string[] };
get_emoji_likes: { params: GetEmojiLikesParams; data: JsonObject };
fetch_emoji_like: { params: FetchEmojiLikeParams; data: JsonObject };
get_friends_with_category: { params: JsonObject; data: JsonObject[] };
get_friends_with_category: { params: JsonObject; data: FriendCategoryResult[] };
get_online_clients: { params: JsonObject; data: OnlineClientsInfo };
_get_model_show: { params: JsonObject; data: { variants: JsonArray } };
_set_model_show: { params: JsonObject; data: EmptyData };
+13
View File
@@ -60,6 +60,19 @@ export interface FriendMessageHistory {
messages: JsonObject[];
}
export interface CategorizedFriend {
user_id: number;
nickname: string;
remark: string;
}
export interface FriendCategoryResult {
categoryId: number;
categoryName: string;
categoryMbCount: number;
buddyList: CategorizedFriend[];
}
export interface MediaInfo extends JsonObject {}
export interface CookieInfo {