diff --git a/src/main/main.ts b/src/main/main.ts index 2c2339d..e2e751d 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -36,9 +36,6 @@ import { } from '../ntqqapi/api' import { existsSync, mkdirSync } from 'node:fs' -import { initWrapperSession} from '@/ntqqapi/native/napcat-protocol-packet' -initWrapperSession().then() - declare module 'cordis' { interface Events { 'llob/config-updated': (input: LLOBConfig) => void @@ -231,6 +228,9 @@ function onLoad() { // 创建窗口时触发 function onBrowserWindowCreated(window: BrowserWindow) { + if (window.id === 2) { + mainWindow = window + } } try { diff --git a/src/ntqqapi/core.ts b/src/ntqqapi/core.ts index ce866c8..47a48b4 100644 --- a/src/ntqqapi/core.ts +++ b/src/ntqqapi/core.ts @@ -41,12 +41,14 @@ class Core extends Service { static inject = ['ntMsgApi', 'ntFriendApi', 'ntGroupApi', 'store'] public startTime = 0 public native - public ntqqPacketApi: NTQQPacketApi + public packet!: NTQQPacketApi constructor(protected ctx: Context, public config: Core.Config) { super(ctx, 'app', true) this.native = new Native(ctx) - initWrapperSession().then(session=>{this.ntqqPacketApi = new NTQQPacketApi(session)}) + initWrapperSession().then(session => { + this.packet = new NTQQPacketApi(session) + }) } public start() { diff --git a/src/ntqqapi/hook.ts b/src/ntqqapi/hook.ts index 66fe858..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 void> = {} @@ -45,8 +46,8 @@ export function startHook() { const senderExclude = Symbol() ipcMain.emit = new Proxy(ipcMain.emit, { - apply(target, thisArg, args: [eventName: string, ...args: any]) { - if (args[2]?.eventName.startsWith('ns-LoggerApi')) { + apply(target, thisArg, args: [channel: string, ...args: any]) { + if (args[2]?.eventName?.startsWith('ns-LoggerApi')) { return target.apply(thisArg, args) } if (logHook) { @@ -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 = new Map() + private cb: Map void> = new Map() constructor(private ctx: Context) { ctx.on('ready', () => { diff --git a/src/ntqqapi/types/msg.ts b/src/ntqqapi/types/msg.ts index d01f4e7..4c85aa5 100644 --- a/src/ntqqapi/types/msg.ts +++ b/src/ntqqapi/types/msg.ts @@ -442,6 +442,7 @@ export interface RawMessage { attrType: number attrId: string }> + isOnlineMsg: boolean } export interface Peer { diff --git a/src/onebot11/action/go-cqhttp/SendGroupSign.ts b/src/onebot11/action/go-cqhttp/SendGroupSign.ts index c80b693..484fd54 100644 --- a/src/onebot11/action/go-cqhttp/SendGroupSign.ts +++ b/src/onebot11/action/go-cqhttp/SendGroupSign.ts @@ -1,6 +1,5 @@ import { BaseAction, Schema } from '../BaseAction' import { ActionName } from '../types' -import { getBuildVersion } from '@/common/utils/misc' import { selfInfo } from '@/common/globalVars' interface Payload { @@ -14,7 +13,7 @@ export class SendGroupSign extends BaseAction { }) async _handle(payload: Payload) { - await this.ctx.app.ntqqPacketApi.sendGroupSignPacket(selfInfo.uin, payload.group_id.toString()) + await this.ctx.app.packet.sendGroupSignPacket(selfInfo.uin, payload.group_id.toString()) return null } } diff --git a/src/onebot11/action/go-cqhttp/SetGroupSpecialTitle.ts b/src/onebot11/action/go-cqhttp/SetGroupSpecialTitle.ts index 0344939..b588e3f 100644 --- a/src/onebot11/action/go-cqhttp/SetGroupSpecialTitle.ts +++ b/src/onebot11/action/go-cqhttp/SetGroupSpecialTitle.ts @@ -1,6 +1,5 @@ import { BaseAction, Schema } from '../BaseAction' import { ActionName } from '../types' -import { getBuildVersion } from '@/common/utils/misc' import { selfInfo } from '@/common/globalVars' import { GroupMemberRole } from '@/ntqqapi/types' @@ -25,7 +24,7 @@ export class SetGroupSpecialTitle extends BaseAction { if (self.role !== GroupMemberRole.Owner){ throw new Error(`不是群${payload.group_id}的群主,无法设置群头衔`) } - await this.ctx.app.ntqqPacketApi.sendSetSpecialTittlePacket(payload.group_id.toString(), uid, payload.special_title || "") + await this.ctx.app.packet.sendSetSpecialTittlePacket(payload.group_id.toString(), uid, payload.special_title || "") return null } } diff --git a/src/onebot11/action/llonebot/FriendPoke.ts b/src/onebot11/action/llonebot/FriendPoke.ts index 3b2f7b2..1cf4fcb 100644 --- a/src/onebot11/action/llonebot/FriendPoke.ts +++ b/src/onebot11/action/llonebot/FriendPoke.ts @@ -1,6 +1,5 @@ import { BaseAction, Schema } from '../BaseAction' import { ActionName } from '../types' -import { getBuildVersion } from '@/common/utils/misc' interface Payload { user_id: number | string @@ -21,7 +20,7 @@ export class FriendPoke extends BaseAction { // } // await this.ctx.app.native.sendFriendPoke(+payload.user_id) - await this.ctx.app.ntqqPacketApi.sendPokePacket(+payload.user_id) + await this.ctx.app.packet.sendPokePacket(+payload.user_id) return null } } diff --git a/src/onebot11/action/llonebot/GroupPoke.ts b/src/onebot11/action/llonebot/GroupPoke.ts index 1025378..25a2ccb 100644 --- a/src/onebot11/action/llonebot/GroupPoke.ts +++ b/src/onebot11/action/llonebot/GroupPoke.ts @@ -1,7 +1,5 @@ import { BaseAction, Schema } from '../BaseAction' import { ActionName } from '../types' -import { getBuildVersion } from '@/common/utils/misc' -import {NTQQPacketApi} from '@/ntqqapi/native/napcat-protocol-packet' interface Payload { group_id: number | string @@ -23,7 +21,7 @@ export class GroupPoke extends BaseAction { // throw new Error(`当前 QQ 版本 ${getBuildVersion()} 不支持,可尝试其他版本 27333—27597`) // } // await this.ctx.app.native.sendGroupPoke(+payload.group_id, +payload.user_id) - await this.ctx.app.ntqqPacketApi.sendPokePacket(+payload.user_id, +payload.group_id) + await this.ctx.app.packet.sendPokePacket(+payload.user_id, +payload.group_id) return null } } 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 { actionName = ActionName.CleanCache - protected _handle(): Promise { - return new Promise(async (res, rej) => { - try { - // dbUtil.clearCache() - const cacheFilePaths: string[] = [] + protected async _handle(): Promise { + 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/renderer/index.ts b/src/renderer/index.ts index 8b3eb06..fab55d1 100644 --- a/src/renderer/index.ts +++ b/src/renderer/index.ts @@ -11,6 +11,10 @@ function isEmpty(value: unknown) { } async function onSettingWindowCreated(view: Element) { + console.log(view) + if (!view){ + return + } const config = await window.llonebot.getConfig() const ob11Config = { ...config.ob11 } @@ -247,7 +251,9 @@ async function onSettingWindowCreated(view: Element) { } else { errDom?.classList.add('show') } - errCodeDom!.innerHTML = errMsg + if (errCodeDom) { + errCodeDom.innerHTML = errMsg + } } showError().then() @@ -456,8 +462,8 @@ async function onSettingWindowCreated(view: Element) { } window.llonebot.checkVersion().then(checkVersionFunc) window.addEventListener('beforeunload', () => { - window.llonebot.getConfig().then(oldConfig=>{ - if(JSON.stringify(oldConfig) !== JSON.stringify(config)){ + window.llonebot.getConfig().then(oldConfig => { + if (JSON.stringify(oldConfig) !== JSON.stringify(config)) { window.llonebot.setConfig(true, config) } }) 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 { // 普通的消息