mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
feat: cache recalled message content
This commit is contained in:
parent
c1d7aa7aed
commit
3f4b0b44cf
@ -52,6 +52,7 @@ export class ConfigUtil {
|
|||||||
autoDeleteFile: false,
|
autoDeleteFile: false,
|
||||||
autoDeleteFileSecond: 60,
|
autoDeleteFileSecond: 60,
|
||||||
musicSignUrl: '',
|
musicSignUrl: '',
|
||||||
|
msgCacheExpire: 8000
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fs.existsSync(this.configPath)) {
|
if (!fs.existsSync(this.configPath)) {
|
||||||
|
@ -9,6 +9,8 @@ import { NTQQGroupApi } from '../ntqqapi/api/group'
|
|||||||
import { log } from './utils/log'
|
import { log } from './utils/log'
|
||||||
import { isNumeric } from './utils/helper'
|
import { isNumeric } from './utils/helper'
|
||||||
import { NTQQFriendApi, NTQQUserApi } from '../ntqqapi/api'
|
import { NTQQFriendApi, NTQQUserApi } from '../ntqqapi/api'
|
||||||
|
import { RawMessage } from '../ntqqapi/types'
|
||||||
|
import { getConfigUtil } from './config'
|
||||||
|
|
||||||
export let groups: Group[] = []
|
export let groups: Group[] = []
|
||||||
export let friends: Friend[] = []
|
export let friends: Friend[] = []
|
||||||
@ -128,3 +130,21 @@ export function getSelfUid() {
|
|||||||
export function getSelfUin() {
|
export function getSelfUin() {
|
||||||
return selfInfo['uin']
|
return selfInfo['uin']
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const messages: Map<string, RawMessage> = new Map()
|
||||||
|
let expire: number
|
||||||
|
|
||||||
|
/** 缓存已撤回消息内容 */
|
||||||
|
export function addMsgCache(msg: RawMessage) {
|
||||||
|
expire ??= getConfigUtil().getConfig().msgCacheExpire!
|
||||||
|
const id = msg.msgId
|
||||||
|
messages.set(id, msg)
|
||||||
|
setTimeout(() => {
|
||||||
|
messages.delete(id)
|
||||||
|
}, expire)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 获取已撤回消息内容 */
|
||||||
|
export function getMsgCache(msgId: string) {
|
||||||
|
return messages.get(msgId)
|
||||||
|
}
|
@ -30,6 +30,7 @@ export interface Config {
|
|||||||
ffmpeg?: string // ffmpeg路径
|
ffmpeg?: string // ffmpeg路径
|
||||||
musicSignUrl?: string
|
musicSignUrl?: string
|
||||||
ignoreBeforeLoginMsg?: boolean
|
ignoreBeforeLoginMsg?: boolean
|
||||||
|
msgCacheExpire?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface LLOneBotError {
|
export interface LLOneBotError {
|
||||||
|
@ -21,7 +21,8 @@ import {
|
|||||||
setSelfInfo,
|
setSelfInfo,
|
||||||
getSelfInfo,
|
getSelfInfo,
|
||||||
getSelfUid,
|
getSelfUid,
|
||||||
getSelfUin
|
getSelfUin,
|
||||||
|
addMsgCache
|
||||||
} from '../common/data'
|
} from '../common/data'
|
||||||
import { hookNTQQApiCall, hookNTQQApiReceive, ReceiveCmdS, registerReceiveHook, startHook } from '../ntqqapi/hook'
|
import { hookNTQQApiCall, hookNTQQApiReceive, ReceiveCmdS, registerReceiveHook, startHook } from '../ntqqapi/hook'
|
||||||
import { OB11Constructor } from '../onebot11/constructor'
|
import { OB11Constructor } from '../onebot11/constructor'
|
||||||
@ -222,6 +223,7 @@ 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)
|
||||||
|
@ -4,6 +4,7 @@ import BaseAction from '../BaseAction'
|
|||||||
import { ActionName } from '../types'
|
import { ActionName } from '../types'
|
||||||
import { NTQQMsgApi } from '@/ntqqapi/api'
|
import { NTQQMsgApi } from '@/ntqqapi/api'
|
||||||
import { MessageUnique } from '@/common/utils/MessageUnique'
|
import { MessageUnique } from '@/common/utils/MessageUnique'
|
||||||
|
import { getMsgCache } from '@/common/data'
|
||||||
|
|
||||||
export interface PayloadType {
|
export interface PayloadType {
|
||||||
message_id: number | string
|
message_id: number | string
|
||||||
@ -29,12 +30,9 @@ class GetMsg extends BaseAction<PayloadType, OB11Message> {
|
|||||||
peerUid: msgIdWithPeer.Peer.peerUid,
|
peerUid: msgIdWithPeer.Peer.peerUid,
|
||||||
chatType: msgIdWithPeer.Peer.chatType
|
chatType: msgIdWithPeer.Peer.chatType
|
||||||
}
|
}
|
||||||
const msg = await NTQQMsgApi.getMsgsByMsgId(
|
const msg = getMsgCache(msgIdWithPeer.MsgId) ?? (await NTQQMsgApi.getMsgsByMsgId(peer, [msgIdWithPeer.MsgId])).msgList[0]
|
||||||
peer,
|
const retMsg = await OB11Constructor.message(msg)
|
||||||
[msgIdWithPeer?.MsgId || payload.message_id.toString()]
|
retMsg.message_id = MessageUnique.createMsg(peer, msg.msgId)!
|
||||||
)
|
|
||||||
const retMsg = await OB11Constructor.message(msg.msgList[0])
|
|
||||||
retMsg.message_id = MessageUnique.createMsg(peer, msg.msgList[0].msgId)!
|
|
||||||
retMsg.message_seq = retMsg.message_id
|
retMsg.message_seq = retMsg.message_id
|
||||||
retMsg.real_id = retMsg.message_id
|
retMsg.real_id = retMsg.message_id
|
||||||
return retMsg
|
return retMsg
|
||||||
|
@ -119,9 +119,8 @@ export async function createSendElements(
|
|||||||
if (!peer) {
|
if (!peer) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
let atQQ = sendMsg.data?.qq
|
if (sendMsg.data?.qq) {
|
||||||
if (atQQ) {
|
const atQQ = String(sendMsg.data.qq)
|
||||||
atQQ = atQQ.toString()
|
|
||||||
if (atQQ === 'all') {
|
if (atQQ === 'all') {
|
||||||
// todo:查询剩余的at全体次数
|
// todo:查询剩余的at全体次数
|
||||||
const groupCode = peer.peerUid
|
const groupCode = peer.peerUid
|
||||||
@ -161,7 +160,7 @@ export async function createSendElements(
|
|||||||
}
|
}
|
||||||
break
|
break
|
||||||
case OB11MessageDataType.reply: {
|
case OB11MessageDataType.reply: {
|
||||||
if (sendMsg.data.id) {
|
if (sendMsg.data?.id) {
|
||||||
const replyMsgId = await MessageUnique.getMsgIdAndPeerByShortId(+sendMsg.data.id)
|
const replyMsgId = await MessageUnique.getMsgIdAndPeerByShortId(+sendMsg.data.id)
|
||||||
if (!replyMsgId) {
|
if (!replyMsgId) {
|
||||||
log('回复消息不存在', replyMsgId)
|
log('回复消息不存在', replyMsgId)
|
||||||
|
@ -590,21 +590,19 @@ export class OB11Constructor {
|
|||||||
msg: RawMessage,
|
msg: RawMessage,
|
||||||
shortId: number
|
shortId: number
|
||||||
): Promise<OB11FriendRecallNoticeEvent | OB11GroupRecallNoticeEvent | undefined> {
|
): Promise<OB11FriendRecallNoticeEvent | OB11GroupRecallNoticeEvent | undefined> {
|
||||||
let msgElement = msg.elements.find(
|
const msgElement = msg.elements.find(
|
||||||
(element) => element.grayTipElement?.subElementType === GrayTipElementSubType.RECALL,
|
(element) => element.grayTipElement?.subElementType === GrayTipElementSubType.RECALL,
|
||||||
)
|
)
|
||||||
if (!msgElement) {
|
if (!msgElement) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const isGroup = msg.chatType === ChatType.group
|
|
||||||
const revokeElement = msgElement.grayTipElement.revokeElement
|
const revokeElement = msgElement.grayTipElement.revokeElement
|
||||||
if (isGroup) {
|
if (msg.chatType === ChatType.group) {
|
||||||
const operator = await getGroupMember(msg.peerUid, revokeElement.operatorUid)
|
const operator = await getGroupMember(msg.peerUid, revokeElement.operatorUid)
|
||||||
const sender = await getGroupMember(msg.peerUid, revokeElement.origMsgSenderUid!)
|
|
||||||
return new OB11GroupRecallNoticeEvent(
|
return new OB11GroupRecallNoticeEvent(
|
||||||
parseInt(msg.peerUid),
|
parseInt(msg.peerUid),
|
||||||
parseInt(sender?.uin!),
|
parseInt(msg.senderUin!),
|
||||||
parseInt(operator?.uin!),
|
parseInt(operator?.uin || msg.senderUin!),
|
||||||
shortId,
|
shortId,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -219,6 +219,11 @@ async function onSettingWindowCreated(view: Element) {
|
|||||||
`${window.LiteLoader.plugins['LLOneBot'].path.data}/logs`,
|
`${window.LiteLoader.plugins['LLOneBot'].path.data}/logs`,
|
||||||
SettingButton('打开', 'config-open-log-path'),
|
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>`,
|
||||||
|
),
|
||||||
]),
|
]),
|
||||||
SettingList([
|
SettingList([
|
||||||
SettingItem('GitHub 仓库', `https://github.com/LLOneBot/LLOneBot`, SettingButton('点个星星', 'open-github')),
|
SettingItem('GitHub 仓库', `https://github.com/LLOneBot/LLOneBot`, SettingButton('点个星星', 'open-github')),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user