From a27c2a69c40c5240a0fc29550570f7b72eec2e47 Mon Sep 17 00:00:00 2001 From: pk5ls20 Date: Fri, 25 Oct 2024 07:27:35 +0800 Subject: [PATCH] feat: maybe more stable fake forwardMsg --- src/core/packet/msg/builder.ts | 13 ++++- src/core/packet/msg/element.ts | 93 +++++++++++++++++----------------- 2 files changed, 58 insertions(+), 48 deletions(-) diff --git a/src/core/packet/msg/builder.ts b/src/core/packet/msg/builder.ts index ea6a1d3c..eef14eec 100644 --- a/src/core/packet/msg/builder.ts +++ b/src/core/packet/msg/builder.ts @@ -3,7 +3,8 @@ import { PushMsgBody } from "@/core/packet/proto/message/message"; import { NapProtoEncodeStructType } from "@/core/packet/proto/NapProto"; import { LogWrapper } from "@/common/log"; import { PacketMsg, PacketSendMsgElement } from "@/core/packet/msg/message"; -import { IPacketMsgElement } from "@/core/packet/msg/element"; +import { IPacketMsgElement, PacketMsgTextElement } from "@/core/packet/msg/element"; +import { SendTextElement } from "@/core"; export class PacketMsgBuilder { private logger: LogWrapper; @@ -12,6 +13,12 @@ export class PacketMsgBuilder { this.logger = logger; } + protected static failBackText = new PacketMsgTextElement( + { + textElement: {content: "[该消息类型暂不支持查看]"}! + } as SendTextElement + ) + buildFakeMsg(selfUid: string, element: PacketMsg[]): NapProtoEncodeStructType[] { return element.map((node): NapProtoEncodeStructType => { const avatar = `https://q.qlogo.cn/headimg_dl?dst_uin=${node.senderUin}&spec=640&img_type=jpg`; @@ -19,6 +26,10 @@ export class PacketMsgBuilder { return acc !== undefined ? acc : msg.buildContent(); }, undefined); const msgElement = node.msg.flatMap(msg => msg.buildElement() ?? []); + if (!msgContent && !msgElement.length) { + this.logger.logWarn(`[PacketMsgBuilder] buildFakeMsg: 空的msgContent和msgElement!`); + msgElement.push(PacketMsgBuilder.failBackText.buildElement()); + } return { responseHead: { fromUid: "", diff --git a/src/core/packet/msg/element.ts b/src/core/packet/msg/element.ts index 1fa9e064..80205ec0 100644 --- a/src/core/packet/msg/element.ts +++ b/src/core/packet/msg/element.ts @@ -1,4 +1,3 @@ -import assert from "node:assert"; import * as zlib from "node:zlib"; import { NapProtoEncodeStructType, NapProtoMsg } from "@/core/packet/proto/NapProto"; import { @@ -25,9 +24,9 @@ import { SendTextElement, SendVideoElement } from "@/core"; -import {MsgInfo} from "@/core/packet/proto/oidb/common/Ntv2.RichMediaReq"; -import {PacketMsg, PacketSendMsgElement} from "@/core/packet/msg/message"; -import {ForwardMsgBuilder} from "@/common/forward-msg-builder"; +import { MsgInfo } from "@/core/packet/proto/oidb/common/Ntv2.RichMediaReq"; +import { PacketMsg, PacketSendMsgElement } from "@/core/packet/msg/message"; +import { ForwardMsgBuilder } from "@/common/forward-msg-builder"; import { FileExtra, GroupFileExtra } from "@/core/packet/proto/message/component"; import { OidbSvcTrpcTcp0XE37_800Response } from "@/core/packet/proto/oidb/Oidb.0XE37_800"; @@ -97,46 +96,6 @@ export class PacketMsgAtElement extends PacketMsgTextElement { } } -export class PacketMsgPicElement extends IPacketMsgElement { - path: string; - name: string; - size: number; - md5: string; - width: number; - height: number; - picType: PicType; - sha1: string | null = null; - msgInfo: NapProtoEncodeStructType | null = null; - groupPicExt: NapProtoEncodeStructType | null = null; - c2cPicExt: NapProtoEncodeStructType | null = null; - - constructor(element: SendPicElement) { - super(element); - this.path = element.picElement.sourcePath; - this.name = element.picElement.fileName; - this.size = +element.picElement.fileSize; - this.md5 = element.picElement.md5HexStr ?? ''; - this.width = element.picElement.picWidth; - this.height = element.picElement.picHeight; - this.picType = element.picElement.picType; - } - - buildElement(): NapProtoEncodeStructType[] { - assert(this.msgInfo !== null, 'msgInfo is null, expected not null'); - return [{ - commonElem: { - serviceType: 48, - pbElem: new NapProtoMsg(MsgInfo).encode(this.msgInfo), - businessType: 10, - } - }]; - } - - toPreview(): string { - return "[图片]"; - } -} - export class PacketMsgReplyElement extends IPacketMsgElement { messageId: bigint; messageSeq: number; @@ -282,6 +241,46 @@ export class PacketMsgMarkFaceElement extends IPacketMsgElement { + path: string; + name: string; + size: number; + md5: string; + width: number; + height: number; + picType: PicType; + sha1: string | null = null; + msgInfo: NapProtoEncodeStructType | null = null; + groupPicExt: NapProtoEncodeStructType | null = null; + c2cPicExt: NapProtoEncodeStructType | null = null; + + constructor(element: SendPicElement) { + super(element); + this.path = element.picElement.sourcePath; + this.name = element.picElement.fileName; + this.size = +element.picElement.fileSize; + this.md5 = element.picElement.md5HexStr ?? ''; + this.width = element.picElement.picWidth; + this.height = element.picElement.picHeight; + this.picType = element.picElement.picType; + } + + buildElement(): NapProtoEncodeStructType[] { + if (!this.msgInfo) return []; + return [{ + commonElem: { + serviceType: 48, + pbElem: new NapProtoMsg(MsgInfo).encode(this.msgInfo), + businessType: 10, + } + }]; + } + + toPreview(): string { + return "[图片]"; + } +} + export class PacketMsgVideoElement extends IPacketMsgElement { fileSize?: string; filePath?: string; @@ -308,7 +307,7 @@ export class PacketMsgVideoElement extends IPacketMsgElement { } buildElement(): NapProtoEncodeStructType[] { - assert(this.msgInfo !== null, 'msgInfo is null, expected not null'); + if (!this.msgInfo) return []; return [{ commonElem: { serviceType: 48, @@ -340,7 +339,7 @@ export class PacketMsgPttElement extends IPacketMsgElement { } buildElement(): NapProtoEncodeStructType[] { - assert(this.msgInfo !== null, 'msgInfo is null, expected not null'); + if (!this.msgInfo) return []; return [{ commonElem: { serviceType: 48, @@ -376,7 +375,7 @@ export class PacketMsgFileElement extends IPacketMsgElement { } buildContent(): Uint8Array | undefined { - if (this.isGroupFile) return undefined; + if (this.isGroupFile || !this._e37_800_rsp) return undefined; return new NapProtoMsg(FileExtra).encode({ file: { fileType: 0,