Merge branch 'dev'

This commit is contained in:
linyuchen 2024-11-14 19:58:27 +08:00
commit 9e03071629
13 changed files with 62 additions and 67 deletions

View File

@ -36,9 +36,6 @@ import {
} from '../ntqqapi/api' } from '../ntqqapi/api'
import { existsSync, mkdirSync } from 'node:fs' import { existsSync, mkdirSync } from 'node:fs'
import { initWrapperSession} from '@/ntqqapi/native/napcat-protocol-packet'
initWrapperSession().then()
declare module 'cordis' { declare module 'cordis' {
interface Events { interface Events {
'llob/config-updated': (input: LLOBConfig) => void 'llob/config-updated': (input: LLOBConfig) => void
@ -231,6 +228,9 @@ function onLoad() {
// 创建窗口时触发 // 创建窗口时触发
function onBrowserWindowCreated(window: BrowserWindow) { function onBrowserWindowCreated(window: BrowserWindow) {
if (window.id === 2) {
mainWindow = window
}
} }
try { try {

View File

@ -41,12 +41,14 @@ class Core extends Service {
static inject = ['ntMsgApi', 'ntFriendApi', 'ntGroupApi', 'store'] static inject = ['ntMsgApi', 'ntFriendApi', 'ntGroupApi', 'store']
public startTime = 0 public startTime = 0
public native public native
public ntqqPacketApi: NTQQPacketApi public packet!: NTQQPacketApi
constructor(protected ctx: Context, public config: Core.Config) { constructor(protected ctx: Context, public config: Core.Config) {
super(ctx, 'app', true) super(ctx, 'app', true)
this.native = new Native(ctx) this.native = new Native(ctx)
initWrapperSession().then(session=>{this.ntqqPacketApi = new NTQQPacketApi(session)}) initWrapperSession().then(session => {
this.packet = new NTQQPacketApi(session)
})
} }
public start() { public start() {

View File

@ -2,6 +2,7 @@ import { NTMethod } from './ntcall'
import { log } from '@/common/utils' import { log } from '@/common/utils'
import { randomUUID } from 'node:crypto' import { randomUUID } from 'node:crypto'
import { ipcMain } from 'electron' import { ipcMain } from 'electron'
import { Dict } from 'cosmokit'
export const hookApiCallbacks: Record<string, (res: any) => void> = {} export const hookApiCallbacks: Record<string, (res: any) => void> = {}
@ -45,8 +46,8 @@ export function startHook() {
const senderExclude = Symbol() const senderExclude = Symbol()
ipcMain.emit = new Proxy(ipcMain.emit, { 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')) { if (args[2]?.eventName?.startsWith('ns-LoggerApi')) {
return target.apply(thisArg, args) return target.apply(thisArg, args)
} }
if (logHook) { if (logHook) {
@ -56,7 +57,7 @@ export function startHook() {
if (event.sender && !event.sender[senderExclude]) { if (event.sender && !event.sender[senderExclude]) {
event.sender[senderExclude] = true event.sender[senderExclude] = true
event.sender.send = new Proxy(event.sender.send, { 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')) { if (args[1].eventName?.startsWith('ns-LoggerApi')) {
return target.apply(thisArg, args) return target.apply(thisArg, args)
} }

View File

@ -11,7 +11,7 @@ export class Native {
public activated = false public activated = false
private crychic?: Dict private crychic?: Dict
private seq = 0 private seq = 0
private cb: Map<number, Function> = new Map() private cb: Map<number, (res: any) => void> = new Map()
constructor(private ctx: Context) { constructor(private ctx: Context) {
ctx.on('ready', () => { ctx.on('ready', () => {

View File

@ -442,6 +442,7 @@ export interface RawMessage {
attrType: number attrType: number
attrId: string attrId: string
}> }>
isOnlineMsg: boolean
} }
export interface Peer { export interface Peer {

View File

@ -1,6 +1,5 @@
import { BaseAction, Schema } from '../BaseAction' import { BaseAction, Schema } from '../BaseAction'
import { ActionName } from '../types' import { ActionName } from '../types'
import { getBuildVersion } from '@/common/utils/misc'
import { selfInfo } from '@/common/globalVars' import { selfInfo } from '@/common/globalVars'
interface Payload { interface Payload {
@ -14,7 +13,7 @@ export class SendGroupSign extends BaseAction<Payload, null> {
}) })
async _handle(payload: Payload) { 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 return null
} }
} }

View File

@ -1,6 +1,5 @@
import { BaseAction, Schema } from '../BaseAction' import { BaseAction, Schema } from '../BaseAction'
import { ActionName } from '../types' import { ActionName } from '../types'
import { getBuildVersion } from '@/common/utils/misc'
import { selfInfo } from '@/common/globalVars' import { selfInfo } from '@/common/globalVars'
import { GroupMemberRole } from '@/ntqqapi/types' import { GroupMemberRole } from '@/ntqqapi/types'
@ -25,7 +24,7 @@ export class SetGroupSpecialTitle extends BaseAction<Payload, null> {
if (self.role !== GroupMemberRole.Owner){ if (self.role !== GroupMemberRole.Owner){
throw new Error(`不是群${payload.group_id}的群主,无法设置群头衔`) 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 return null
} }
} }

View File

@ -1,6 +1,5 @@
import { BaseAction, Schema } from '../BaseAction' import { BaseAction, Schema } from '../BaseAction'
import { ActionName } from '../types' import { ActionName } from '../types'
import { getBuildVersion } from '@/common/utils/misc'
interface Payload { interface Payload {
user_id: number | string user_id: number | string
@ -21,7 +20,7 @@ export class FriendPoke extends BaseAction<Payload, null> {
// } // }
// await this.ctx.app.native.sendFriendPoke(+payload.user_id) // 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 return null
} }
} }

View File

@ -1,7 +1,5 @@
import { BaseAction, Schema } from '../BaseAction' import { BaseAction, Schema } from '../BaseAction'
import { ActionName } from '../types' import { ActionName } from '../types'
import { getBuildVersion } from '@/common/utils/misc'
import {NTQQPacketApi} from '@/ntqqapi/native/napcat-protocol-packet'
interface Payload { interface Payload {
group_id: number | string group_id: number | string
@ -23,7 +21,7 @@ export class GroupPoke extends BaseAction<Payload, null> {
// throw new Error(`当前 QQ 版本 ${getBuildVersion()} 不支持,可尝试其他版本 27333—27597`) // throw new Error(`当前 QQ 版本 ${getBuildVersion()} 不支持,可尝试其他版本 27333—27597`)
// } // }
// await this.ctx.app.native.sendGroupPoke(+payload.group_id, +payload.user_id) // 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 return null
} }
} }

View File

@ -7,62 +7,52 @@ import { ChatCacheListItemBasic, CacheFileType } from '@/ntqqapi/types'
export default class CleanCache extends BaseAction<void, void> { export default class CleanCache extends BaseAction<void, void> {
actionName = ActionName.CleanCache actionName = ActionName.CleanCache
protected _handle(): Promise<void> { protected async _handle(): Promise<void> {
return new Promise<void>(async (res, rej) => { const cacheFilePaths: string[] = []
try {
// dbUtil.clearCache()
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.getHotUpdateCachePath())
cacheFilePaths.push(await this.ctx.ntFileCacheApi.getDesktopTmpPath()) cacheFilePaths.push(await this.ctx.ntFileCacheApi.getDesktopTmpPath())
const list = await this.ctx.ntFileCacheApi.getCacheSessionPathList() const list = await this.ctx.ntFileCacheApi.getCacheSessionPathList()
list.forEach((e) => cacheFilePaths.push(e.value)) list.forEach((e) => cacheFilePaths.push(e.value))
// await NTQQApi.addCacheScannedPaths(); // XXX: 调用就崩溃,原因目前还未知 // await NTQQApi.addCacheScannedPaths(); // XXX: 调用就崩溃,原因目前还未知
const cacheScanResult = await this.ctx.ntFileCacheApi.scanCache() const cacheScanResult = await this.ctx.ntFileCacheApi.scanCache()
const cacheSize = parseInt(cacheScanResult.size[6]) const cacheSize = parseInt(cacheScanResult.size[6])
if (cacheScanResult.result !== 0) { if (cacheScanResult.result !== 0) {
throw 'Something went wrong while scanning cache. Code: ' + cacheScanResult.result throw 'Something went wrong while scanning cache. Code: ' + cacheScanResult.result
} }
await this.ctx.ntFileCacheApi.setCacheSilentScan(true) await this.ctx.ntFileCacheApi.setCacheSilentScan(true)
if (cacheSize > 0 && cacheFilePaths.length > 2) { if (cacheSize > 0 && cacheFilePaths.length > 2) {
// 存在缓存文件且大小不为 0 时执行清理动作 // 存在缓存文件且大小不为 0 时执行清理动作
// await NTQQApi.clearCache([ 'tmp', 'hotUpdate', ...cacheScanResult ]) // XXX: 也是调用就崩溃,调用 fs 删除得了 // await NTQQApi.clearCache([ 'tmp', 'hotUpdate', ...cacheScanResult ]) // XXX: 也是调用就崩溃,调用 fs 删除得了
deleteCachePath(cacheFilePaths) deleteCachePath(cacheFilePaths)
} }
// 获取聊天记录列表 // 获取聊天记录列表
// NOTE: 以防有人不需要删除聊天记录,暂时先注释掉,日后加个开关 // NOTE: 以防有人不需要删除聊天记录,暂时先注释掉,日后加个开关
// const privateChatCache = await getCacheList(ChatType.friend); // 私聊消息 // const privateChatCache = await getCacheList(ChatType.friend); // 私聊消息
// const groupChatCache = await getCacheList(ChatType.group); // 群聊消息 // const groupChatCache = await getCacheList(ChatType.group); // 群聊消息
// const chatCacheList = [ ...privateChatCache, ...groupChatCache ]; // const chatCacheList = [ ...privateChatCache, ...groupChatCache ];
const chatCacheList: ChatCacheListItemBasic[] = [] const chatCacheList: ChatCacheListItemBasic[] = []
// 获取聊天缓存文件列表 // 获取聊天缓存文件列表
const cacheFileList: string[] = [] const cacheFileList: string[] = []
for (const name in CacheFileType) { for (const name in CacheFileType) {
if (!isNaN(parseInt(name))) continue if (!isNaN(parseInt(name))) continue
const fileTypeAny: any = CacheFileType[name] const fileType = CacheFileType[name] as unknown as CacheFileType
const fileType: CacheFileType = fileTypeAny
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) await this.ctx.ntFileCacheApi.clearChatCache(chatCacheList, cacheFileList)
res()
} catch (e) {
console.error('清理缓存时发生了错误')
rej(e)
}
})
} }
} }

View File

@ -221,7 +221,7 @@ export class MessageEncoder {
} }
} }
async generate(content: any[]) { async generate(content: OB11MessageData[]) {
await this.render(content) await this.render(content)
return { return {
multiMsgItems: [{ multiMsgItems: [{

View File

@ -11,6 +11,10 @@ function isEmpty(value: unknown) {
} }
async function onSettingWindowCreated(view: Element) { async function onSettingWindowCreated(view: Element) {
console.log(view)
if (!view){
return
}
const config = await window.llonebot.getConfig() const config = await window.llonebot.getConfig()
const ob11Config = { ...config.ob11 } const ob11Config = { ...config.ob11 }
@ -247,7 +251,9 @@ async function onSettingWindowCreated(view: Element) {
} else { } else {
errDom?.classList.add('show') errDom?.classList.add('show')
} }
errCodeDom!.innerHTML = errMsg if (errCodeDom) {
errCodeDom.innerHTML = errMsg
}
} }
showError().then() showError().then()
@ -456,8 +462,8 @@ async function onSettingWindowCreated(view: Element) {
} }
window.llonebot.checkVersion().then(checkVersionFunc) window.llonebot.checkVersion().then(checkVersionFunc)
window.addEventListener('beforeunload', () => { window.addEventListener('beforeunload', () => {
window.llonebot.getConfig().then(oldConfig=>{ window.llonebot.getConfig().then(oldConfig => {
if(JSON.stringify(oldConfig) !== JSON.stringify(config)){ if (JSON.stringify(oldConfig) !== JSON.stringify(config)) {
window.llonebot.setConfig(true, config) window.llonebot.setConfig(true, config)
} }
}) })

View File

@ -91,7 +91,7 @@ class SatoriAdapter extends Service {
input.subMsgType === 12 && input.subMsgType === 12 &&
input.elements[0]?.grayTipElement?.xmlElement?.templId === '10382' input.elements[0]?.grayTipElement?.xmlElement?.templId === '10382'
) { ) {
// 机器人被表情回应
} }
else { else {
// 普通的消息 // 普通的消息