mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-21 09:36:35 +00:00
fix: 跳过空消息
This commit is contained in:
parent
e77bcc1267
commit
43e94a5db0
@ -39,15 +39,16 @@ export class GoCQHTTPGetForwardMsgAction extends BaseAction<Payload, any> {
|
|||||||
throw Error('找不到相关的聊天记录' + data?.errMsg);
|
throw Error('找不到相关的聊天记录' + data?.errMsg);
|
||||||
}
|
}
|
||||||
const msgList = data.msgList;
|
const msgList = data.msgList;
|
||||||
const messages = await Promise.all(msgList.map(async msg => {
|
const messages = (await Promise.all(msgList.map(async msg => {
|
||||||
const resMsg = await OB11Constructor.message(this.CoreContext, msg, 'array');
|
const resMsg = await OB11Constructor.message(this.CoreContext, msg, 'array');
|
||||||
|
if (!resMsg) return;
|
||||||
resMsg.message_id = MessageUnique.createMsg({
|
resMsg.message_id = MessageUnique.createMsg({
|
||||||
guildId: '',
|
guildId: '',
|
||||||
chatType: msg.chatType,
|
chatType: msg.chatType,
|
||||||
peerUid: msg.peerUid,
|
peerUid: msg.peerUid,
|
||||||
}, msg.msgId)!;
|
}, msg.msgId)!;
|
||||||
return resMsg;
|
return resMsg;
|
||||||
}));
|
}))).filter(msg => !!msg);
|
||||||
messages.map(msg => {
|
messages.map(msg => {
|
||||||
(<OB11ForwardMessage>msg).content = msg.message;
|
(<OB11ForwardMessage>msg).content = msg.message;
|
||||||
delete (<any>msg).message;
|
delete (<any>msg).message;
|
||||||
|
@ -53,7 +53,7 @@ export default class GetFriendMsgHistory extends BaseAction<Payload, Response> {
|
|||||||
msg.id = MessageUnique.createMsg({ guildId: '', chatType: msg.chatType, peerUid: msg.peerUid }, msg.msgId);
|
msg.id = MessageUnique.createMsg({ guildId: '', chatType: msg.chatType, peerUid: msg.peerUid }, msg.msgId);
|
||||||
}));
|
}));
|
||||||
//转换消息
|
//转换消息
|
||||||
const ob11MsgList = await Promise.all(msgList.map(msg => OB11Constructor.message(this.CoreContext, msg, 'array')));
|
const ob11MsgList = (await Promise.all(msgList.map(msg => OB11Constructor.message(this.CoreContext, msg, 'array')))).filter(msg => !!msg);
|
||||||
return { 'messages': ob11MsgList };
|
return { 'messages': ob11MsgList };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ export default class GoCQHTTPGetGroupMsgHistory extends BaseAction<Payload, Resp
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
//转换消息
|
//转换消息
|
||||||
const ob11MsgList = await Promise.all(msgList.map(msg => OB11Constructor.message(this.CoreContext, msg, 'array')));
|
const ob11MsgList = (await Promise.all(msgList.map(msg => OB11Constructor.message(this.CoreContext, msg, 'array')))).filter(msg => !!msg);
|
||||||
return { 'messages': ob11MsgList };
|
return { 'messages': ob11MsgList };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,7 @@ class GetMsg extends BaseAction<Payload, OB11Message> {
|
|||||||
peer,
|
peer,
|
||||||
[msgIdWithPeer?.MsgId || payload.message_id.toString()]);
|
[msgIdWithPeer?.MsgId || payload.message_id.toString()]);
|
||||||
const retMsg = await OB11Constructor.message(this.CoreContext, msg.msgList[0], 'array');
|
const retMsg = await OB11Constructor.message(this.CoreContext, msg.msgList[0], 'array');
|
||||||
|
if(!retMsg) throw Error('消息为空');
|
||||||
try {
|
try {
|
||||||
retMsg.message_id = MessageUnique.createMsg(peer, msg.msgList[0].msgId)!;
|
retMsg.message_id = MessageUnique.createMsg(peer, msg.msgList[0].msgId)!;
|
||||||
retMsg.message_seq = retMsg.message_id;
|
retMsg.message_seq = retMsg.message_id;
|
||||||
|
@ -42,10 +42,14 @@ import { OB11BaseNoticeEvent } from '../event/notice/OB11BaseNoticeEvent';
|
|||||||
import { OB11GroupEssenceEvent } from '../event/notice/OB11GroupEssenceEvent';
|
import { OB11GroupEssenceEvent } from '../event/notice/OB11GroupEssenceEvent';
|
||||||
import { MessageUnique } from '@/common/utils/MessageUnique';
|
import { MessageUnique } from '@/common/utils/MessageUnique';
|
||||||
import { NapCatCore } from '@/core';
|
import { NapCatCore } from '@/core';
|
||||||
|
import { c } from 'vite/dist/node/types.d-aGj9QkWt';
|
||||||
|
|
||||||
|
|
||||||
export class OB11Constructor {
|
export class OB11Constructor {
|
||||||
static async message(core: NapCatCore, msg: RawMessage, messagePostFormat: any): Promise<OB11Message> {
|
static async message(core: NapCatCore, msg: RawMessage, messagePostFormat: any): Promise<OB11Message | undefined> {
|
||||||
|
if (msg.senderUin == "0") return;
|
||||||
|
if (msg.peerUin == "0") return;
|
||||||
|
//跳过空消息
|
||||||
const NTQQGroupApi = core.apis.GroupApi;
|
const NTQQGroupApi = core.apis.GroupApi;
|
||||||
const NTQQUserApi = core.apis.UserApi;
|
const NTQQUserApi = core.apis.UserApi;
|
||||||
const NTQQFileApi = core.apis.FileApi;
|
const NTQQFileApi = core.apis.FileApi;
|
||||||
@ -141,7 +145,7 @@ export class OB11Constructor {
|
|||||||
message_data['type'] = OB11MessageDataType.reply;
|
message_data['type'] = OB11MessageDataType.reply;
|
||||||
//log("收到回复消息", element.replyElement);
|
//log("收到回复消息", element.replyElement);
|
||||||
try {
|
try {
|
||||||
const records = msg.records.find(msgRecord => msgRecord.msgId === element.replyElement.sourceMsgIdInRecords);
|
const records = msg.records.find(msgRecord => msgRecord.msgId === element?.replyElement?.sourceMsgIdInRecords);
|
||||||
const peer = {
|
const peer = {
|
||||||
chatType: msg.chatType,
|
chatType: msg.chatType,
|
||||||
peerUid: msg.peerUid,
|
peerUid: msg.peerUid,
|
||||||
@ -343,6 +347,7 @@ export class OB11Constructor {
|
|||||||
MultiMsg.parentMsgIdList = msg.parentMsgIdList;
|
MultiMsg.parentMsgIdList = msg.parentMsgIdList;
|
||||||
MultiMsg.id = MessageUnique.createMsg(ParentMsgPeer, MultiMsg.msgId);//该ID仅用查看 无法调用
|
MultiMsg.id = MessageUnique.createMsg(ParentMsgPeer, MultiMsg.msgId);//该ID仅用查看 无法调用
|
||||||
const msgList = await OB11Constructor.message(core, MultiMsg, 'array');
|
const msgList = await OB11Constructor.message(core, MultiMsg, 'array');
|
||||||
|
if (!msgList) continue;
|
||||||
message_data['data']['content'].push(msgList);
|
message_data['data']['content'].push(msgList);
|
||||||
//console.log("合并消息", msgList);
|
//console.log("合并消息", msgList);
|
||||||
}
|
}
|
||||||
|
@ -255,6 +255,7 @@ export class NapCatOneBot11Adapter {
|
|||||||
// 完成后再post
|
// 完成后再post
|
||||||
OB11Constructor.message(this.core, msg, this.configLoader.configData.messagePostFormat)
|
OB11Constructor.message(this.core, msg, this.configLoader.configData.messagePostFormat)
|
||||||
.then((ob11Msg) => {
|
.then((ob11Msg) => {
|
||||||
|
if(!ob11Msg) return;
|
||||||
ob11Msg.target_id = parseInt(msg.peerUin);
|
ob11Msg.target_id = parseInt(msg.peerUin);
|
||||||
if (this.configLoader.configData.reportSelfMessage) {
|
if (this.configLoader.configData.reportSelfMessage) {
|
||||||
msg.id = MessageUnique.createMsg({
|
msg.id = MessageUnique.createMsg({
|
||||||
@ -425,6 +426,7 @@ export class NapCatOneBot11Adapter {
|
|||||||
const { debug, reportSelfMessage, messagePostFormat } = this.configLoader.configData;
|
const { debug, reportSelfMessage, messagePostFormat } = this.configLoader.configData;
|
||||||
this.context.logger.logDebug('收到新消息 RawMessage', message);
|
this.context.logger.logDebug('收到新消息 RawMessage', message);
|
||||||
OB11Constructor.message(this.core, message, messagePostFormat).then((ob11Msg) => {
|
OB11Constructor.message(this.core, message, messagePostFormat).then((ob11Msg) => {
|
||||||
|
if(!ob11Msg) return;
|
||||||
this.context.logger.logDebug('转化为 OB11Message', ob11Msg);
|
this.context.logger.logDebug('转化为 OB11Message', ob11Msg);
|
||||||
if (debug) {
|
if (debug) {
|
||||||
ob11Msg.raw = message;
|
ob11Msg.raw = message;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user