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'
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 {

View File

@ -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() {

View File

@ -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,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)
}

View File

@ -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', () => {

View File

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

View File

@ -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<Payload, null> {
})
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
}
}

View File

@ -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<Payload, null> {
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
}
}

View File

@ -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<Payload, null> {
// }
// 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
}
}

View File

@ -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<Payload, null> {
// 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
}
}

View File

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

View File

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

View File

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

View File

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