mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
feat: history msg db cache
test: try send music card
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import {
|
||||
AtType,
|
||||
ElementType, PicType,
|
||||
ElementType, PicType, SendArkElement,
|
||||
SendFaceElement,
|
||||
SendFileElement,
|
||||
SendPicElement,
|
||||
@@ -150,4 +150,12 @@ export class SendMsgElementConstructor {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static ark(data: any): SendArkElement {
|
||||
return {
|
||||
elementType: ElementType.ARK,
|
||||
elementId: "",
|
||||
arkElement: data
|
||||
}
|
||||
}
|
||||
}
|
@@ -2,13 +2,14 @@ import {type BrowserWindow} from 'electron'
|
||||
import {getConfigUtil, log, sleep} from '../common/utils'
|
||||
import {NTQQApi, type NTQQApiClass, sendMessagePool} from './ntcall'
|
||||
import {type Group, type RawMessage, type User} from './types'
|
||||
import {addHistoryMsg, friends, groups, msgHistory, selfInfo, tempGroupCodeMap} from '../common/data'
|
||||
import {friends, groups, selfInfo, tempGroupCodeMap} from '../common/data'
|
||||
import {OB11GroupDecreaseEvent} from '../onebot11/event/notice/OB11GroupDecreaseEvent'
|
||||
import {OB11GroupIncreaseEvent} from '../onebot11/event/notice/OB11GroupIncreaseEvent'
|
||||
import {v4 as uuidv4} from 'uuid'
|
||||
import {postOB11Event} from '../onebot11/server/postOB11Event'
|
||||
import {HOOK_LOG} from '../common/config'
|
||||
import fs from 'fs'
|
||||
import {dbUtil} from "../common/db";
|
||||
|
||||
export const hookApiCallbacks: Record<string, (apiReturn: any) => void> = {}
|
||||
|
||||
@@ -233,7 +234,7 @@ registerReceiveHook<{ msgList: RawMessage[] }>(ReceiveCmd.NEW_MSG, (payload) =>
|
||||
const {autoDeleteFile, autoDeleteFileSecond} = getConfigUtil().getConfig()
|
||||
for (const message of payload.msgList) {
|
||||
// log("收到新消息,push到历史记录", message)
|
||||
addHistoryMsg(message)
|
||||
dbUtil.addMsg(message).then()
|
||||
// 清理文件
|
||||
if (!autoDeleteFile) {
|
||||
continue
|
||||
@@ -261,10 +262,6 @@ registerReceiveHook<{ msgList: RawMessage[] }>(ReceiveCmd.NEW_MSG, (payload) =>
|
||||
}, autoDeleteFileSecond * 1000)
|
||||
}
|
||||
}
|
||||
const msgIds = Object.keys(msgHistory)
|
||||
if (msgIds.length > 30000) {
|
||||
delete msgHistory[msgIds.sort()[0]]
|
||||
}
|
||||
})
|
||||
|
||||
registerReceiveHook<{ msgRecord: RawMessage }>(ReceiveCmd.SELF_SEND_MSG, ({msgRecord}) => {
|
||||
|
@@ -17,9 +17,10 @@ import {
|
||||
type User
|
||||
} from './types'
|
||||
import * as fs from 'node:fs'
|
||||
import {addHistoryMsg, friendRequests, groupNotifies, msgHistory, selfInfo} from '../common/data'
|
||||
import {friendRequests, groupNotifies, selfInfo} from '../common/data'
|
||||
import {v4 as uuidv4} from 'uuid'
|
||||
import path from 'path'
|
||||
import {dbUtil} from "../common/db";
|
||||
|
||||
interface IPCReceiveEvent {
|
||||
eventName: string
|
||||
@@ -57,6 +58,7 @@ export enum NTQQApiMethod {
|
||||
RECALL_MSG = 'nodeIKernelMsgService/recallMsg',
|
||||
SEND_MSG = 'nodeIKernelMsgService/sendMsg',
|
||||
DOWNLOAD_MEDIA = 'nodeIKernelMsgService/downloadRichMedia',
|
||||
FORWARD_MSG = "nodeIKernelMsgService/forwardMsgWithComment", // 逐条转发
|
||||
MULTI_FORWARD_MSG = 'nodeIKernelMsgService/multiForwardMsgWithComment', // 合并转发
|
||||
GET_GROUP_NOTICE = 'nodeIKernelGroupService/getSingleScreenNotifies',
|
||||
HANDLE_GROUP_REQUEST = 'nodeIKernelGroupService/operateSysNotify',
|
||||
@@ -449,7 +451,14 @@ export class NTQQApi {
|
||||
|
||||
let checkSendCompleteUsingTime = 0
|
||||
const checkSendComplete = async (): Promise<RawMessage> => {
|
||||
if (sentMessage && msgHistory[sentMessage.msgId]?.sendStatus == 2) {
|
||||
if (sentMessage) {
|
||||
if (waitComplete) {
|
||||
if ((await dbUtil.getMsgByLongId(sentMessage.msgId)).sendStatus == 2) {
|
||||
return sentMessage
|
||||
} else {
|
||||
return await checkSendComplete()
|
||||
}
|
||||
}
|
||||
// log(`给${peerUid}发送消息成功`)
|
||||
return sentMessage
|
||||
} else {
|
||||
@@ -474,6 +483,24 @@ export class NTQQApi {
|
||||
return await checkSendComplete()
|
||||
}
|
||||
|
||||
static async forwardMsg(srcPeer: Peer, destPeer: Peer, msgIds: string[]) {
|
||||
return await callNTQQApi<GeneralCallResult>({
|
||||
methodName: NTQQApiMethod.FORWARD_MSG,
|
||||
args:[
|
||||
{
|
||||
msgIds: msgIds,
|
||||
srcContact: srcPeer,
|
||||
dstContacts: [
|
||||
destPeer
|
||||
],
|
||||
commentElements: [],
|
||||
msgAttributeInfos: new Map()
|
||||
},
|
||||
null,
|
||||
]
|
||||
})
|
||||
|
||||
}
|
||||
static async multiForwardMsg(srcPeer: Peer, destPeer: Peer, msgIds: string[]) {
|
||||
const msgInfos = msgIds.map(id => {
|
||||
return {msgId: id, senderShowName: selfInfo.nick}
|
||||
@@ -495,7 +522,7 @@ export class NTQQApi {
|
||||
reject('转发消息超时')
|
||||
}
|
||||
}, 5000)
|
||||
registerReceiveHook(ReceiveCmd.SELF_SEND_MSG, (payload: { msgRecord: RawMessage }) => {
|
||||
registerReceiveHook(ReceiveCmd.SELF_SEND_MSG, async (payload: { msgRecord: RawMessage }) => {
|
||||
const msg = payload.msgRecord
|
||||
// 需要判断它是转发的消息,并且识别到是当前转发的这一条
|
||||
const arkElement = msg.elements.find(ele => ele.arkElement)
|
||||
@@ -509,7 +536,7 @@ export class NTQQApi {
|
||||
}
|
||||
if (msg.peerUid == destPeer.peerUid && msg.senderUid == selfInfo.uid) {
|
||||
complete = true
|
||||
addHistoryMsg(msg)
|
||||
await dbUtil.addMsg(msg)
|
||||
resolve(msg)
|
||||
log('转发消息成功:', payload)
|
||||
}
|
||||
|
@@ -73,6 +73,7 @@ export enum ElementType {
|
||||
PTT = 4,
|
||||
FACE = 6,
|
||||
REPLY = 7,
|
||||
ARK = 10,
|
||||
}
|
||||
|
||||
export interface SendTextElement {
|
||||
@@ -165,13 +166,20 @@ export interface FileElement {
|
||||
}
|
||||
|
||||
export interface SendFileElement {
|
||||
"elementType": ElementType.FILE,
|
||||
"elementId": "",
|
||||
"fileElement": FileElement
|
||||
elementType: ElementType.FILE,
|
||||
elementId: "",
|
||||
fileElement: FileElement
|
||||
}
|
||||
|
||||
export interface SendArkElement {
|
||||
elementType: ElementType.ARK,
|
||||
elementId: "",
|
||||
arkElement: ArkElement
|
||||
|
||||
}
|
||||
|
||||
export type SendMessageElement = SendTextElement | SendPttElement |
|
||||
SendPicElement | SendReplyElement | SendFaceElement | SendFileElement
|
||||
SendPicElement | SendReplyElement | SendFaceElement | SendFileElement | SendArkElement
|
||||
|
||||
export enum AtType {
|
||||
notAt = 0,
|
||||
@@ -210,6 +218,8 @@ export interface PttElement {
|
||||
|
||||
export interface ArkElement {
|
||||
bytesData: string;
|
||||
linkInfo:null,
|
||||
subElementType:null
|
||||
}
|
||||
|
||||
export const IMAGE_HTTP_HOST = "https://gchat.qpic.cn"
|
||||
|
Reference in New Issue
Block a user