This commit is contained in:
idranme 2024-08-15 10:31:51 +08:00
parent 3f4b0b44cf
commit d143dc043c
No known key found for this signature in database
GPG Key ID: 926F7B5B668E495F
5 changed files with 14 additions and 10 deletions

View File

@ -52,7 +52,7 @@ export class ConfigUtil {
autoDeleteFile: false,
autoDeleteFileSecond: 60,
musicSignUrl: '',
msgCacheExpire: 8000
msgCacheExpire: 120
}
if (!fs.existsSync(this.configPath)) {

View File

@ -134,9 +134,12 @@ export function getSelfUin() {
const messages: Map<string, RawMessage> = new Map()
let expire: number
/** 缓存已撤回消息内容 */
export function addMsgCache(msg: RawMessage) {
expire ??= getConfigUtil().getConfig().msgCacheExpire!
/** 缓存近期消息内容 */
export async function addMsgCache(msg: RawMessage) {
expire ??= getConfigUtil().getConfig().msgCacheExpire! * 1000
if (expire === 0) {
return
}
const id = msg.msgId
messages.set(id, msg)
setTimeout(() => {
@ -144,7 +147,7 @@ export function addMsgCache(msg: RawMessage) {
}, expire)
}
/** 获取已撤回消息内容 */
/** 获取近期消息内容 */
export function getMsgCache(msgId: string) {
return messages.get(msgId)
}

View File

@ -30,6 +30,7 @@ export interface Config {
ffmpeg?: string // ffmpeg路径
musicSignUrl?: string
ignoreBeforeLoginMsg?: boolean
/** 单位为秒 */
msgCacheExpire?: number
}

View File

@ -96,7 +96,7 @@ function onLoad() {
}
ipcMain.handle(CHANNEL_ERROR, async (event, arg) => {
const ffmpegOk = await checkFfmpeg(getConfigUtil().getConfig().ffmpeg)
llonebotError.ffmpegError = ffmpegOk ? '' : '没有找到ffmpeg,音频只能发送wav和silk,视频尺寸可能异常'
llonebotError.ffmpegError = ffmpegOk ? '' : '没有找到 FFmpeg, 音频只能发送 WAV 和 SILK, 视频尺寸可能异常'
let { httpServerError, wsServerError, otherError, ffmpegError } = llonebotError
let error = `${otherError}\n${httpServerError}\n${wsServerError}\n${ffmpegError}`
error = error.replace('\n\n', '\n')
@ -160,6 +160,7 @@ function onLoad() {
peerUid: message.peerUid
}
message.msgShortId = MessageUnique.createMsg(peer, message.msgId)
addMsgCache(message)
OB11Constructor.message(message)
.then((msg) => {
@ -184,7 +185,7 @@ function onLoad() {
}
})
OB11Constructor.PrivateEvent(message).then((privateEvent) => {
log(message)
//log(message)
if (privateEvent) {
// log("post private event", privateEvent);
postOb11Event(privateEvent)
@ -223,7 +224,6 @@ function onLoad() {
if (!oriMessageId) {
continue
}
addMsgCache(message)
OB11Constructor.RecallEvent(message, oriMessageId).then((recallEvent) => {
if (recallEvent) {
//log('post recall event', recallEvent)

View File

@ -220,8 +220,8 @@ async function onSettingWindowCreated(view: Element) {
SettingButton('打开', 'config-open-log-path'),
),
SettingItem(
'已撤回消息内容缓存时长',
'单位为秒',
'消息内容缓存时长',
'单位为秒',
`<div class="q-input"><input class="q-input__inner" data-config-key="msgCacheExpire" type="number" min="1" value="${config.msgCacheExpire}" placeholder="${config.msgCacheExpire}" /></div>`,
),
]),