fix: report self sent message_id

This commit is contained in:
linyuchen 2024-02-14 01:35:05 +08:00
parent c4b45f8298
commit aea67db27c
4 changed files with 38 additions and 31 deletions

View File

@ -4,7 +4,7 @@
"name": "LLOneBot", "name": "LLOneBot",
"slug": "LLOneBot", "slug": "LLOneBot",
"description": "LiteLoaderQQNT的OneBotApi", "description": "LiteLoaderQQNT的OneBotApi",
"version": "3.0.5", "version": "3.0.6",
"thumbnail": "./icon.png", "thumbnail": "./icon.png",
"authors": [{ "authors": [{
"name": "linyuchen", "name": "linyuchen",

View File

@ -12,7 +12,7 @@ import {
} from "../common/channels"; } from "../common/channels";
import { postMsg, startExpress } from "../onebot11/server"; import { postMsg, startExpress } from "../onebot11/server";
import { CONFIG_DIR, getConfigUtil, log } from "../common/utils"; import { CONFIG_DIR, getConfigUtil, log } from "../common/utils";
import { addHistoryMsg, selfInfo } from "../common/data"; import { addHistoryMsg, msgHistory, selfInfo } from "../common/data";
import { hookNTQQApiReceive, ReceiveCmd, registerReceiveHook } from "../ntqqapi/hook"; import { hookNTQQApiReceive, ReceiveCmd, registerReceiveHook } from "../ntqqapi/hook";
import { OB11Constructor } from "../onebot11/constructor"; import { OB11Constructor } from "../onebot11/constructor";
import { NTQQApi } from "../ntqqapi/ntcall"; import { NTQQApi } from "../ntqqapi/ntcall";
@ -48,6 +48,10 @@ function onLoad() {
function postRawMsg(msgList: RawMessage[]) { function postRawMsg(msgList: RawMessage[]) {
const {debug, reportSelfMessage} = getConfigUtil().getConfig(); const {debug, reportSelfMessage} = getConfigUtil().getConfig();
for (let message of msgList) { for (let message of msgList) {
message.msgShortId = msgHistory[message.msgId]?.msgShortId
if (!message.msgShortId) {
addHistoryMsg(message)
}
OB11Constructor.message(message).then((msg) => { OB11Constructor.message(message).then((msg) => {
if (debug) { if (debug) {
msg.raw = message; msg.raw = message;
@ -78,7 +82,7 @@ function onLoad() {
if (!reportSelfMessage) { if (!reportSelfMessage) {
return return
} }
log("reportSelfMessage", payload) // log("reportSelfMessage", payload)
try { try {
postRawMsg([payload.msgRecord]); postRawMsg([payload.msgRecord]);
} catch (e) { } catch (e) {

View File

@ -137,12 +137,8 @@ registerReceiveHook<{ msgList: Array<RawMessage> }>(ReceiveCmd.UPDATE_MSG, (payl
registerReceiveHook<{ msgList: Array<RawMessage> }>(ReceiveCmd.NEW_MSG, (payload) => { registerReceiveHook<{ msgList: Array<RawMessage> }>(ReceiveCmd.NEW_MSG, (payload) => {
for (const message of payload.msgList) { for (const message of payload.msgList) {
log("收到新消息push到历史记录", message) // log("收到新消息push到历史记录", message)
if (!msgHistory[message.msgId]) {
addHistoryMsg(message) addHistoryMsg(message)
} else {
Object.assign(msgHistory[message.msgId], message)
}
} }
const msgIds = Object.keys(msgHistory); const msgIds = Object.keys(msgHistory);
if (msgIds.length > 30000) { if (msgIds.length > 30000) {

View File

@ -1,12 +1,21 @@
import {OB11MessageDataType, OB11GroupMemberRole, OB11Message, OB11MessageData, OB11Group, OB11GroupMember, OB11User} from "./types"; import {
OB11MessageDataType,
OB11GroupMemberRole,
OB11Message,
OB11MessageData,
OB11Group,
OB11GroupMember,
OB11User
} from "./types";
import { AtType, ChatType, Group, GroupMember, IMAGE_HTTP_HOST, RawMessage, SelfInfo, User } from '../ntqqapi/types'; import { AtType, ChatType, Group, GroupMember, IMAGE_HTTP_HOST, RawMessage, SelfInfo, User } from '../ntqqapi/types';
import { addHistoryMsg, getFriend, getGroupMember, getHistoryMsgBySeq, selfInfo } from '../common/data'; import { addHistoryMsg, getFriend, getGroupMember, getHistoryMsgBySeq, msgHistory, selfInfo } from '../common/data';
import { file2base64, getConfigUtil, log } from "../common/utils"; import { file2base64, getConfigUtil, log } from "../common/utils";
import { NTQQApi } from "../ntqqapi/ntcall"; import { NTQQApi } from "../ntqqapi/ntcall";
export class OB11Constructor { export class OB11Constructor {
static async message(msg: RawMessage): Promise<OB11Message> { static async message(msg: RawMessage): Promise<OB11Message> {
const {enableBase64} = getConfigUtil().getConfig() const {enableBase64} = getConfigUtil().getConfig()
const message_type = msg.chatType == ChatType.group ? "group" : "private"; const message_type = msg.chatType == ChatType.group ? "group" : "private";
const resMsg: OB11Message = { const resMsg: OB11Message = {
@ -86,8 +95,7 @@ export class OB11Constructor {
const replyMsg = getHistoryMsgBySeq(element.replyElement.replayMsgSeq) const replyMsg = getHistoryMsgBySeq(element.replyElement.replayMsgSeq)
if (replyMsg) { if (replyMsg) {
message_data["data"]["id"] = replyMsg.msgShortId message_data["data"]["id"] = replyMsg.msgShortId
} } else {
else{
continue continue
} }
} else if (element.pttElement) { } else if (element.pttElement) {
@ -106,8 +114,7 @@ export class OB11Constructor {
} }
if (message_data.data.http_file) { if (message_data.data.http_file) {
message_data.data.file = message_data.data.http_file message_data.data.file = message_data.data.http_file
} } else if (message_data.data.file) {
else if (message_data.data.file) {
let filePath: string = message_data.data.file; let filePath: string = message_data.data.file;
message_data.data.file = "file://" + filePath message_data.data.file = "file://" + filePath
if (enableBase64) { if (enableBase64) {