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, autoDeleteFile: false,
autoDeleteFileSecond: 60, autoDeleteFileSecond: 60,
musicSignUrl: '', musicSignUrl: '',
msgCacheExpire: 8000 msgCacheExpire: 120
} }
if (!fs.existsSync(this.configPath)) { if (!fs.existsSync(this.configPath)) {

View File

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

View File

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

View File

@ -96,7 +96,7 @@ function onLoad() {
} }
ipcMain.handle(CHANNEL_ERROR, async (event, arg) => { ipcMain.handle(CHANNEL_ERROR, async (event, arg) => {
const ffmpegOk = await checkFfmpeg(getConfigUtil().getConfig().ffmpeg) 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 { httpServerError, wsServerError, otherError, ffmpegError } = llonebotError
let error = `${otherError}\n${httpServerError}\n${wsServerError}\n${ffmpegError}` let error = `${otherError}\n${httpServerError}\n${wsServerError}\n${ffmpegError}`
error = error.replace('\n\n', '\n') error = error.replace('\n\n', '\n')
@ -160,6 +160,7 @@ function onLoad() {
peerUid: message.peerUid peerUid: message.peerUid
} }
message.msgShortId = MessageUnique.createMsg(peer, message.msgId) message.msgShortId = MessageUnique.createMsg(peer, message.msgId)
addMsgCache(message)
OB11Constructor.message(message) OB11Constructor.message(message)
.then((msg) => { .then((msg) => {
@ -184,7 +185,7 @@ function onLoad() {
} }
}) })
OB11Constructor.PrivateEvent(message).then((privateEvent) => { OB11Constructor.PrivateEvent(message).then((privateEvent) => {
log(message) //log(message)
if (privateEvent) { if (privateEvent) {
// log("post private event", privateEvent); // log("post private event", privateEvent);
postOb11Event(privateEvent) postOb11Event(privateEvent)
@ -223,7 +224,6 @@ function onLoad() {
if (!oriMessageId) { if (!oriMessageId) {
continue continue
} }
addMsgCache(message)
OB11Constructor.RecallEvent(message, oriMessageId).then((recallEvent) => { OB11Constructor.RecallEvent(message, oriMessageId).then((recallEvent) => {
if (recallEvent) { if (recallEvent) {
//log('post recall event', recallEvent) //log('post recall event', recallEvent)

View File

@ -220,8 +220,8 @@ async function onSettingWindowCreated(view: Element) {
SettingButton('打开', 'config-open-log-path'), SettingButton('打开', 'config-open-log-path'),
), ),
SettingItem( 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>`, `<div class="q-input"><input class="q-input__inner" data-config-key="msgCacheExpire" type="number" min="1" value="${config.msgCacheExpire}" placeholder="${config.msgCacheExpire}" /></div>`,
), ),
]), ]),