diff --git a/packages/engine-chronocat-api/src/api/internal/qface.ts b/packages/engine-chronocat-api/src/api/internal/qface.ts new file mode 100644 index 0000000..c851dce --- /dev/null +++ b/packages/engine-chronocat-api/src/api/internal/qface.ts @@ -0,0 +1,31 @@ +import type { QFace } from '@chronocat/red' +import { readFile } from 'node:fs/promises' +import { getEmojiResourcePath } from '../../definitions/msgService' + +let task: Promise | undefined = undefined +let qfaces: QFace[] | undefined = undefined + +const init = async () => { + const { resourcePath } = await getEmojiResourcePath({ + type: 0, + }) + qfaces = ( + JSON.parse((await readFile(resourcePath)).toString('utf-8')) as { + sysface: QFace[] + } + ).sysface +} + +export const qfaceGet = async (sid: string) => { + if (!task) task = init() + await task + + return qfaces!.find((x) => sid === x.QSid) +} + +export const qfaceList = async () => { + if (!task) task = init() + await task + + return qfaces! +} diff --git a/packages/engine-chronocat-api/src/index.ts b/packages/engine-chronocat-api/src/index.ts index a529dc3..8b04acc 100644 --- a/packages/engine-chronocat-api/src/index.ts +++ b/packages/engine-chronocat-api/src/index.ts @@ -2,6 +2,7 @@ import type { RedIpcArgs } from '@chronocat/red' import type { ChronocatContext } from '@chronocat/shell' import { ipcMan } from 'ipcman' import { buildAssetsGet } from './api/internal/assets/get' +import { qfaceGet, qfaceList } from './api/internal/qface' import { buildMessageCreate } from './api/message/create' import { buildHandler } from './handler' @@ -22,4 +23,7 @@ export const apply = async (ctx: ChronocatContext) => { register('chronocat.internal.message.create.forward', buildMessageCreate(ctx)) await ctx.chronocat.whenReady() + + register('chronocat.internal.qface.get', qfaceGet) + register('chronocat.internal.qface.list', qfaceList) }