Skip to content

Commit

Permalink
feat(api): implement chronocat.internal.qface.get/list
Browse files Browse the repository at this point in the history
  • Loading branch information
ilharp committed Mar 7, 2024
1 parent 2f41a2c commit 32f24c5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
31 changes: 31 additions & 0 deletions packages/engine-chronocat-api/src/api/internal/qface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { QFace } from '@chronocat/red'
import { readFile } from 'node:fs/promises'
import { getEmojiResourcePath } from '../../definitions/msgService'

let task: Promise<void> | 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!
}
4 changes: 4 additions & 0 deletions packages/engine-chronocat-api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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)
}

0 comments on commit 32f24c5

Please sign in to comment.