feat(onebot): expose friend dress queries (#277)

Add a read-only action for querying QQ profile decorations from the authenticated web page.

Validate and classify page responses, expose structured errors, and cover parsing with a sanitized fixture.
This commit is contained in:
H3CoF6 authored and GitHub committed 2026-07-25 19:53:24 +08:00
1 parent 679756d1a7
commit 3517257aa6
8 files changed
+865 -5

No files matched your search

+20
View File
@@ -1,4 +1,5 @@
import { readFile } from 'node:fs/promises';
import { FriendDressError } from '@snowluma/protocol/web/friend-dress';
import type { ApiActionContext } from '../api-handler';
import { asNumber, asString } from '../api-handler';
import type { ForwardPreviewMeta } from '../modules/message-actions';
@@ -2438,6 +2439,25 @@ export const actions = [
return okResponse({ fileset_id: filesetId });
},
}),
// 好友个性装扮
defineAction({
name: '_get_friend_dress',
summary: '获取指定 QQ 号正在使用的个性装扮(挂件/名片/来电/输入状态等)',
returns: '装扮信息;目标未使用任何可查询装扮时 items 为空数组。网络失败、未登录态/风控、页面改版、返回账号与请求不一致时返回失败并附具体原因',
readOnly: true,
params: { user_id: f.userId().describe('目标 QQ 号') },
run: async (p, ctx) => {
try {
return okResponse(await ctx.bridge.apis.web.getFriendDress(p.user_id));
} catch (e) {
if (e instanceof FriendDressError) {
return failedResponse(RETCODE.ACTION_FAILED, `failed to get friend dress (${e.kind}): ${e.message}`);
}
return failedResponse(RETCODE.ACTION_FAILED, `failed to get friend dress: ${(e as Error).message}`);
}
},
}),
];
// 已过滤(机器人/被忽略)的入群请求。
@@ -90,9 +90,9 @@ describe('compileActionRegistry namespace conflicts', () => {
});
describe('compiled production Action registry', () => {
it('preserves all 179 canonical Action docs', () => {
expect(ACTION_REGISTRY.actions).toHaveLength(179);
expect(collectActionDocs()).toHaveLength(179);
it('preserves all 180 canonical Action docs', () => {
expect(ACTION_REGISTRY.actions).toHaveLength(180);
expect(collectActionDocs()).toHaveLength(180);
});
it('resolves every executable name to exactly one canonical doc', () => {