From 1f02c98c8f30cfb135231e6e78ff7773d2f134bd Mon Sep 17 00:00:00 2001
From: idranme <96647698+idranme@users.noreply.github.com>
Date: Thu, 14 Nov 2024 15:24:46 +0800
Subject: [PATCH] chore

---
 src/ntqqapi/hook.ts                       |  5 +-
 src/ntqqapi/native/crychic/index.ts       |  2 +-
 src/onebot11/action/system/CleanCache.ts  | 78 ++++++++++-------------
 src/onebot11/helper/createMultiMessage.ts |  2 +-
 src/satori/adapter.ts                     |  2 +-
 5 files changed, 40 insertions(+), 49 deletions(-)

diff --git a/src/ntqqapi/hook.ts b/src/ntqqapi/hook.ts
index 177e250..eb36206 100644
--- a/src/ntqqapi/hook.ts
+++ b/src/ntqqapi/hook.ts
@@ -2,6 +2,7 @@ import { NTMethod } from './ntcall'
 import { log } from '@/common/utils'
 import { randomUUID } from 'node:crypto'
 import { ipcMain } from 'electron'
+import { Dict } from 'cosmokit'
 
 export const hookApiCallbacks: Record<string, (res: any) => void> = {}
 
@@ -45,7 +46,7 @@ export function startHook() {
   const senderExclude = Symbol()
 
   ipcMain.emit = new Proxy(ipcMain.emit, {
-    apply(target, thisArg, args: [eventName: string, ...args: any]) {
+    apply(target, thisArg, args: [channel: string, ...args: any]) {
       if (args[2]?.eventName?.startsWith('ns-LoggerApi')) {
         return target.apply(thisArg, args)
       }
@@ -56,7 +57,7 @@ export function startHook() {
       if (event.sender && !event.sender[senderExclude]) {
         event.sender[senderExclude] = true
         event.sender.send = new Proxy(event.sender.send, {
-          apply(target, thisArg, args: any[]) {
+          apply(target, thisArg, args: [channel: string, meta: Dict, data: Dict[]]) {
             if (args[1].eventName?.startsWith('ns-LoggerApi')) {
               return target.apply(thisArg, args)
             }
diff --git a/src/ntqqapi/native/crychic/index.ts b/src/ntqqapi/native/crychic/index.ts
index aa8670d..8271008 100644
--- a/src/ntqqapi/native/crychic/index.ts
+++ b/src/ntqqapi/native/crychic/index.ts
@@ -11,7 +11,7 @@ export class Native {
   public activated = false
   private crychic?: Dict
   private seq = 0
-  private cb: Map<number, Function> = new Map()
+  private cb: Map<number, (res: any) => void> = new Map()
 
   constructor(private ctx: Context) {
     ctx.on('ready', () => {
diff --git a/src/onebot11/action/system/CleanCache.ts b/src/onebot11/action/system/CleanCache.ts
index 081ec17..88acfea 100644
--- a/src/onebot11/action/system/CleanCache.ts
+++ b/src/onebot11/action/system/CleanCache.ts
@@ -7,62 +7,52 @@ import { ChatCacheListItemBasic, CacheFileType } from '@/ntqqapi/types'
 export default class CleanCache extends BaseAction<void, void> {
   actionName = ActionName.CleanCache
 
-  protected _handle(): Promise<void> {
-    return new Promise<void>(async (res, rej) => {
-      try {
-        // dbUtil.clearCache()
-        const cacheFilePaths: string[] = []
+  protected async _handle(): Promise<void> {
+    const cacheFilePaths: string[] = []
 
-        await this.ctx.ntFileCacheApi.setCacheSilentScan(false)
+    await this.ctx.ntFileCacheApi.setCacheSilentScan(false)
 
-        cacheFilePaths.push(await this.ctx.ntFileCacheApi.getHotUpdateCachePath())
-        cacheFilePaths.push(await this.ctx.ntFileCacheApi.getDesktopTmpPath())
+    cacheFilePaths.push(await this.ctx.ntFileCacheApi.getHotUpdateCachePath())
+    cacheFilePaths.push(await this.ctx.ntFileCacheApi.getDesktopTmpPath())
 
-        const list = await this.ctx.ntFileCacheApi.getCacheSessionPathList()
-        list.forEach((e) => cacheFilePaths.push(e.value))
+    const list = await this.ctx.ntFileCacheApi.getCacheSessionPathList()
+    list.forEach((e) => cacheFilePaths.push(e.value))
 
-        // await NTQQApi.addCacheScannedPaths(); // XXX: 调用就崩溃,原因目前还未知
-        const cacheScanResult = await this.ctx.ntFileCacheApi.scanCache()
-        const cacheSize = parseInt(cacheScanResult.size[6])
+    // await NTQQApi.addCacheScannedPaths(); // XXX: 调用就崩溃,原因目前还未知
+    const cacheScanResult = await this.ctx.ntFileCacheApi.scanCache()
+    const cacheSize = parseInt(cacheScanResult.size[6])
 
-        if (cacheScanResult.result !== 0) {
-          throw 'Something went wrong while scanning cache. Code: ' + cacheScanResult.result
-        }
+    if (cacheScanResult.result !== 0) {
+      throw 'Something went wrong while scanning cache. Code: ' + cacheScanResult.result
+    }
 
-        await this.ctx.ntFileCacheApi.setCacheSilentScan(true)
-        if (cacheSize > 0 && cacheFilePaths.length > 2) {
-          // 存在缓存文件且大小不为 0 时执行清理动作
-          // await NTQQApi.clearCache([ 'tmp', 'hotUpdate', ...cacheScanResult ]) // XXX: 也是调用就崩溃,调用 fs 删除得了
-          deleteCachePath(cacheFilePaths)
-        }
+    await this.ctx.ntFileCacheApi.setCacheSilentScan(true)
+    if (cacheSize > 0 && cacheFilePaths.length > 2) {
+      // 存在缓存文件且大小不为 0 时执行清理动作
+      // await NTQQApi.clearCache([ 'tmp', 'hotUpdate', ...cacheScanResult ]) // XXX: 也是调用就崩溃,调用 fs 删除得了
+      deleteCachePath(cacheFilePaths)
+    }
 
-        // 获取聊天记录列表
-        // NOTE: 以防有人不需要删除聊天记录,暂时先注释掉,日后加个开关
-        // const privateChatCache = await getCacheList(ChatType.friend); // 私聊消息
-        // const groupChatCache = await getCacheList(ChatType.group); // 群聊消息
-        // const chatCacheList = [ ...privateChatCache, ...groupChatCache ];
-        const chatCacheList: ChatCacheListItemBasic[] = []
+    // 获取聊天记录列表
+    // NOTE: 以防有人不需要删除聊天记录,暂时先注释掉,日后加个开关
+    // const privateChatCache = await getCacheList(ChatType.friend); // 私聊消息
+    // const groupChatCache = await getCacheList(ChatType.group); // 群聊消息
+    // const chatCacheList = [ ...privateChatCache, ...groupChatCache ];
+    const chatCacheList: ChatCacheListItemBasic[] = []
 
-        // 获取聊天缓存文件列表
-        const cacheFileList: string[] = []
+    // 获取聊天缓存文件列表
+    const cacheFileList: string[] = []
 
-        for (const name in CacheFileType) {
-          if (!isNaN(parseInt(name))) continue
+    for (const name in CacheFileType) {
+      if (!isNaN(parseInt(name))) continue
 
-          const fileTypeAny: any = CacheFileType[name]
-          const fileType: CacheFileType = fileTypeAny
+      const fileType = CacheFileType[name] as unknown as CacheFileType
 
-          cacheFileList.push(...(await this.ctx.ntFileCacheApi.getFileCacheInfo(fileType)).infos.map((file) => file.fileKey))
-        }
+      cacheFileList.push(...(await this.ctx.ntFileCacheApi.getFileCacheInfo(fileType)).infos.map((file) => file.fileKey))
+    }
 
-        // 一并清除
-        await this.ctx.ntFileCacheApi.clearChatCache(chatCacheList, cacheFileList)
-        res()
-      } catch (e) {
-        console.error('清理缓存时发生了错误')
-        rej(e)
-      }
-    })
+    // 一并清除
+    await this.ctx.ntFileCacheApi.clearChatCache(chatCacheList, cacheFileList)
   }
 }
 
diff --git a/src/onebot11/helper/createMultiMessage.ts b/src/onebot11/helper/createMultiMessage.ts
index 9c3a044..2dc8e25 100644
--- a/src/onebot11/helper/createMultiMessage.ts
+++ b/src/onebot11/helper/createMultiMessage.ts
@@ -221,7 +221,7 @@ export class MessageEncoder {
     }
   }
 
-  async generate(content: any[]) {
+  async generate(content: OB11MessageData[]) {
     await this.render(content)
     return {
       multiMsgItems: [{
diff --git a/src/satori/adapter.ts b/src/satori/adapter.ts
index 8d8a710..46cf884 100644
--- a/src/satori/adapter.ts
+++ b/src/satori/adapter.ts
@@ -91,7 +91,7 @@ class SatoriAdapter extends Service {
       input.subMsgType === 12 &&
       input.elements[0]?.grayTipElement?.xmlElement?.templId === '10382'
     ) {
-
+      // 机器人被表情回应
     }
     else {
       // 普通的消息