diff --git a/packages/mcp/src/generated/catalog.json b/packages/mcp/src/generated/catalog.json index 76014256..8f4ca704 100644 --- a/packages/mcp/src/generated/catalog.json +++ b/packages/mcp/src/generated/catalog.json @@ -2030,6 +2030,147 @@ }, "category": "扩展" }, + { + "name": "fetch_face_entity", + "aliases": [], + "summary": "按编号查询 QQ 系统表情", + "returns": "表情详情;编号不存在时返回 null。", + "returnsSchema": { + "anyOf": [ + { + "type": "object", + "properties": { + "q_sid": { + "type": "string", + "description": "表情编号" + }, + "q_des": { + "type": "string", + "description": "表情描述" + }, + "em_code": { + "type": "string" + }, + "q_cid": { + "type": [ + "integer", + "null" + ] + }, + "ani_sticker_type": { + "type": [ + "integer", + "null" + ] + }, + "ani_sticker_pack_id": { + "type": [ + "integer", + "null" + ] + }, + "ani_sticker_id": { + "type": [ + "integer", + "null" + ] + }, + "url": { + "type": [ + "string", + "null" + ] + }, + "emoji_name_alias": { + "type": "array", + "items": { + "type": "string" + } + }, + "ani_sticker_width": { + "type": [ + "integer", + "null" + ] + }, + "ani_sticker_height": { + "type": [ + "integer", + "null" + ] + }, + "is_super": { + "type": "boolean", + "description": "是否使用超级表情格式" + } + }, + "required": [ + "q_sid", + "q_des", + "em_code", + "q_cid", + "ani_sticker_type", + "ani_sticker_pack_id", + "ani_sticker_id", + "url", + "emoji_name_alias", + "ani_sticker_width", + "ani_sticker_height", + "is_super" + ] + }, + { + "type": "null" + } + ] + }, + "readOnly": true, + "params": [ + { + "name": "face_id", + "type": "int", + "required": true, + "schema": { + "type": "integer", + "minimum": 0 + }, + "role": "face_id", + "desc": "QQ 系统表情编号" + }, + { + "name": "refresh", + "type": "bool", + "required": false, + "schema": { + "type": "boolean" + }, + "default": false, + "desc": "是否强制从 QQ 刷新目录" + } + ], + "invariants": [], + "inputSchema": { + "type": "object", + "properties": { + "face_id": { + "type": "integer", + "minimum": 0, + "description": "QQ 系统表情编号", + "x-role": "face_id" + }, + "refresh": { + "type": "boolean", + "description": "是否强制从 QQ 刷新目录", + "default": false + } + }, + "required": [ + "face_id" + ], + "additionalProperties": true + }, + "category": "系统表情" + }, { "name": "fetch_ptt_text", "aliases": [ @@ -2077,6 +2218,209 @@ }, "category": "扩展" }, + { + "name": "fetch_super_face_id", + "aliases": [], + "summary": "判断 QQ 系统表情是否使用超级表情格式", + "returns": "是否使用超级表情格式。", + "returnsSchema": { + "type": "object", + "properties": { + "is_super": { + "type": "boolean" + } + }, + "required": [ + "is_super" + ] + }, + "readOnly": true, + "params": [ + { + "name": "face_id", + "type": "int", + "required": true, + "schema": { + "type": "integer", + "minimum": 0 + }, + "role": "face_id", + "desc": "QQ 系统表情编号" + }, + { + "name": "refresh", + "type": "bool", + "required": false, + "schema": { + "type": "boolean" + }, + "default": false, + "desc": "是否强制从 QQ 刷新目录" + } + ], + "invariants": [], + "inputSchema": { + "type": "object", + "properties": { + "face_id": { + "type": "integer", + "minimum": 0, + "description": "QQ 系统表情编号", + "x-role": "face_id" + }, + "refresh": { + "type": "boolean", + "description": "是否强制从 QQ 刷新目录", + "default": false + } + }, + "required": [ + "face_id" + ], + "additionalProperties": true + }, + "category": "系统表情" + }, + { + "name": "fetch_sys_faces", + "aliases": [], + "summary": "获取 QQ 系统表情目录", + "returns": "按分组返回完整的 QQ 系统表情映射。", + "returnsSchema": { + "type": "object", + "properties": { + "packs": { + "type": "array", + "items": { + "type": "object", + "properties": { + "pack_name": { + "type": "string" + }, + "emojis": { + "type": "array", + "items": { + "type": "object", + "properties": { + "q_sid": { + "type": "string", + "description": "表情编号" + }, + "q_des": { + "type": "string", + "description": "表情描述" + }, + "em_code": { + "type": "string" + }, + "q_cid": { + "type": [ + "integer", + "null" + ] + }, + "ani_sticker_type": { + "type": [ + "integer", + "null" + ] + }, + "ani_sticker_pack_id": { + "type": [ + "integer", + "null" + ] + }, + "ani_sticker_id": { + "type": [ + "integer", + "null" + ] + }, + "url": { + "type": [ + "string", + "null" + ] + }, + "emoji_name_alias": { + "type": "array", + "items": { + "type": "string" + } + }, + "ani_sticker_width": { + "type": [ + "integer", + "null" + ] + }, + "ani_sticker_height": { + "type": [ + "integer", + "null" + ] + }, + "is_super": { + "type": "boolean", + "description": "是否使用超级表情格式" + } + }, + "required": [ + "q_sid", + "q_des", + "em_code", + "q_cid", + "ani_sticker_type", + "ani_sticker_pack_id", + "ani_sticker_id", + "url", + "emoji_name_alias", + "ani_sticker_width", + "ani_sticker_height", + "is_super" + ] + } + } + }, + "required": [ + "pack_name", + "emojis" + ] + } + } + }, + "required": [ + "packs" + ] + }, + "readOnly": true, + "params": [ + { + "name": "refresh", + "type": "bool", + "required": false, + "schema": { + "type": "boolean" + }, + "default": false, + "desc": "是否强制从 QQ 刷新目录" + } + ], + "invariants": [], + "inputSchema": { + "type": "object", + "properties": { + "refresh": { + "type": "boolean", + "description": "是否强制从 QQ 刷新目录", + "default": false + } + }, + "additionalProperties": true + }, + "category": "系统表情" + }, { "name": "forward_friend_single_msg", "aliases": [], @@ -7373,6 +7717,134 @@ }, "category": "扩展" }, + { + "name": "search_sys_faces", + "aliases": [], + "summary": "搜索 QQ 系统表情", + "returns": "匹配编号、名称、别名或分组名的表情列表。", + "returnsSchema": { + "type": "object", + "properties": { + "faces": { + "type": "array", + "items": { + "type": "object", + "properties": { + "q_sid": { + "type": "string", + "description": "表情编号" + }, + "q_des": { + "type": "string", + "description": "表情描述" + }, + "em_code": { + "type": "string" + }, + "q_cid": { + "type": [ + "integer", + "null" + ] + }, + "ani_sticker_type": { + "type": [ + "integer", + "null" + ] + }, + "ani_sticker_pack_id": { + "type": [ + "integer", + "null" + ] + }, + "ani_sticker_id": { + "type": [ + "integer", + "null" + ] + }, + "url": { + "type": [ + "string", + "null" + ] + }, + "emoji_name_alias": { + "type": "array", + "items": { + "type": "string" + } + }, + "ani_sticker_width": { + "type": [ + "integer", + "null" + ] + }, + "ani_sticker_height": { + "type": [ + "integer", + "null" + ] + }, + "is_super": { + "type": "boolean", + "description": "是否使用超级表情格式" + } + }, + "required": [ + "q_sid", + "q_des", + "em_code", + "q_cid", + "ani_sticker_type", + "ani_sticker_pack_id", + "ani_sticker_id", + "url", + "emoji_name_alias", + "ani_sticker_width", + "ani_sticker_height", + "is_super" + ] + } + } + }, + "required": [ + "faces" + ] + }, + "readOnly": true, + "params": [ + { + "name": "query", + "type": "string", + "required": true, + "schema": { + "type": "string", + "minLength": 1 + }, + "desc": "编号、名称、别名或分组名" + } + ], + "invariants": [], + "inputSchema": { + "type": "object", + "properties": { + "query": { + "type": "string", + "minLength": 1, + "description": "编号、名称、别名或分组名" + } + }, + "required": [ + "query" + ], + "additionalProperties": true + }, + "category": "系统表情" + }, { "name": "send_ark_share", "aliases": [], @@ -11049,6 +11521,10 @@ "category": "空间", "count": 9 }, + { + "category": "系统表情", + "count": 4 + }, { "category": "流式接口", "count": 6 diff --git a/packages/mcp/src/generated/catalog.ts b/packages/mcp/src/generated/catalog.ts index 74bcd7d2..01b14708 100644 --- a/packages/mcp/src/generated/catalog.ts +++ b/packages/mcp/src/generated/catalog.ts @@ -2033,6 +2033,147 @@ export const ACTIONS: CatalogAction[] = [ }, "category": "扩展" }, + { + "name": "fetch_face_entity", + "aliases": [], + "summary": "按编号查询 QQ 系统表情", + "returns": "表情详情;编号不存在时返回 null。", + "returnsSchema": { + "anyOf": [ + { + "type": "object", + "properties": { + "q_sid": { + "type": "string", + "description": "表情编号" + }, + "q_des": { + "type": "string", + "description": "表情描述" + }, + "em_code": { + "type": "string" + }, + "q_cid": { + "type": [ + "integer", + "null" + ] + }, + "ani_sticker_type": { + "type": [ + "integer", + "null" + ] + }, + "ani_sticker_pack_id": { + "type": [ + "integer", + "null" + ] + }, + "ani_sticker_id": { + "type": [ + "integer", + "null" + ] + }, + "url": { + "type": [ + "string", + "null" + ] + }, + "emoji_name_alias": { + "type": "array", + "items": { + "type": "string" + } + }, + "ani_sticker_width": { + "type": [ + "integer", + "null" + ] + }, + "ani_sticker_height": { + "type": [ + "integer", + "null" + ] + }, + "is_super": { + "type": "boolean", + "description": "是否使用超级表情格式" + } + }, + "required": [ + "q_sid", + "q_des", + "em_code", + "q_cid", + "ani_sticker_type", + "ani_sticker_pack_id", + "ani_sticker_id", + "url", + "emoji_name_alias", + "ani_sticker_width", + "ani_sticker_height", + "is_super" + ] + }, + { + "type": "null" + } + ] + }, + "readOnly": true, + "params": [ + { + "name": "face_id", + "type": "int", + "required": true, + "schema": { + "type": "integer", + "minimum": 0 + }, + "role": "face_id", + "desc": "QQ 系统表情编号" + }, + { + "name": "refresh", + "type": "bool", + "required": false, + "schema": { + "type": "boolean" + }, + "default": false, + "desc": "是否强制从 QQ 刷新目录" + } + ], + "invariants": [], + "inputSchema": { + "type": "object", + "properties": { + "face_id": { + "type": "integer", + "minimum": 0, + "description": "QQ 系统表情编号", + "x-role": "face_id" + }, + "refresh": { + "type": "boolean", + "description": "是否强制从 QQ 刷新目录", + "default": false + } + }, + "required": [ + "face_id" + ], + "additionalProperties": true + }, + "category": "系统表情" + }, { "name": "fetch_ptt_text", "aliases": [ @@ -2080,6 +2221,209 @@ export const ACTIONS: CatalogAction[] = [ }, "category": "扩展" }, + { + "name": "fetch_super_face_id", + "aliases": [], + "summary": "判断 QQ 系统表情是否使用超级表情格式", + "returns": "是否使用超级表情格式。", + "returnsSchema": { + "type": "object", + "properties": { + "is_super": { + "type": "boolean" + } + }, + "required": [ + "is_super" + ] + }, + "readOnly": true, + "params": [ + { + "name": "face_id", + "type": "int", + "required": true, + "schema": { + "type": "integer", + "minimum": 0 + }, + "role": "face_id", + "desc": "QQ 系统表情编号" + }, + { + "name": "refresh", + "type": "bool", + "required": false, + "schema": { + "type": "boolean" + }, + "default": false, + "desc": "是否强制从 QQ 刷新目录" + } + ], + "invariants": [], + "inputSchema": { + "type": "object", + "properties": { + "face_id": { + "type": "integer", + "minimum": 0, + "description": "QQ 系统表情编号", + "x-role": "face_id" + }, + "refresh": { + "type": "boolean", + "description": "是否强制从 QQ 刷新目录", + "default": false + } + }, + "required": [ + "face_id" + ], + "additionalProperties": true + }, + "category": "系统表情" + }, + { + "name": "fetch_sys_faces", + "aliases": [], + "summary": "获取 QQ 系统表情目录", + "returns": "按分组返回完整的 QQ 系统表情映射。", + "returnsSchema": { + "type": "object", + "properties": { + "packs": { + "type": "array", + "items": { + "type": "object", + "properties": { + "pack_name": { + "type": "string" + }, + "emojis": { + "type": "array", + "items": { + "type": "object", + "properties": { + "q_sid": { + "type": "string", + "description": "表情编号" + }, + "q_des": { + "type": "string", + "description": "表情描述" + }, + "em_code": { + "type": "string" + }, + "q_cid": { + "type": [ + "integer", + "null" + ] + }, + "ani_sticker_type": { + "type": [ + "integer", + "null" + ] + }, + "ani_sticker_pack_id": { + "type": [ + "integer", + "null" + ] + }, + "ani_sticker_id": { + "type": [ + "integer", + "null" + ] + }, + "url": { + "type": [ + "string", + "null" + ] + }, + "emoji_name_alias": { + "type": "array", + "items": { + "type": "string" + } + }, + "ani_sticker_width": { + "type": [ + "integer", + "null" + ] + }, + "ani_sticker_height": { + "type": [ + "integer", + "null" + ] + }, + "is_super": { + "type": "boolean", + "description": "是否使用超级表情格式" + } + }, + "required": [ + "q_sid", + "q_des", + "em_code", + "q_cid", + "ani_sticker_type", + "ani_sticker_pack_id", + "ani_sticker_id", + "url", + "emoji_name_alias", + "ani_sticker_width", + "ani_sticker_height", + "is_super" + ] + } + } + }, + "required": [ + "pack_name", + "emojis" + ] + } + } + }, + "required": [ + "packs" + ] + }, + "readOnly": true, + "params": [ + { + "name": "refresh", + "type": "bool", + "required": false, + "schema": { + "type": "boolean" + }, + "default": false, + "desc": "是否强制从 QQ 刷新目录" + } + ], + "invariants": [], + "inputSchema": { + "type": "object", + "properties": { + "refresh": { + "type": "boolean", + "description": "是否强制从 QQ 刷新目录", + "default": false + } + }, + "additionalProperties": true + }, + "category": "系统表情" + }, { "name": "forward_friend_single_msg", "aliases": [], @@ -7376,6 +7720,134 @@ export const ACTIONS: CatalogAction[] = [ }, "category": "扩展" }, + { + "name": "search_sys_faces", + "aliases": [], + "summary": "搜索 QQ 系统表情", + "returns": "匹配编号、名称、别名或分组名的表情列表。", + "returnsSchema": { + "type": "object", + "properties": { + "faces": { + "type": "array", + "items": { + "type": "object", + "properties": { + "q_sid": { + "type": "string", + "description": "表情编号" + }, + "q_des": { + "type": "string", + "description": "表情描述" + }, + "em_code": { + "type": "string" + }, + "q_cid": { + "type": [ + "integer", + "null" + ] + }, + "ani_sticker_type": { + "type": [ + "integer", + "null" + ] + }, + "ani_sticker_pack_id": { + "type": [ + "integer", + "null" + ] + }, + "ani_sticker_id": { + "type": [ + "integer", + "null" + ] + }, + "url": { + "type": [ + "string", + "null" + ] + }, + "emoji_name_alias": { + "type": "array", + "items": { + "type": "string" + } + }, + "ani_sticker_width": { + "type": [ + "integer", + "null" + ] + }, + "ani_sticker_height": { + "type": [ + "integer", + "null" + ] + }, + "is_super": { + "type": "boolean", + "description": "是否使用超级表情格式" + } + }, + "required": [ + "q_sid", + "q_des", + "em_code", + "q_cid", + "ani_sticker_type", + "ani_sticker_pack_id", + "ani_sticker_id", + "url", + "emoji_name_alias", + "ani_sticker_width", + "ani_sticker_height", + "is_super" + ] + } + } + }, + "required": [ + "faces" + ] + }, + "readOnly": true, + "params": [ + { + "name": "query", + "type": "string", + "required": true, + "schema": { + "type": "string", + "minLength": 1 + }, + "desc": "编号、名称、别名或分组名" + } + ], + "invariants": [], + "inputSchema": { + "type": "object", + "properties": { + "query": { + "type": "string", + "minLength": 1, + "description": "编号、名称、别名或分组名" + } + }, + "required": [ + "query" + ], + "additionalProperties": true + }, + "category": "系统表情" + }, { "name": "send_ark_share", "aliases": [], @@ -11053,6 +11525,10 @@ export const CATEGORIES: CatalogCategory[] = [ "category": "空间", "count": 9 }, + { + "category": "系统表情", + "count": 4 + }, { "category": "流式接口", "count": 6 diff --git a/packages/onebot/src/actions/index.ts b/packages/onebot/src/actions/index.ts index 3a79035f..ef74f9a6 100644 --- a/packages/onebot/src/actions/index.ts +++ b/packages/onebot/src/actions/index.ts @@ -20,6 +20,7 @@ import { actions as groupAlbumActions } from './group-album'; import { actions as qzoneActions } from './qzone'; import { actions as streamFileActions } from './stream-file'; import { actions as streamDownloadActions } from './stream-download'; +import { actions as systemFaceActions } from './system-face'; export interface ActionGroup { /** Domain category (= source file), surfaced to the MCP / UI for grouping. */ @@ -196,6 +197,7 @@ export const ACTION_GROUPS: readonly ActionGroup[] = [ { category: '扩展', actions: extendedActions }, { category: '群相册', actions: groupAlbumActions }, { category: '空间', actions: qzoneActions }, + { category: '系统表情', actions: systemFaceActions }, { category: '流式接口', actions: [...streamFileActions, ...streamDownloadActions] }, ]; diff --git a/packages/onebot/src/actions/system-face.ts b/packages/onebot/src/actions/system-face.ts new file mode 100644 index 00000000..67e7d900 --- /dev/null +++ b/packages/onebot/src/actions/system-face.ts @@ -0,0 +1,137 @@ +import { isSuperFaceEntry } from '@snowluma/protocol/oidb-services/sys-faces/fetch-sys-faces'; +import type { SysFaceEntry } from '@snowluma/protocol/sys-face-store'; +import { defineAction, f } from '../action-kit'; +import { okResponse, type JsonObject } from '../types'; + +function faceEntry(face: SysFaceEntry): JsonObject { + return { + q_sid: face.qSid, + q_des: face.qDes, + em_code: face.emCode, + q_cid: face.qCid, + ani_sticker_type: face.aniStickerType, + ani_sticker_pack_id: face.aniStickerPackId, + ani_sticker_id: face.aniStickerId, + url: face.url, + emoji_name_alias: face.emojiNameAlias, + ani_sticker_width: face.aniStickerWidth, + ani_sticker_height: face.aniStickerHeight, + is_super: isSuperFaceEntry(face), + }; +} + +const refreshField = () => f.bool().default(false).describe('是否强制从 QQ 刷新目录'); +const faceIdField = () => f.faceId().describe('QQ 系统表情编号'); +const nullableInteger = { type: ['integer', 'null'] }; +const nullableString = { type: ['string', 'null'] }; +const faceSchema = { + type: 'object', + properties: { + q_sid: { type: 'string', description: '表情编号' }, + q_des: { type: 'string', description: '表情描述' }, + em_code: { type: 'string' }, + q_cid: nullableInteger, + ani_sticker_type: nullableInteger, + ani_sticker_pack_id: nullableInteger, + ani_sticker_id: nullableInteger, + url: nullableString, + emoji_name_alias: { type: 'array', items: { type: 'string' } }, + ani_sticker_width: nullableInteger, + ani_sticker_height: nullableInteger, + is_super: { type: 'boolean', description: '是否使用超级表情格式' }, + }, + required: [ + 'q_sid', 'q_des', 'em_code', 'q_cid', 'ani_sticker_type', + 'ani_sticker_pack_id', 'ani_sticker_id', 'url', 'emoji_name_alias', + 'ani_sticker_width', 'ani_sticker_height', 'is_super', + ], +}; + +export const actions = [ + defineAction({ + name: 'fetch_sys_faces', + summary: '获取 QQ 系统表情目录', + readOnly: true, + returns: '按分组返回完整的 QQ 系统表情映射。', + returnsSchema: { + type: 'object', + properties: { + packs: { + type: 'array', + items: { + type: 'object', + properties: { + pack_name: { type: 'string' }, + emojis: { type: 'array', items: faceSchema }, + }, + required: ['pack_name', 'emojis'], + }, + }, + }, + required: ['packs'], + }, + params: { refresh: refreshField() }, + run: async (params, ctx) => { + const packs = await ctx.bridge.apis.systemFace.fetchCatalog(params.refresh); + return okResponse({ + packs: packs.map((pack) => ({ + pack_name: pack.packName, + emojis: pack.emojis.map(faceEntry), + })), + }); + }, + }), + + defineAction({ + name: 'fetch_face_entity', + summary: '按编号查询 QQ 系统表情', + readOnly: true, + returns: '表情详情;编号不存在时返回 null。', + returnsSchema: { anyOf: [faceSchema, { type: 'null' }] }, + params: { + face_id: faceIdField(), + refresh: refreshField(), + }, + run: async (params, ctx) => { + const face = await ctx.bridge.apis.systemFace.fetchFace(params.face_id, params.refresh); + return okResponse(face ? faceEntry(face) : null); + }, + }), + + defineAction({ + name: 'search_sys_faces', + summary: '搜索 QQ 系统表情', + readOnly: true, + returns: '匹配编号、名称、别名或分组名的表情列表。', + returnsSchema: { + type: 'object', + properties: { faces: { type: 'array', items: faceSchema } }, + required: ['faces'], + }, + params: { + query: f.string({ allowEmpty: false }).describe('编号、名称、别名或分组名'), + }, + run: async (params, ctx) => okResponse({ + faces: (await ctx.bridge.apis.systemFace.search(params.query)).map(faceEntry), + }), + }), + + defineAction({ + name: 'fetch_super_face_id', + summary: '判断 QQ 系统表情是否使用超级表情格式', + readOnly: true, + returns: '是否使用超级表情格式。', + returnsSchema: { + type: 'object', + properties: { is_super: { type: 'boolean' } }, + required: ['is_super'], + }, + params: { + face_id: faceIdField(), + refresh: refreshField(), + }, + run: async (params, ctx) => okResponse({ + is_super: await ctx.bridge.apis.systemFace.isSuper(params.face_id, params.refresh), + }), + }), +]; diff --git a/packages/onebot/tests/action-registry.test.ts b/packages/onebot/tests/action-registry.test.ts index c0b2a026..045ac1ca 100644 --- a/packages/onebot/tests/action-registry.test.ts +++ b/packages/onebot/tests/action-registry.test.ts @@ -90,9 +90,9 @@ describe('compileActionRegistry namespace conflicts', () => { }); describe('compiled production Action registry', () => { - it('preserves all 181 canonical Action docs', () => { - expect(ACTION_REGISTRY.actions).toHaveLength(181); - expect(collectActionDocs()).toHaveLength(181); + it('preserves all 185 canonical Action docs', () => { + expect(ACTION_REGISTRY.actions).toHaveLength(185); + expect(collectActionDocs()).toHaveLength(185); }); it('resolves every executable name to exactly one canonical doc', () => { diff --git a/packages/onebot/tests/system-face-actions.test.ts b/packages/onebot/tests/system-face-actions.test.ts new file mode 100644 index 00000000..69191540 --- /dev/null +++ b/packages/onebot/tests/system-face-actions.test.ts @@ -0,0 +1,65 @@ +import { describe, expect, it, vi } from 'vitest'; +import type { BridgeInterface } from '@snowluma/core/bridge-interface'; +import { ApiHandler, type ApiActionContext } from '../src/api-handler'; + +const FACE = { + qSid: '392', qDes: '/龙年快乐', emCode: '10392', qCid: 392, + aniStickerType: 3, aniStickerPackId: 1, aniStickerId: 38, + url: 'https://example.invalid/392', emojiNameAlias: ['dragon'], + aniStickerWidth: 200, aniStickerHeight: 200, +}; + +function handler(systemFace: Record): ApiHandler { + const bridge = { apis: { systemFace } } as unknown as BridgeInterface; + return new ApiHandler({ bridge } as ApiActionContext); +} + +describe('system face actions', () => { + it('returns the full pack mapping and supports an explicit server refresh', async () => { + const fetchCatalog = vi.fn(async () => [{ packName: '超级表情', emojis: [FACE] }]); + const response = await handler({ fetchCatalog }).handle('fetch_sys_faces', { refresh: true }); + + expect(fetchCatalog).toHaveBeenCalledWith(true); + expect(response).toMatchObject({ + status: 'ok', + data: { + packs: [{ + pack_name: '超级表情', + emojis: [{ q_sid: '392', q_des: '/龙年快乐', is_super: true }], + }], + }, + }); + }); + + it('looks up one id without redownloading a fresh catalog', async () => { + const fetchFace = vi.fn(async () => FACE); + const response = await handler({ fetchFace }).handle('fetch_face_entity', { face_id: '392' }); + + expect(fetchFace).toHaveBeenCalledWith(392, false); + expect(response).toMatchObject({ status: 'ok', data: { q_sid: '392', q_des: '/龙年快乐' } }); + }); + + it('accepts face id 0', async () => { + const fetchFace = vi.fn(async () => ({ ...FACE, qSid: '0', qDes: '/惊讶' })); + const response = await handler({ fetchFace }).handle('fetch_face_entity', { face_id: 0 }); + + expect(fetchFace).toHaveBeenCalledWith(0, false); + expect(response).toMatchObject({ status: 'ok', data: { q_sid: '0', q_des: '/惊讶' } }); + }); + + it('searches descriptions and aliases through the shared local catalog', async () => { + const search = vi.fn(async () => [FACE]); + const response = await handler({ search }).handle('search_sys_faces', { query: 'dragon' }); + + expect(search).toHaveBeenCalledWith('dragon'); + expect(response).toMatchObject({ status: 'ok', data: { faces: [{ q_sid: '392' }] } }); + }); + + it('reports whether an id uses the super-face wire shape', async () => { + const isSuper = vi.fn(async () => true); + const response = await handler({ isSuper }).handle('fetch_super_face_id', { face_id: 392 }); + + expect(isSuper).toHaveBeenCalledWith(392, false); + expect(response).toMatchObject({ status: 'ok', data: { is_super: true } }); + }); +}); diff --git a/packages/sdk/src/client/api-client.ts b/packages/sdk/src/client/api-client.ts index 4a8d3a1f..55655e82 100644 --- a/packages/sdk/src/client/api-client.ts +++ b/packages/sdk/src/client/api-client.ts @@ -409,6 +409,28 @@ export abstract class SnowLumaApiClient { return this.call('set_msg_emoji_like', { message_id: messageId, emoji_id: emojiId, set }, options); } + fetchSysFaces(refresh = false, options?: RequestOptions) { + return this.call('fetch_sys_faces', { refresh }, options); + } + + fetchFaceEntity(faceId: number, options: RequestOptions & { refresh?: boolean } = {}) { + return this.call('fetch_face_entity', { + face_id: faceId, + refresh: options.refresh ?? false, + }, options); + } + + searchSysFaces(query: string, options?: RequestOptions) { + return this.call('search_sys_faces', { query }, options); + } + + fetchSuperFaceId(faceId: number, options: RequestOptions & { refresh?: boolean } = {}) { + return this.call('fetch_super_face_id', { + face_id: faceId, + refresh: options.refresh ?? false, + }, options); + } + markAllAsRead(options?: RequestOptions) { return this.call('_mark_all_as_read', {}, options); } diff --git a/packages/sdk/src/types/actions.ts b/packages/sdk/src/types/actions.ts index 9c27db03..683a85c6 100644 --- a/packages/sdk/src/types/actions.ts +++ b/packages/sdk/src/types/actions.ts @@ -7,6 +7,8 @@ import type { DomainParams, DownloadFileParams, FetchCustomFaceParams, + FetchFaceEntityParams, + FetchSysFacesParams, FetchEmojiLikeParams, ForwardMessageParams, FriendPokeParams, @@ -70,6 +72,7 @@ import type { AiVoiceParams, DeleteGroupFolderParams, SendPacketParams, + SearchSysFacesParams, } from './params'; import type { CapabilityInfo, @@ -100,6 +103,10 @@ import type { UserOnlineStatus, SendGroupAiRecordResult, CollectionListInfo, + SuperFaceInfo, + SystemFaceCatalogInfo, + SystemFaceInfo, + SystemFaceSearchInfo, } from './results'; export type ActionData = JsonValue; @@ -200,6 +207,10 @@ export interface SnowLumaActionMap { get_recent_contact: { params: JsonObject; data: JsonArray }; get_profile_like: { params: JsonObject; data: JsonObject }; fetch_custom_face: { params: FetchCustomFaceParams; data: string[] }; + fetch_sys_faces: { params: FetchSysFacesParams; data: SystemFaceCatalogInfo }; + fetch_face_entity: { params: FetchFaceEntityParams; data: SystemFaceInfo | null }; + search_sys_faces: { params: SearchSysFacesParams; data: SystemFaceSearchInfo }; + fetch_super_face_id: { params: FetchFaceEntityParams; data: SuperFaceInfo }; get_emoji_likes: { params: GetEmojiLikesParams; data: JsonObject }; fetch_emoji_like: { params: FetchEmojiLikeParams; data: JsonObject }; get_friends_with_category: { params: JsonObject; data: FriendCategoryResult[] }; diff --git a/packages/sdk/src/types/params.ts b/packages/sdk/src/types/params.ts index cfea50f7..693ea1a2 100644 --- a/packages/sdk/src/types/params.ts +++ b/packages/sdk/src/types/params.ts @@ -302,6 +302,18 @@ export interface FetchCustomFaceParams extends JsonObject { count?: number; } +export interface FetchSysFacesParams extends JsonObject { + refresh?: boolean; +} + +export interface FetchFaceEntityParams extends FetchSysFacesParams { + face_id: number; +} + +export interface SearchSysFacesParams extends JsonObject { + query: string; +} + export interface GetCollectionListParams extends JsonObject { /** Collection category ID; 0 returns every category. */ category?: number; diff --git a/packages/sdk/src/types/results.ts b/packages/sdk/src/types/results.ts index 5fdfa31c..f8c7b553 100644 --- a/packages/sdk/src/types/results.ts +++ b/packages/sdk/src/types/results.ts @@ -175,6 +175,38 @@ export interface CollectionListInfo extends JsonObject { collectionSearchList: CollectionSearchListInfo; } +export interface SystemFaceInfo extends JsonObject { + q_sid: string; + q_des: string; + em_code: string; + q_cid: number | null; + ani_sticker_type: number | null; + ani_sticker_pack_id: number | null; + ani_sticker_id: number | null; + url: string | null; + emoji_name_alias: string[]; + ani_sticker_width: number | null; + ani_sticker_height: number | null; + is_super: boolean; +} + +export interface SystemFacePackInfo extends JsonObject { + pack_name: string; + emojis: SystemFaceInfo[]; +} + +export interface SystemFaceCatalogInfo extends JsonObject { + packs: SystemFacePackInfo[]; +} + +export interface SystemFaceSearchInfo extends JsonObject { + faces: SystemFaceInfo[]; +} + +export interface SuperFaceInfo extends JsonObject { + is_super: boolean; +} + export interface UrlSafetyInfo { level: number; } diff --git a/packages/sdk/tests/http-client.test.ts b/packages/sdk/tests/http-client.test.ts index 0a9f24c6..db4df6a3 100644 --- a/packages/sdk/tests/http-client.test.ts +++ b/packages/sdk/tests/http-client.test.ts @@ -7,6 +7,27 @@ import { } from '../src'; describe('SnowLumaHttpClient', () => { + it('maps system-face catalog helpers to their OneBot actions', async () => { + const fetchImpl = vi.fn().mockImplementation(async () => new Response(JSON.stringify({ + status: 'ok', + retcode: 0, + data: null, + }))); + const client = new SnowLumaHttpClient({ fetch: fetchImpl }); + + await client.fetchSysFaces(true); + await client.fetchFaceEntity(392, { refresh: true }); + await client.searchSysFaces('dragon'); + await client.fetchSuperFaceId(392); + + expect(fetchImpl.mock.calls.map((call) => JSON.parse((call[1] as RequestInit).body as string))).toEqual([ + { action: 'fetch_sys_faces', params: { refresh: true } }, + { action: 'fetch_face_entity', params: { face_id: 392, refresh: true } }, + { action: 'search_sys_faces', params: { query: 'dragon' } }, + { action: 'fetch_super_face_id', params: { face_id: 392, refresh: false } }, + ]); + }); + it('maps group-announcement options to their OneBot field names', async () => { const fetchImpl = vi.fn().mockResolvedValue(new Response(JSON.stringify({ status: 'ok',