mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
opt
This commit is contained in:
parent
128f40a51d
commit
2b0179acd1
@ -27,33 +27,12 @@ class DBUtil {
|
||||
* */
|
||||
|
||||
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}`
|
||||
|
||||
init(uin: string) {
|
||||
const DB_PATH = DATA_DIR + `/msg_${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()
|
||||
|
||||
const expiredMilliSecond = 1000 * 60 * 60
|
||||
|
||||
setInterval(() => {
|
||||
// this.cache = {}
|
||||
// 清理时间较久的缓存
|
||||
|
@ -25,7 +25,7 @@ export function checkFileReceived(path: string, timeout: number = 3000): Promise
|
||||
} else if (Date.now() - startTime > timeout) {
|
||||
reject(new Error(`文件不存在: ${path}`))
|
||||
} else {
|
||||
setTimeout(check, 100)
|
||||
setTimeout(check, 200)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,12 +45,12 @@ import { GroupDecreaseSubType, OB11GroupDecreaseEvent } from '../onebot11/event/
|
||||
import '../ntqqapi/wrapper'
|
||||
import { NTEventDispatch } from '../common/utils/EventTask'
|
||||
import { wrapperConstructor, getSession } from '../ntqqapi/wrapper'
|
||||
import { sleep } from '../common/utils/helper'
|
||||
|
||||
let mainWindow: BrowserWindow | null = null
|
||||
|
||||
// 加载插件时触发
|
||||
function onLoad() {
|
||||
log('llonebot main onLoad')
|
||||
ipcMain.handle(CHANNEL_CHECK_VERSION, async (event, arg) => {
|
||||
return checkNewVersion()
|
||||
})
|
||||
@ -428,6 +428,7 @@ function onLoad() {
|
||||
}
|
||||
llonebotError.otherError = ''
|
||||
startTime = Date.now()
|
||||
dbUtil.init(selfInfo.uin)
|
||||
NTEventDispatch.init({ ListenerMap: wrapperConstructor, WrapperSession: getSession()! })
|
||||
log('start activate group member info')
|
||||
NTQQGroupApi.activateMemberInfoChange().then().catch(log)
|
||||
@ -452,21 +453,12 @@ function onLoad() {
|
||||
|
||||
let getSelfNickCount = 0
|
||||
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) {
|
||||
selfInfo.uin = globalThis.authData?.uin
|
||||
selfInfo.uid = globalThis.authData?.uid
|
||||
selfInfo.nick = selfInfo.uin
|
||||
}
|
||||
log('self info', selfInfo, globalThis.authData)
|
||||
//log('self info', selfInfo, globalThis.authData)
|
||||
if (selfInfo.uin) {
|
||||
async function getUserNick() {
|
||||
try {
|
||||
@ -481,18 +473,19 @@ function onLoad() {
|
||||
log('get self nickname failed', e.stack)
|
||||
}
|
||||
if (getSelfNickCount < 10) {
|
||||
return setTimeout(getUserNick, 1000)
|
||||
await sleep(1000)
|
||||
return await getUserNick()
|
||||
}
|
||||
}
|
||||
|
||||
getUserNick().then()
|
||||
start().then()
|
||||
await getUserNick()
|
||||
start()
|
||||
}
|
||||
else {
|
||||
setTimeout(init, 1000)
|
||||
}
|
||||
}
|
||||
setTimeout(init, 1000)
|
||||
init()
|
||||
}
|
||||
|
||||
// 创建窗口时触发
|
||||
|
@ -175,7 +175,6 @@ export class SendMsgElementConstructor {
|
||||
|
||||
setTimeout(useDefaultThumb, 5000)
|
||||
ffmpeg(filePath)
|
||||
.on('end', () => { })
|
||||
.on('error', (err) => {
|
||||
if (diyThumbPath) {
|
||||
fs.copyFile(diyThumbPath, thumbPath)
|
||||
|
@ -242,18 +242,7 @@ async function updateGroups(_groups: Group[], needUpdate: boolean = true) {
|
||||
continue
|
||||
}
|
||||
log('update group', group)
|
||||
// if (!activatedGroups.includes(group.groupCode)) {
|
||||
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)
|
||||
// }
|
||||
NTQQMsgApi.activateChat({ peerUid: group.groupCode, chatType: ChatType.group }).then().catch(log)
|
||||
let existGroup = groups.find((g) => g.groupCode == group.groupCode)
|
||||
if (existGroup) {
|
||||
Object.assign(existGroup, group)
|
||||
|
Loading…
x
Reference in New Issue
Block a user