This commit is contained in:
idranme 2024-08-11 18:10:27 +08:00
parent 128f40a51d
commit 2b0179acd1
No known key found for this signature in database
GPG Key ID: 926F7B5B668E495F
5 changed files with 14 additions and 54 deletions

View File

@ -27,33 +27,12 @@ class DBUtil {
* */ * */
constructor() { constructor() {
let initCount = 0 }
new Promise((resolve, reject) => {
const initDB = () => {
initCount++
// if (initCount > 50) {
// return reject("init db fail")
// }
try {
if (!selfInfo.uin) {
setTimeout(initDB, 300)
return
}
const DB_PATH = DATA_DIR + `/msg_${selfInfo.uin}`
this.db = new Level(DB_PATH, { valueEncoding: 'json' })
console.log('llonebot init db success')
resolve(null)
} catch (e: any) {
console.log('init db fail', e.stack.toString())
setTimeout(initDB, 300)
}
}
setTimeout(initDB)
}).then()
init(uin: string) {
const DB_PATH = DATA_DIR + `/msg_${uin}`
this.db = new Level(DB_PATH, { valueEncoding: 'json' })
const expiredMilliSecond = 1000 * 60 * 60 const expiredMilliSecond = 1000 * 60 * 60
setInterval(() => { setInterval(() => {
// this.cache = {} // this.cache = {}
// 清理时间较久的缓存 // 清理时间较久的缓存

View File

@ -25,7 +25,7 @@ export function checkFileReceived(path: string, timeout: number = 3000): Promise
} else if (Date.now() - startTime > timeout) { } else if (Date.now() - startTime > timeout) {
reject(new Error(`文件不存在: ${path}`)) reject(new Error(`文件不存在: ${path}`))
} else { } else {
setTimeout(check, 100) setTimeout(check, 200)
} }
} }

View File

@ -45,12 +45,12 @@ import { GroupDecreaseSubType, OB11GroupDecreaseEvent } from '../onebot11/event/
import '../ntqqapi/wrapper' import '../ntqqapi/wrapper'
import { NTEventDispatch } from '../common/utils/EventTask' import { NTEventDispatch } from '../common/utils/EventTask'
import { wrapperConstructor, getSession } from '../ntqqapi/wrapper' import { wrapperConstructor, getSession } from '../ntqqapi/wrapper'
import { sleep } from '../common/utils/helper'
let mainWindow: BrowserWindow | null = null let mainWindow: BrowserWindow | null = null
// 加载插件时触发 // 加载插件时触发
function onLoad() { function onLoad() {
log('llonebot main onLoad')
ipcMain.handle(CHANNEL_CHECK_VERSION, async (event, arg) => { ipcMain.handle(CHANNEL_CHECK_VERSION, async (event, arg) => {
return checkNewVersion() return checkNewVersion()
}) })
@ -428,6 +428,7 @@ function onLoad() {
} }
llonebotError.otherError = '' llonebotError.otherError = ''
startTime = Date.now() startTime = Date.now()
dbUtil.init(selfInfo.uin)
NTEventDispatch.init({ ListenerMap: wrapperConstructor, WrapperSession: getSession()! }) NTEventDispatch.init({ ListenerMap: wrapperConstructor, WrapperSession: getSession()! })
log('start activate group member info') log('start activate group member info')
NTQQGroupApi.activateMemberInfoChange().then().catch(log) NTQQGroupApi.activateMemberInfoChange().then().catch(log)
@ -452,21 +453,12 @@ function onLoad() {
let getSelfNickCount = 0 let getSelfNickCount = 0
const init = async () => { const init = async () => {
try {
log('start get self info')
const _ = await NTQQUserApi.getSelfInfo()
log('get self info api result:', _)
Object.assign(selfInfo, _)
selfInfo.nick = selfInfo.uin
} catch (e) {
log('retry get self info', e)
}
if (!selfInfo.uin) { if (!selfInfo.uin) {
selfInfo.uin = globalThis.authData?.uin selfInfo.uin = globalThis.authData?.uin
selfInfo.uid = globalThis.authData?.uid selfInfo.uid = globalThis.authData?.uid
selfInfo.nick = selfInfo.uin selfInfo.nick = selfInfo.uin
} }
log('self info', selfInfo, globalThis.authData) //log('self info', selfInfo, globalThis.authData)
if (selfInfo.uin) { if (selfInfo.uin) {
async function getUserNick() { async function getUserNick() {
try { try {
@ -481,18 +473,19 @@ function onLoad() {
log('get self nickname failed', e.stack) log('get self nickname failed', e.stack)
} }
if (getSelfNickCount < 10) { if (getSelfNickCount < 10) {
return setTimeout(getUserNick, 1000) await sleep(1000)
return await getUserNick()
} }
} }
getUserNick().then() await getUserNick()
start().then() start()
} }
else { else {
setTimeout(init, 1000) setTimeout(init, 1000)
} }
} }
setTimeout(init, 1000) init()
} }
// 创建窗口时触发 // 创建窗口时触发

View File

@ -175,7 +175,6 @@ export class SendMsgElementConstructor {
setTimeout(useDefaultThumb, 5000) setTimeout(useDefaultThumb, 5000)
ffmpeg(filePath) ffmpeg(filePath)
.on('end', () => { })
.on('error', (err) => { .on('error', (err) => {
if (diyThumbPath) { if (diyThumbPath) {
fs.copyFile(diyThumbPath, thumbPath) fs.copyFile(diyThumbPath, thumbPath)

View File

@ -242,18 +242,7 @@ async function updateGroups(_groups: Group[], needUpdate: boolean = true) {
continue continue
} }
log('update group', group) log('update group', group)
// if (!activatedGroups.includes(group.groupCode)) { NTQQMsgApi.activateChat({ peerUid: group.groupCode, chatType: ChatType.group }).then().catch(log)
NTQQMsgApi.activateChat({ peerUid: group.groupCode, chatType: ChatType.group })
.then((r) => {
// activatedGroups.push(group.groupCode);
// log(`激活群聊天窗口${group.groupName}(${group.groupCode})`, r)
// if (r.result !== 0) {
// setTimeout(() => NTQQMsgApi.activateGroupChat(group.groupCode).then(r => log(`再次激活群聊天窗口${group.groupName}(${group.groupCode})`, r)), 500);
// }else {
// }
})
.catch(log)
// }
let existGroup = groups.find((g) => g.groupCode == group.groupCode) let existGroup = groups.find((g) => g.groupCode == group.groupCode)
if (existGroup) { if (existGroup) {
Object.assign(existGroup, group) Object.assign(existGroup, group)