mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-21 09:36:35 +00:00
feat: maybe more stable fake forwardMsg
This commit is contained in:
parent
9ed2a2fd19
commit
a27c2a69c4
@ -3,7 +3,8 @@ import { PushMsgBody } from "@/core/packet/proto/message/message";
|
|||||||
import { NapProtoEncodeStructType } from "@/core/packet/proto/NapProto";
|
import { NapProtoEncodeStructType } from "@/core/packet/proto/NapProto";
|
||||||
import { LogWrapper } from "@/common/log";
|
import { LogWrapper } from "@/common/log";
|
||||||
import { PacketMsg, PacketSendMsgElement } from "@/core/packet/msg/message";
|
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 {
|
export class PacketMsgBuilder {
|
||||||
private logger: LogWrapper;
|
private logger: LogWrapper;
|
||||||
@ -12,6 +13,12 @@ export class PacketMsgBuilder {
|
|||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static failBackText = new PacketMsgTextElement(
|
||||||
|
{
|
||||||
|
textElement: {content: "[该消息类型暂不支持查看]"}!
|
||||||
|
} as SendTextElement
|
||||||
|
)
|
||||||
|
|
||||||
buildFakeMsg(selfUid: string, element: PacketMsg[]): NapProtoEncodeStructType<typeof PushMsgBody>[] {
|
buildFakeMsg(selfUid: string, element: PacketMsg[]): NapProtoEncodeStructType<typeof PushMsgBody>[] {
|
||||||
return element.map((node): NapProtoEncodeStructType<typeof PushMsgBody> => {
|
return element.map((node): NapProtoEncodeStructType<typeof PushMsgBody> => {
|
||||||
const avatar = `https://q.qlogo.cn/headimg_dl?dst_uin=${node.senderUin}&spec=640&img_type=jpg`;
|
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();
|
return acc !== undefined ? acc : msg.buildContent();
|
||||||
}, undefined);
|
}, undefined);
|
||||||
const msgElement = node.msg.flatMap(msg => msg.buildElement() ?? []);
|
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 {
|
return {
|
||||||
responseHead: {
|
responseHead: {
|
||||||
fromUid: "",
|
fromUid: "",
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import assert from "node:assert";
|
|
||||||
import * as zlib from "node:zlib";
|
import * as zlib from "node:zlib";
|
||||||
import { NapProtoEncodeStructType, NapProtoMsg } from "@/core/packet/proto/NapProto";
|
import { NapProtoEncodeStructType, NapProtoMsg } from "@/core/packet/proto/NapProto";
|
||||||
import {
|
import {
|
||||||
@ -25,9 +24,9 @@ import {
|
|||||||
SendTextElement,
|
SendTextElement,
|
||||||
SendVideoElement
|
SendVideoElement
|
||||||
} from "@/core";
|
} from "@/core";
|
||||||
import {MsgInfo} from "@/core/packet/proto/oidb/common/Ntv2.RichMediaReq";
|
import { MsgInfo } from "@/core/packet/proto/oidb/common/Ntv2.RichMediaReq";
|
||||||
import {PacketMsg, PacketSendMsgElement} from "@/core/packet/msg/message";
|
import { PacketMsg, PacketSendMsgElement } from "@/core/packet/msg/message";
|
||||||
import {ForwardMsgBuilder} from "@/common/forward-msg-builder";
|
import { ForwardMsgBuilder } from "@/common/forward-msg-builder";
|
||||||
import { FileExtra, GroupFileExtra } from "@/core/packet/proto/message/component";
|
import { FileExtra, GroupFileExtra } from "@/core/packet/proto/message/component";
|
||||||
import { OidbSvcTrpcTcp0XE37_800Response } from "@/core/packet/proto/oidb/Oidb.0XE37_800";
|
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<SendPicElement> {
|
|
||||||
path: string;
|
|
||||||
name: string;
|
|
||||||
size: number;
|
|
||||||
md5: string;
|
|
||||||
width: number;
|
|
||||||
height: number;
|
|
||||||
picType: PicType;
|
|
||||||
sha1: string | null = null;
|
|
||||||
msgInfo: NapProtoEncodeStructType<typeof MsgInfo> | null = null;
|
|
||||||
groupPicExt: NapProtoEncodeStructType<typeof CustomFace> | null = null;
|
|
||||||
c2cPicExt: NapProtoEncodeStructType<typeof NotOnlineImage> | 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<typeof Elem>[] {
|
|
||||||
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<SendReplyElement> {
|
export class PacketMsgReplyElement extends IPacketMsgElement<SendReplyElement> {
|
||||||
messageId: bigint;
|
messageId: bigint;
|
||||||
messageSeq: number;
|
messageSeq: number;
|
||||||
@ -282,6 +241,46 @@ export class PacketMsgMarkFaceElement extends IPacketMsgElement<SendMarketFaceEl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class PacketMsgPicElement extends IPacketMsgElement<SendPicElement> {
|
||||||
|
path: string;
|
||||||
|
name: string;
|
||||||
|
size: number;
|
||||||
|
md5: string;
|
||||||
|
width: number;
|
||||||
|
height: number;
|
||||||
|
picType: PicType;
|
||||||
|
sha1: string | null = null;
|
||||||
|
msgInfo: NapProtoEncodeStructType<typeof MsgInfo> | null = null;
|
||||||
|
groupPicExt: NapProtoEncodeStructType<typeof CustomFace> | null = null;
|
||||||
|
c2cPicExt: NapProtoEncodeStructType<typeof NotOnlineImage> | 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<typeof Elem>[] {
|
||||||
|
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<SendVideoElement> {
|
export class PacketMsgVideoElement extends IPacketMsgElement<SendVideoElement> {
|
||||||
fileSize?: string;
|
fileSize?: string;
|
||||||
filePath?: string;
|
filePath?: string;
|
||||||
@ -308,7 +307,7 @@ export class PacketMsgVideoElement extends IPacketMsgElement<SendVideoElement> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
buildElement(): NapProtoEncodeStructType<typeof Elem>[] {
|
buildElement(): NapProtoEncodeStructType<typeof Elem>[] {
|
||||||
assert(this.msgInfo !== null, 'msgInfo is null, expected not null');
|
if (!this.msgInfo) return [];
|
||||||
return [{
|
return [{
|
||||||
commonElem: {
|
commonElem: {
|
||||||
serviceType: 48,
|
serviceType: 48,
|
||||||
@ -340,7 +339,7 @@ export class PacketMsgPttElement extends IPacketMsgElement<SendPttElement> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
buildElement(): NapProtoEncodeStructType<typeof Elem>[] {
|
buildElement(): NapProtoEncodeStructType<typeof Elem>[] {
|
||||||
assert(this.msgInfo !== null, 'msgInfo is null, expected not null');
|
if (!this.msgInfo) return [];
|
||||||
return [{
|
return [{
|
||||||
commonElem: {
|
commonElem: {
|
||||||
serviceType: 48,
|
serviceType: 48,
|
||||||
@ -376,7 +375,7 @@ export class PacketMsgFileElement extends IPacketMsgElement<SendFileElement> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
buildContent(): Uint8Array | undefined {
|
buildContent(): Uint8Array | undefined {
|
||||||
if (this.isGroupFile) return undefined;
|
if (this.isGroupFile || !this._e37_800_rsp) return undefined;
|
||||||
return new NapProtoMsg(FileExtra).encode({
|
return new NapProtoMsg(FileExtra).encode({
|
||||||
file: {
|
file: {
|
||||||
fileType: 0,
|
fileType: 0,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user