feat(onebot): fetch custom face details
Add packet-backed custom face detail retrieval and expose the result through the OneBot action. Fixes #333
This commit is contained in:
8 files changed
+363
-7
No files matched your search
@@ -1219,6 +1219,40 @@ export const actions = [
|
||||
},
|
||||
}),
|
||||
|
||||
defineAction({
|
||||
name: 'fetch_custom_face_detail',
|
||||
summary: '获取自定义表情详情',
|
||||
readOnly: true,
|
||||
returns: '自定义表情详情数组,包含资源标识、图片地址、摘要与描述。',
|
||||
returnsSchema: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
emoji_id: { type: 'string', description: '可传给 SnowLuma 表情管理接口的资源标识' },
|
||||
resId: { type: 'string', description: '兼容 NapCat 的资源标识' },
|
||||
url: { type: 'string', description: '表情图片地址' },
|
||||
md5: { type: 'string', description: '表情内容摘要' },
|
||||
desc: { type: 'string', description: '自定义表情描述;未设置时为空字符串' },
|
||||
},
|
||||
required: ['emoji_id', 'resId', 'url', 'md5', 'desc'],
|
||||
},
|
||||
},
|
||||
params: {
|
||||
count: f.int({ min: 0 }).default(48),
|
||||
},
|
||||
run: async (p, ctx) => {
|
||||
const details = await ctx.bridge.apis.profile.fetchCustomFaceDetails(p.count);
|
||||
return okResponse(details.map((detail) => ({
|
||||
emoji_id: detail.emojiId,
|
||||
resId: detail.emojiId,
|
||||
url: detail.url,
|
||||
md5: detail.md5,
|
||||
desc: detail.desc,
|
||||
})));
|
||||
},
|
||||
}),
|
||||
|
||||
defineAction({
|
||||
name: 'get_emoji_likes',
|
||||
summary: '获取表情回应用户',
|
||||
|
||||
@@ -90,9 +90,9 @@ describe('compileActionRegistry namespace conflicts', () => {
|
||||
});
|
||||
|
||||
describe('compiled production Action registry', () => {
|
||||
it('preserves all 185 canonical Action docs', () => {
|
||||
expect(ACTION_REGISTRY.actions).toHaveLength(185);
|
||||
expect(collectActionDocs()).toHaveLength(185);
|
||||
it('preserves all 186 canonical Action docs', () => {
|
||||
expect(ACTION_REGISTRY.actions).toHaveLength(186);
|
||||
expect(collectActionDocs()).toHaveLength(186);
|
||||
});
|
||||
|
||||
it('resolves every executable name to exactly one canonical doc', () => {
|
||||
|
||||
@@ -61,6 +61,7 @@ const APIS_ROUTING: Record<string, [string, string]> = {
|
||||
setAvatar: ['profile', 'setAvatar'],
|
||||
setGroupAvatar: ['profile', 'setGroupAvatar'],
|
||||
fetchCustomFace: ['profile', 'fetchCustomFace'],
|
||||
fetchCustomFaceDetails: ['profile', 'fetchCustomFaceDetails'],
|
||||
getProfileLike: ['profile', 'getLike'],
|
||||
getUnidirectionalFriendList: ['profile', 'getUnidirectionalFriendList'],
|
||||
// FriendApi: handleRequest/delete/setRemark.
|
||||
@@ -1407,6 +1408,51 @@ describe('extended-actions / set_group_portrait', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('extended-actions / fetch_custom_face_detail', () => {
|
||||
it('returns real packet-backed fields with SnowLuma and NapCat resource aliases', async () => {
|
||||
const fetchCustomFaceDetails = vi.fn(async () => [{
|
||||
emojiId: '10001_0_0_0_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA_0_0',
|
||||
url: 'https://p.qpic.cn/qq_expression/10001/id/0',
|
||||
md5: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
|
||||
desc: '开心',
|
||||
}]);
|
||||
const bridge = fakeBridge({ fetchCustomFaceDetails });
|
||||
|
||||
const response = await makeHandler(fakeCtx(bridge)).handle('fetch_custom_face_detail', {
|
||||
count: '1',
|
||||
});
|
||||
|
||||
expect(fetchCustomFaceDetails).toHaveBeenCalledWith(1);
|
||||
expect(response).toMatchObject({
|
||||
status: 'ok',
|
||||
data: [{
|
||||
emoji_id: '10001_0_0_0_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA_0_0',
|
||||
resId: '10001_0_0_0_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA_0_0',
|
||||
url: 'https://p.qpic.cn/qq_expression/10001/id/0',
|
||||
md5: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
|
||||
desc: '开心',
|
||||
}],
|
||||
});
|
||||
});
|
||||
|
||||
it('defaults to the compatibility page size of 48', async () => {
|
||||
const fetchCustomFaceDetails = vi.fn(async () => []);
|
||||
const bridge = fakeBridge({ fetchCustomFaceDetails });
|
||||
await makeHandler(fakeCtx(bridge)).handle('fetch_custom_face_detail', {});
|
||||
expect(fetchCustomFaceDetails).toHaveBeenCalledWith(48);
|
||||
});
|
||||
|
||||
it('rejects a negative count before calling the bridge', async () => {
|
||||
const fetchCustomFaceDetails = vi.fn();
|
||||
const bridge = fakeBridge({ fetchCustomFaceDetails });
|
||||
const response = await makeHandler(fakeCtx(bridge)).handle('fetch_custom_face_detail', {
|
||||
count: -1,
|
||||
});
|
||||
expect(response).toMatchObject({ status: 'failed', retcode: 1400 });
|
||||
expect(fetchCustomFaceDetails).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
// ─── Wave 1: get_group_shut_list ───
|
||||
|
||||
describe('extended-actions / get_group_shut_list', () => {
|
||||
|
||||
Reference in new issue
Block a user