feat: 合并消息初步解析完成

This commit is contained in:
手瓜一十雪 2024-08-06 14:48:20 +08:00
parent 1a1acdc3c9
commit c36bb77286
5 changed files with 50 additions and 27 deletions

View File

@ -67,6 +67,9 @@ setTimeout(() => {
// }, 25000) // }, 25000)
export class NTQQMsgApi { export class NTQQMsgApi {
static async FetchLongMsg(peer: Peer, msgId: string) {
return napCatCore.session.getMsgService().fetchLongMsg(peer, msgId);
}
static async getMsgEmojiLikesList(peer: Peer, msgSeq: string, emojiId: string, emojiType: string, count: number = 20) { static async getMsgEmojiLikesList(peer: Peer, msgSeq: string, emojiId: string, emojiType: string, count: number = 20) {
//console.log(peer, msgSeq, emojiId, emojiType, count); //console.log(peer, msgSeq, emojiId, emojiType, count);
return napCatCore.session.getMsgService().getMsgEmojiLikesList(peer, msgSeq, emojiId, emojiType, "", false, 20) return napCatCore.session.getMsgService().getMsgEmojiLikesList(peer, msgSeq, emojiId, emojiType, "", false, 20)
@ -100,7 +103,7 @@ export class NTQQMsgApi {
filterMsgFromTime: '0', filterMsgFromTime: '0',
isReverseOrder: false, isReverseOrder: false,
isIncludeCurrent: true, isIncludeCurrent: true,
pageLimit: 1, pageLimit: count,
}); });
return ret; return ret;
} }

View File

@ -731,10 +731,12 @@ export interface MultiForwardMsgElement {
} }
export interface RawMessage { export interface RawMessage {
parentMsgPeer: Peer;
parentMsgIdList:string[];
id?: number;//扩展字段 用于处理OB11 ID
guildId: string; guildId: string;
msgRandom: string; msgRandom: string;
// int32, 自己维护的消息id
id?: number;
msgId: string; msgId: string;

View File

@ -37,7 +37,7 @@ export default class GoCQHTTPGetGroupMsgHistory extends BaseAction<Payload, Resp
peerUid: group.groupCode peerUid: group.groupCode
}; };
let msgList: RawMessage[]; let msgList: RawMessage[];
if (!payload.message_seq) { if (!payload.message_seq || payload.message_seq === 0) {
msgList = (await NTQQMsgApi.getLastestMsgByUids(peer, count)).msgList; msgList = (await NTQQMsgApi.getLastestMsgByUids(peer, count)).msgList;
} else { } else {
const startMsgId = (await MessageUnique.getMsgIdAndPeerByShortId(targetMsgShortId ?? (payload.message_seq ?? 0)))?.MsgId || '0'; const startMsgId = (await MessageUnique.getMsgIdAndPeerByShortId(targetMsgShortId ?? (payload.message_seq ?? 0)))?.MsgId || '0';

View File

@ -327,6 +327,24 @@ export class OB11Constructor {
else if (element.multiForwardMsgElement) { else if (element.multiForwardMsgElement) {
message_data['type'] = OB11MessageDataType.forward; message_data['type'] = OB11MessageDataType.forward;
message_data['data']['id'] = msg.msgId; message_data['data']['id'] = msg.msgId;
const ParentMsgPeer = msg.parentMsgPeer ?? { chatType: msg.chatType, guildId: '', peerUid: msg.peerUid };
//判断是否在合并消息内
msg.parentMsgIdList = msg.parentMsgIdList ?? [];
//首次列表不存在则开始创建
msg.parentMsgIdList.push(msg.msgId);
//let parentMsgId = msg.parentMsgIdList[msg.parentMsgIdList.length - 2 < 0 ? 0 : msg.parentMsgIdList.length - 2];
//加入自身MsgId
let MultiMsgs = (await NTQQMsgApi.getMultiMsg(ParentMsgPeer, msg.parentMsgIdList[0], msg.msgId))?.msgList;
//拉取下级消息
if (!MultiMsgs) continue;
//拉取失败则跳过
for (let MultiMsg of MultiMsgs) {
//对每条拉取的消息传递ParentMsgPeer修正Peer
MultiMsg.parentMsgPeer = ParentMsgPeer;
MultiMsg.parentMsgIdList = msg.parentMsgIdList;
let msgList = await OB11Constructor.message(MultiMsg);
console.log(msgList);
}
} }
if ((message_data.type as string) !== 'unknown' && message_data.data) { if ((message_data.type as string) !== 'unknown' && message_data.data) {
const cqCode = encodeCQCode(message_data); const cqCode = encodeCQCode(message_data);

View File

@ -2,7 +2,7 @@ import { OB11Message } from '@/onebot11/types';
import { log } from '@/common/utils/log'; import { log } from '@/common/utils/log';
import { getGroup, getGroupMember, selfInfo } from '@/core/data'; import { getGroup, getGroupMember, selfInfo } from '@/core/data';
import exp from 'constants'; import exp from 'constants';
import { Group } from '@/core'; import { Group, NTQQMsgApi } from '@/core';
import chalk from 'chalk'; import chalk from 'chalk';
const spSegColor = chalk.blue;// for special segment const spSegColor = chalk.blue;// for special segment
@ -67,7 +67,7 @@ export async function logMessage(ob11Message: OB11Message) {
msgParts.push(spSegColor(`[视频|${segment.data.url}]`)); msgParts.push(spSegColor(`[视频|${segment.data.url}]`));
} }
else if (segment.type === 'forward') { else if (segment.type === 'forward') {
msgParts.push(spSegColor(`[转发|${JSON.stringify(segment.data.id)}]`)); msgParts.push(spSegColor(`[转发|${segment.data.id}]`));
} }
else { else {
msgParts.push(spSegColor(`[未实现|${JSON.stringify(segment)}]`)); msgParts.push(spSegColor(`[未实现|${JSON.stringify(segment)}]`));