mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-07-19 12:03:37 +00:00
fix: #721
This commit is contained in:
@@ -66,7 +66,7 @@ export abstract class ConfigBase<T> {
|
|||||||
|
|
||||||
private handleError(e: unknown, message: string): void {
|
private handleError(e: unknown, message: string): void {
|
||||||
if (e instanceof SyntaxError) {
|
if (e instanceof SyntaxError) {
|
||||||
this.core.context.logger.logError(`[Core] [Config] 操作配置文件格式错误,请检查配置文件:`, e.message);
|
this.core.context.logger.logError('[Core] [Config] 操作配置文件格式错误,请检查配置文件:', e.message);
|
||||||
} else {
|
} else {
|
||||||
this.core.context.logger.logError(`[Core] [Config] ${message}:`, (e as Error).message);
|
this.core.context.logger.logError(`[Core] [Config] ${message}:`, (e as Error).message);
|
||||||
}
|
}
|
||||||
|
@@ -8,13 +8,15 @@ import {
|
|||||||
PacketMsgPttElement,
|
PacketMsgPttElement,
|
||||||
PacketMsgVideoElement
|
PacketMsgVideoElement
|
||||||
} from '@/core/packet/message/element';
|
} from '@/core/packet/message/element';
|
||||||
import { ChatType } from '@/core';
|
import {ChatType, MsgSourceType, NTMsgType, RawMessage} from '@/core';
|
||||||
import {MiniAppRawData, MiniAppReqParams} from '@/core/packet/entities/miniApp';
|
import {MiniAppRawData, MiniAppReqParams} from '@/core/packet/entities/miniApp';
|
||||||
import {AIVoiceChatType} from '@/core/packet/entities/aiChat';
|
import {AIVoiceChatType} from '@/core/packet/entities/aiChat';
|
||||||
import { NapProtoDecodeStructType, NapProtoEncodeStructType } from '@napneko/nap-proto-core';
|
import {NapProtoDecodeStructType, NapProtoEncodeStructType, NapProtoMsg} from '@napneko/nap-proto-core';
|
||||||
import { IndexNode, MsgInfo } from '@/core/packet/transformer/proto';
|
import {IndexNode, LongMsgResult, MsgInfo} from '@/core/packet/transformer/proto';
|
||||||
import {OidbPacket} from '@/core/packet/transformer/base';
|
import {OidbPacket} from '@/core/packet/transformer/base';
|
||||||
import {ImageOcrResult} from '@/core/packet/entities/ocrResult';
|
import {ImageOcrResult} from '@/core/packet/entities/ocrResult';
|
||||||
|
import {gunzipSync} from 'zlib';
|
||||||
|
import {PacketMsgConverter} from '@/core/packet/message/converter';
|
||||||
|
|
||||||
export class PacketOperationContext {
|
export class PacketOperationContext {
|
||||||
private readonly context: PacketContext;
|
private readonly context: PacketContext;
|
||||||
@@ -116,6 +118,13 @@ export class PacketOperationContext {
|
|||||||
return `https://${res.download.info.domain}${res.download.info.urlPath}${res.download.rKeyParam}`;
|
return `https://${res.download.info.domain}${res.download.info.urlPath}${res.download.rKeyParam}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async GetGroupImageUrl(groupUin: number, node: NapProtoEncodeStructType<typeof IndexNode>) {
|
||||||
|
const req = trans.DownloadGroupImage.build(groupUin, node);
|
||||||
|
const resp = await this.context.client.sendOidbPacket(req, true);
|
||||||
|
const res = trans.DownloadImage.parse(resp);
|
||||||
|
return `https://${res.download.info.domain}${res.download.info.urlPath}${res.download.rKeyParam}`;
|
||||||
|
}
|
||||||
|
|
||||||
async ImageOCR(imgUrl: string) {
|
async ImageOCR(imgUrl: string) {
|
||||||
const req = trans.ImageOCR.build(imgUrl);
|
const req = trans.ImageOCR.build(imgUrl);
|
||||||
const resp = await this.context.client.sendOidbPacket(req, true);
|
const resp = await this.context.client.sendOidbPacket(req, true);
|
||||||
@@ -195,4 +204,74 @@ export class PacketOperationContext {
|
|||||||
return res.msgInfo;
|
return res.msgInfo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async FetchForwardMsg(res_id: string): Promise<RawMessage[]> {
|
||||||
|
const req = trans.DownloadForwardMsg.build(this.context.napcore.basicInfo.uid, res_id);
|
||||||
|
const resp = await this.context.client.sendOidbPacket(req, true);
|
||||||
|
const res = trans.DownloadForwardMsg.parse(resp);
|
||||||
|
const inflate = gunzipSync(res.result.payload);
|
||||||
|
const result = new NapProtoMsg(LongMsgResult).decode(inflate);
|
||||||
|
|
||||||
|
const main = result.action.find((r) => r.actionCommand === 'MultiMsg');
|
||||||
|
if (!main?.actionData.msgBody) {
|
||||||
|
throw new Error('msgBody is empty');
|
||||||
|
}
|
||||||
|
|
||||||
|
const messagesPromises = main.actionData.msgBody.map(async (msg) => {
|
||||||
|
if (!msg?.body?.richText?.elems) {
|
||||||
|
throw new Error('msg.body.richText.elems is empty');
|
||||||
|
}
|
||||||
|
const rawChains = new PacketMsgConverter().packetMsgToRaw(msg?.body?.richText?.elems);
|
||||||
|
const elements = await Promise.all(
|
||||||
|
rawChains.map(async ([element, rawElem]) => {
|
||||||
|
if (element.picElement && rawElem?.commonElem?.pbElem) {
|
||||||
|
const extra = new NapProtoMsg(MsgInfo).decode(rawElem.commonElem.pbElem);
|
||||||
|
const index = extra?.msgInfoBody[0]?.index;
|
||||||
|
if (msg?.responseHead.grp !== undefined) {
|
||||||
|
const groupUin = msg?.responseHead.grp?.groupUin ?? 0;
|
||||||
|
element.picElement = {
|
||||||
|
...element.picElement,
|
||||||
|
originImageUrl: await this.GetGroupImageUrl(groupUin, index!)
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
element.picElement = {
|
||||||
|
...element.picElement,
|
||||||
|
originImageUrl: await this.GetImageUrl(this.context.napcore.basicInfo.uid, index!)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
return element;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
return {
|
||||||
|
chatType: ChatType.KCHATTYPEGROUP,
|
||||||
|
elements: elements,
|
||||||
|
guildId: '',
|
||||||
|
isOnlineMsg: false,
|
||||||
|
msgId: '7467703692092974645', // TODO: no necessary
|
||||||
|
msgRandom: '0',
|
||||||
|
msgSeq: String(msg.contentHead.sequence ?? 0),
|
||||||
|
msgTime: String(msg.contentHead.timeStamp ?? 0),
|
||||||
|
msgType: NTMsgType.KMSGTYPEMIX,
|
||||||
|
parentMsgIdList: [],
|
||||||
|
parentMsgPeer: {
|
||||||
|
chatType: ChatType.KCHATTYPEGROUP,
|
||||||
|
peerUid: String(msg?.responseHead.grp?.groupUin ?? 0),
|
||||||
|
},
|
||||||
|
peerName: '',
|
||||||
|
peerUid: '1094950020',
|
||||||
|
peerUin: '1094950020',
|
||||||
|
recallTime: '0',
|
||||||
|
records: [],
|
||||||
|
sendNickName: msg?.responseHead.grp?.memberName ?? '',
|
||||||
|
sendRemarkName: msg?.responseHead.grp?.memberName ?? '',
|
||||||
|
senderUid: '',
|
||||||
|
senderUin: '1094950020',
|
||||||
|
sourceType: MsgSourceType.K_DOWN_SOURCETYPE_UNKNOWN,
|
||||||
|
subMsgType: 1,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
return await Promise.all(messagesPromises);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
import {
|
import {
|
||||||
Peer,
|
|
||||||
ChatType,
|
ChatType,
|
||||||
ElementType,
|
ElementType,
|
||||||
MessageElement,
|
MessageElement,
|
||||||
|
Peer,
|
||||||
RawMessage,
|
RawMessage,
|
||||||
SendArkElement,
|
SendArkElement,
|
||||||
SendFaceElement,
|
SendFaceElement,
|
||||||
@@ -32,6 +32,8 @@ import {
|
|||||||
PacketMultiMsgElement
|
PacketMultiMsgElement
|
||||||
} from '@/core/packet/message/element';
|
} from '@/core/packet/message/element';
|
||||||
import {PacketMsg, PacketSendMsgElement} from '@/core/packet/message/message';
|
import {PacketMsg, PacketSendMsgElement} from '@/core/packet/message/message';
|
||||||
|
import {NapProtoDecodeStructType} from '@napneko/nap-proto-core';
|
||||||
|
import {Elem} from '@/core/packet/transformer/proto';
|
||||||
|
|
||||||
const SupportedElementTypes = [
|
const SupportedElementTypes = [
|
||||||
ElementType.TEXT,
|
ElementType.TEXT,
|
||||||
@@ -154,4 +156,16 @@ export class PacketMsgConverter {
|
|||||||
}).filter((e) => e !== null)
|
}).filter((e) => e !== null)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
packetMsgToRaw(msg: NapProtoDecodeStructType<typeof Elem>[]): [MessageElement, NapProtoDecodeStructType<typeof Elem> | null][] {
|
||||||
|
const converters = [PacketMsgTextElement.parseElement,
|
||||||
|
PacketMsgAtElement.parseElement, PacketMsgReplyElement.parseElement, PacketMsgPicElement.parseElement];
|
||||||
|
return msg.map((element) => {
|
||||||
|
for (const converter of converters) {
|
||||||
|
const result = converter(element);
|
||||||
|
if (result) return result;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}).filter((e) => e !== null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,20 +1,22 @@
|
|||||||
import * as zlib from 'node:zlib';
|
import * as zlib from 'node:zlib';
|
||||||
import { NapProtoEncodeStructType, NapProtoMsg } from '@napneko/nap-proto-core';
|
import {NapProtoDecodeStructType, NapProtoEncodeStructType, NapProtoMsg} from '@napneko/nap-proto-core';
|
||||||
import {
|
import {
|
||||||
CustomFace,
|
CustomFace,
|
||||||
Elem,
|
Elem,
|
||||||
|
FileExtra,
|
||||||
|
GroupFileExtra,
|
||||||
MarkdownData,
|
MarkdownData,
|
||||||
MentionExtra,
|
MentionExtra,
|
||||||
|
MsgInfo,
|
||||||
NotOnlineImage,
|
NotOnlineImage,
|
||||||
|
OidbSvcTrpcTcp0XE37_800Response,
|
||||||
QBigFaceExtra,
|
QBigFaceExtra,
|
||||||
QSmallFaceExtra,
|
QSmallFaceExtra,
|
||||||
MsgInfo,
|
|
||||||
OidbSvcTrpcTcp0XE37_800Response,
|
|
||||||
FileExtra,
|
|
||||||
GroupFileExtra
|
|
||||||
} from '@/core/packet/transformer/proto';
|
} from '@/core/packet/transformer/proto';
|
||||||
import {
|
import {
|
||||||
|
ElementType,
|
||||||
FaceType,
|
FaceType,
|
||||||
|
MessageElement,
|
||||||
NTMsgAtType,
|
NTMsgAtType,
|
||||||
PicType,
|
PicType,
|
||||||
SendArkElement,
|
SendArkElement,
|
||||||
@@ -32,6 +34,9 @@ import {
|
|||||||
import {ForwardMsgBuilder} from '@/common/forward-msg-builder';
|
import {ForwardMsgBuilder} from '@/common/forward-msg-builder';
|
||||||
import {PacketMsg, PacketSendMsgElement} from '@/core/packet/message/message';
|
import {PacketMsg, PacketSendMsgElement} from '@/core/packet/message/message';
|
||||||
|
|
||||||
|
export type ParseElementFnR = [MessageElement, NapProtoDecodeStructType<typeof Elem> | null] | undefined;
|
||||||
|
type ParseElementFn = (elem: NapProtoDecodeStructType<typeof Elem>) => ParseElementFnR;
|
||||||
|
|
||||||
// raw <-> packet
|
// raw <-> packet
|
||||||
// TODO: SendStructLongMsgElement
|
// TODO: SendStructLongMsgElement
|
||||||
export abstract class IPacketMsgElement<T extends PacketSendMsgElement> {
|
export abstract class IPacketMsgElement<T extends PacketSendMsgElement> {
|
||||||
@@ -51,6 +56,8 @@ export abstract class IPacketMsgElement<T extends PacketSendMsgElement> {
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static parseElement: ParseElementFn;
|
||||||
|
|
||||||
toPreview(): string {
|
toPreview(): string {
|
||||||
return '[暂不支持该消息类型喵~]';
|
return '[暂不支持该消息类型喵~]';
|
||||||
}
|
}
|
||||||
@@ -72,10 +79,29 @@ export class PacketMsgTextElement extends IPacketMsgElement<SendTextElement> {
|
|||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static override parseElement = (elem: NapProtoDecodeStructType<typeof Elem>): ParseElementFnR => {
|
||||||
|
if (elem.text?.str && (elem.text?.attr6Buf === undefined || elem.text?.attr6Buf?.length === 0)) {
|
||||||
|
return [{
|
||||||
|
textElement: {
|
||||||
|
content: elem.text?.str,
|
||||||
|
atType: NTMsgAtType.ATTYPEUNKNOWN,
|
||||||
|
atUid: '',
|
||||||
|
atTinyId: '',
|
||||||
|
atNtUid: '',
|
||||||
|
},
|
||||||
|
elementType: ElementType.UNKNOWN,
|
||||||
|
elementId: '',
|
||||||
|
}, null];
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
};
|
||||||
|
|
||||||
override toPreview(): string {
|
override toPreview(): string {
|
||||||
return this.text;
|
return this.text;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
export class PacketMsgAtElement extends PacketMsgTextElement {
|
export class PacketMsgAtElement extends PacketMsgTextElement {
|
||||||
targetUid: string;
|
targetUid: string;
|
||||||
@@ -101,6 +127,22 @@ export class PacketMsgAtElement extends PacketMsgTextElement {
|
|||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
static override parseElement = (elem: NapProtoDecodeStructType<typeof Elem>): ParseElementFnR => {
|
||||||
|
if (elem.text?.str && (elem.text?.attr6Buf?.length ?? 100) >= 11) {
|
||||||
|
return [{
|
||||||
|
textElement: {
|
||||||
|
content: elem.text?.str,
|
||||||
|
atType: NTMsgAtType.ATTYPEONE,
|
||||||
|
atUid: String(Buffer.from(elem.text!.attr6Buf!).readUInt32BE(7)), // FIXME: hack
|
||||||
|
atTinyId: '',
|
||||||
|
atNtUid: '',
|
||||||
|
},
|
||||||
|
elementType: ElementType.UNKNOWN,
|
||||||
|
elementId: '',
|
||||||
|
}, null];
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export class PacketMsgReplyElement extends IPacketMsgElement<SendReplyElement> {
|
export class PacketMsgReplyElement extends IPacketMsgElement<SendReplyElement> {
|
||||||
@@ -152,6 +194,22 @@ export class PacketMsgReplyElement extends IPacketMsgElement<SendReplyElement> {
|
|||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static override parseElement = (elem: NapProtoDecodeStructType<typeof Elem>): ParseElementFnR => {
|
||||||
|
if (elem.srcMsg && elem.srcMsg.pbReserve) {
|
||||||
|
const reserve = elem.srcMsg.pbReserve;
|
||||||
|
return [{
|
||||||
|
replyElement: {
|
||||||
|
replayMsgSeq: String(reserve.friendSeq ?? elem.srcMsg?.origSeqs?.[0] ?? 0),
|
||||||
|
replayMsgId: String(reserve.messageId ?? 0),
|
||||||
|
senderUin: String(elem?.srcMsg ?? 0)
|
||||||
|
},
|
||||||
|
elementType: ElementType.UNKNOWN,
|
||||||
|
elementId: '',
|
||||||
|
}, null];
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
};
|
||||||
|
|
||||||
override toPreview(): string {
|
override toPreview(): string {
|
||||||
return '[回复消息]';
|
return '[回复消息]';
|
||||||
}
|
}
|
||||||
@@ -207,6 +265,46 @@ export class PacketMsgFaceElement extends IPacketMsgElement<SendFaceElement> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static override parseElement = (elem: NapProtoDecodeStructType<typeof Elem>): ParseElementFnR => {
|
||||||
|
if (elem.face?.index) {
|
||||||
|
return [{
|
||||||
|
faceElement: {
|
||||||
|
faceIndex: elem.face.index,
|
||||||
|
faceType: FaceType.Normal
|
||||||
|
},
|
||||||
|
elementType: ElementType.UNKNOWN,
|
||||||
|
elementId: '',
|
||||||
|
}, null];
|
||||||
|
}
|
||||||
|
if (elem?.commonElem?.serviceType === 37 && elem?.commonElem?.pbElem) {
|
||||||
|
const qface = new NapProtoMsg(QBigFaceExtra).decode(elem?.commonElem?.pbElem);
|
||||||
|
if (qface?.faceId) {
|
||||||
|
return [{
|
||||||
|
faceElement: {
|
||||||
|
faceIndex: qface.faceId,
|
||||||
|
faceType: FaceType.Normal
|
||||||
|
},
|
||||||
|
elementType: ElementType.UNKNOWN,
|
||||||
|
elementId: '',
|
||||||
|
}, null];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (elem?.commonElem?.serviceType === 33 && elem?.commonElem?.pbElem) {
|
||||||
|
const qface = new NapProtoMsg(QSmallFaceExtra).decode(elem?.commonElem?.pbElem);
|
||||||
|
if (qface?.faceId) {
|
||||||
|
return [{
|
||||||
|
faceElement: {
|
||||||
|
faceIndex: qface.faceId,
|
||||||
|
faceType: FaceType.Normal
|
||||||
|
},
|
||||||
|
elementType: ElementType.UNKNOWN,
|
||||||
|
elementId: '',
|
||||||
|
}, null];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
};
|
||||||
|
|
||||||
override toPreview(): string {
|
override toPreview(): string {
|
||||||
return '[表情]';
|
return '[表情]';
|
||||||
}
|
}
|
||||||
@@ -295,6 +393,60 @@ export class PacketMsgPicElement extends IPacketMsgElement<SendPicElement> {
|
|||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static override parseElement = (elem: NapProtoDecodeStructType<typeof Elem>): ParseElementFnR => {
|
||||||
|
if (elem?.commonElem?.serviceType === 48 || [10, 20].includes(elem?.commonElem?.businessType ?? 0)) {
|
||||||
|
const extra = new NapProtoMsg(MsgInfo).decode(elem.commonElem!.pbElem!);
|
||||||
|
const msgInfoBody = extra.msgInfoBody[0];
|
||||||
|
const index = msgInfoBody?.index;
|
||||||
|
return [{
|
||||||
|
picElement: {
|
||||||
|
fileSize: index?.info.fileSize ?? 0,
|
||||||
|
picWidth: index?.info?.width ?? 0,
|
||||||
|
picHeight: index?.info?.height ?? 0,
|
||||||
|
fileName: index?.info?.fileHash ?? '',
|
||||||
|
sourcePath: '',
|
||||||
|
original: false,
|
||||||
|
picType: PicType.NEWPIC_APNG,
|
||||||
|
fileUuid: '',
|
||||||
|
fileSubId: '',
|
||||||
|
thumbFileSize: 0,
|
||||||
|
summary: '[图片]',
|
||||||
|
thumbPath: new Map(),
|
||||||
|
},
|
||||||
|
elementType: ElementType.UNKNOWN,
|
||||||
|
elementId: '',
|
||||||
|
}, elem];
|
||||||
|
}
|
||||||
|
if (elem?.notOnlineImage) {
|
||||||
|
const img = elem?.notOnlineImage; // url in originImageUrl
|
||||||
|
const preImg: MessageElement = {
|
||||||
|
picElement: {
|
||||||
|
fileSize: img.fileLen ?? 0,
|
||||||
|
picWidth: img.picWidth ?? 0,
|
||||||
|
picHeight: img.picHeight ?? 0,
|
||||||
|
fileName: Buffer.from(img.picMd5!).toString('hex') ?? '',
|
||||||
|
sourcePath: '',
|
||||||
|
original: false,
|
||||||
|
picType: PicType.NEWPIC_APNG,
|
||||||
|
fileUuid: '',
|
||||||
|
fileSubId: '',
|
||||||
|
thumbFileSize: 0,
|
||||||
|
summary: '[图片]',
|
||||||
|
thumbPath: new Map(),
|
||||||
|
},
|
||||||
|
elementType: ElementType.UNKNOWN,
|
||||||
|
elementId: '',
|
||||||
|
};
|
||||||
|
if (img.origUrl?.includes('&fileid=')) {
|
||||||
|
preImg.picElement!.originImageUrl = `https://multimedia.nt.qq.com.cn${img.origUrl}`;
|
||||||
|
} else {
|
||||||
|
preImg.picElement!.originImageUrl = `https://gchat.qpic.cn${img.origUrl}`;
|
||||||
|
}
|
||||||
|
return [preImg, elem];
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
};
|
||||||
|
|
||||||
override toPreview(): string {
|
override toPreview(): string {
|
||||||
return this.summary;
|
return this.summary;
|
||||||
}
|
}
|
||||||
|
50
src/core/packet/transformer/highway/DownloadGroupImage.ts
Normal file
50
src/core/packet/transformer/highway/DownloadGroupImage.ts
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
import * as proto from '@/core/packet/transformer/proto';
|
||||||
|
import { NapProtoEncodeStructType, NapProtoMsg } from '@napneko/nap-proto-core';
|
||||||
|
import { OidbPacket, PacketTransformer } from '@/core/packet/transformer/base';
|
||||||
|
import OidbBase from '@/core/packet/transformer/oidb/oidbBase';
|
||||||
|
import { IndexNode } from '@/core/packet/transformer/proto';
|
||||||
|
|
||||||
|
class DownloadGroupImage extends PacketTransformer<typeof proto.NTV2RichMediaResp> {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
build(group_uin: number, node: NapProtoEncodeStructType<typeof IndexNode>): OidbPacket {
|
||||||
|
const body = new NapProtoMsg(proto.NTV2RichMediaReq).encode({
|
||||||
|
reqHead: {
|
||||||
|
common: {
|
||||||
|
requestId: 1,
|
||||||
|
command: 200
|
||||||
|
},
|
||||||
|
scene: {
|
||||||
|
requestType: 2,
|
||||||
|
businessType: 1,
|
||||||
|
sceneType: 2,
|
||||||
|
group: {
|
||||||
|
groupUin: group_uin
|
||||||
|
}
|
||||||
|
},
|
||||||
|
client: {
|
||||||
|
agentType: 2,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
download: {
|
||||||
|
node: node,
|
||||||
|
download: {
|
||||||
|
video: {
|
||||||
|
busiType: 0,
|
||||||
|
sceneType: 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return OidbBase.build(0x11C4, 200, body, true, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
parse(data: Buffer) {
|
||||||
|
const oidbBody = OidbBase.parse(data).body;
|
||||||
|
return new NapProtoMsg(proto.NTV2RichMediaResp).decode(oidbBody);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default new DownloadGroupImage();
|
@@ -14,7 +14,7 @@ class DownloadImage extends PacketTransformer<typeof proto.NTV2RichMediaResp> {
|
|||||||
reqHead: {
|
reqHead: {
|
||||||
common: {
|
common: {
|
||||||
requestId: 1,
|
requestId: 1,
|
||||||
command: 100
|
command: 200
|
||||||
},
|
},
|
||||||
scene: {
|
scene: {
|
||||||
requestType: 2,
|
requestType: 2,
|
||||||
|
@@ -12,3 +12,4 @@ export { default as UploadPrivateImage } from './UploadPrivateImage';
|
|||||||
export { default as UploadPrivatePtt } from './UploadPrivatePtt';
|
export { default as UploadPrivatePtt } from './UploadPrivatePtt';
|
||||||
export { default as UploadPrivateVideo } from './UploadPrivateVideo';
|
export { default as UploadPrivateVideo } from './UploadPrivateVideo';
|
||||||
export { default as DownloadImage } from './DownloadImage';
|
export { default as DownloadImage } from './DownloadImage';
|
||||||
|
export { default as DownloadGroupImage } from './DownloadGroupImage';
|
||||||
|
37
src/core/packet/transformer/message/DownloadForwardMsg.ts
Normal file
37
src/core/packet/transformer/message/DownloadForwardMsg.ts
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
import * as proto from '@/core/packet/transformer/proto';
|
||||||
|
import { NapProtoMsg } from '@napneko/nap-proto-core';
|
||||||
|
import { OidbPacket, PacketHexStrBuilder, PacketTransformer } from '@/core/packet/transformer/base';
|
||||||
|
|
||||||
|
class DownloadForwardMsg extends PacketTransformer<typeof proto.RecvLongMsgResp> {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
build(uid: string, resId: string): OidbPacket {
|
||||||
|
const req = new NapProtoMsg(proto.RecvLongMsgReq).encode({
|
||||||
|
info: {
|
||||||
|
uid: {
|
||||||
|
uid: uid
|
||||||
|
},
|
||||||
|
resId: resId,
|
||||||
|
acquire: true
|
||||||
|
},
|
||||||
|
settings: {
|
||||||
|
field1: 2,
|
||||||
|
field2: 0,
|
||||||
|
field3: 0,
|
||||||
|
field4: 0
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return {
|
||||||
|
cmd: 'trpc.group.long_msg_interface.MsgService.SsoRecvLongMsg',
|
||||||
|
data: PacketHexStrBuilder(req)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
parse(data: Buffer) {
|
||||||
|
return new NapProtoMsg(proto.RecvLongMsgResp).decode(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default new DownloadForwardMsg();
|
@@ -1 +1,2 @@
|
|||||||
export { default as UploadForwardMsg } from './UploadForwardMsg';
|
export { default as UploadForwardMsg } from './UploadForwardMsg';
|
||||||
|
export { default as DownloadForwardMsg } from './DownloadForwardMsg';
|
@@ -2,7 +2,7 @@ import { ProtoField, ScalarType } from '@napneko/nap-proto-core';
|
|||||||
import { PushMsgBody } from '@/core/packet/transformer/proto';
|
import { PushMsgBody } from '@/core/packet/transformer/proto';
|
||||||
|
|
||||||
export const LongMsgResult = {
|
export const LongMsgResult = {
|
||||||
action: ProtoField(2, () => LongMsgAction)
|
action: ProtoField(2, () => LongMsgAction, false, true)
|
||||||
};
|
};
|
||||||
|
|
||||||
export const LongMsgAction = {
|
export const LongMsgAction = {
|
||||||
|
@@ -3,6 +3,7 @@ import { OB11Message, OB11MessageData, OB11MessageDataType, OB11MessageForward,
|
|||||||
import { ActionName } from '@/onebot/action/router';
|
import { ActionName } from '@/onebot/action/router';
|
||||||
import { MessageUnique } from '@/common/message-unique';
|
import { MessageUnique } from '@/common/message-unique';
|
||||||
import { Static, Type } from '@sinclair/typebox';
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
import { ChatType, ElementType, MsgSourceType, NTMsgType, RawMessage } from '@/core';
|
||||||
|
|
||||||
const SchemaData = Type.Object({
|
const SchemaData = Type.Object({
|
||||||
message_id: Type.Optional(Type.Union([Type.Number(), Type.String()])),
|
message_id: Type.Optional(Type.Union([Type.Number(), Type.String()])),
|
||||||
@@ -57,24 +58,72 @@ export class GoCQHTTPGetForwardMsgAction extends OneBotAction<Payload, {
|
|||||||
throw new Error('message_id is required');
|
throw new Error('message_id is required');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const fakeForwardMsg = (res_id: string) => {
|
||||||
|
return {
|
||||||
|
chatType: ChatType.KCHATTYPEGROUP,
|
||||||
|
elements: [{
|
||||||
|
elementType: ElementType.MULTIFORWARD,
|
||||||
|
elementId: '',
|
||||||
|
multiForwardMsgElement: {
|
||||||
|
resId: res_id,
|
||||||
|
fileName: '',
|
||||||
|
xmlContent: '',
|
||||||
|
}
|
||||||
|
}],
|
||||||
|
guildId: '',
|
||||||
|
isOnlineMsg: false,
|
||||||
|
msgId: '', // TODO: no necessary
|
||||||
|
msgRandom: '0',
|
||||||
|
msgSeq: '',
|
||||||
|
msgTime: '',
|
||||||
|
msgType: NTMsgType.KMSGTYPEMIX,
|
||||||
|
parentMsgIdList: [],
|
||||||
|
parentMsgPeer: {
|
||||||
|
chatType: ChatType.KCHATTYPEGROUP,
|
||||||
|
peerUid: '',
|
||||||
|
},
|
||||||
|
peerName: '',
|
||||||
|
peerUid: '284840486',
|
||||||
|
peerUin: '284840486',
|
||||||
|
recallTime: '0',
|
||||||
|
records: [],
|
||||||
|
sendNickName: '',
|
||||||
|
sendRemarkName: '',
|
||||||
|
senderUid: '',
|
||||||
|
senderUin: '1094950020',
|
||||||
|
sourceType: MsgSourceType.K_DOWN_SOURCETYPE_UNKNOWN,
|
||||||
|
subMsgType: 1,
|
||||||
|
} as RawMessage;
|
||||||
|
};
|
||||||
|
|
||||||
|
const protocolFallbackLogic = async (res_id: string) => {
|
||||||
|
const ob = (await this.obContext.apis.MsgApi.parseMessageV2(fakeForwardMsg(res_id)))?.arrayMsg;
|
||||||
|
if (ob) {
|
||||||
|
return {
|
||||||
|
messages: (ob?.message?.[0] as OB11MessageForward)?.data?.content
|
||||||
|
};
|
||||||
|
}
|
||||||
|
throw new Error('protocolFallbackLogic: 找不到相关的聊天记录');
|
||||||
|
};
|
||||||
|
|
||||||
const rootMsgId = MessageUnique.getShortIdByMsgId(msgId.toString());
|
const rootMsgId = MessageUnique.getShortIdByMsgId(msgId.toString());
|
||||||
const rootMsg = MessageUnique.getMsgIdAndPeerByShortId(rootMsgId ?? +msgId);
|
const rootMsg = MessageUnique.getMsgIdAndPeerByShortId(rootMsgId ?? +msgId);
|
||||||
if (!rootMsg) {
|
if (!rootMsg) {
|
||||||
throw new Error('msg not found');
|
return await protocolFallbackLogic(msgId.toString());
|
||||||
}
|
}
|
||||||
const data = await this.core.apis.MsgApi.getMsgsByMsgId(rootMsg.Peer, [rootMsg.MsgId]);
|
const data = await this.core.apis.MsgApi.getMsgsByMsgId(rootMsg.Peer, [rootMsg.MsgId]);
|
||||||
|
|
||||||
if (!data || data.result !== 0) {
|
if (!data || data.result !== 0) {
|
||||||
throw new Error('找不到相关的聊天记录' + data?.errMsg);
|
return await protocolFallbackLogic(msgId.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
const singleMsg = data.msgList[0];
|
const singleMsg = data.msgList[0];
|
||||||
if (!singleMsg) {
|
if (!singleMsg) {
|
||||||
throw new Error('找不到相关的聊天记录');
|
return await protocolFallbackLogic(msgId.toString());
|
||||||
}
|
}
|
||||||
const resMsg = (await this.obContext.apis.MsgApi.parseMessageV2(singleMsg))?.arrayMsg;//强制array 以便处理
|
const resMsg = (await this.obContext.apis.MsgApi.parseMessageV2(singleMsg))?.arrayMsg;//强制array 以便处理
|
||||||
if (!(resMsg?.message?.[0] as OB11MessageForward)?.data?.content) {
|
if (!(resMsg?.message?.[0] as OB11MessageForward)?.data?.content) {
|
||||||
throw new Error('找不到相关的聊天记录');
|
return await protocolFallbackLogic(msgId.toString());
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
messages: (resMsg?.message?.[0] as OB11MessageForward)?.data?.content
|
messages: (resMsg?.message?.[0] as OB11MessageForward)?.data?.content
|
||||||
|
@@ -1,25 +1,34 @@
|
|||||||
import {FileNapCatOneBotUUID} from '@/common/file-uuid';
|
import {FileNapCatOneBotUUID} from '@/common/file-uuid';
|
||||||
import {MessageUnique} from '@/common/message-unique';
|
import {MessageUnique} from '@/common/message-unique';
|
||||||
import {
|
import {
|
||||||
NTMsgAtType,
|
|
||||||
ChatType,
|
ChatType,
|
||||||
CustomMusicSignPostData,
|
CustomMusicSignPostData,
|
||||||
ElementType,
|
ElementType,
|
||||||
FaceIndex,
|
FaceIndex,
|
||||||
|
FaceType,
|
||||||
|
GrayTipElement,
|
||||||
|
GroupNotify,
|
||||||
IdMusicSignPostData,
|
IdMusicSignPostData,
|
||||||
MessageElement,
|
MessageElement,
|
||||||
NapCatCore,
|
NapCatCore,
|
||||||
NTGrayTipElementSubTypeV2,
|
NTGrayTipElementSubTypeV2,
|
||||||
|
NTMsgAtType,
|
||||||
Peer,
|
Peer,
|
||||||
RawMessage,
|
RawMessage,
|
||||||
SendMessageElement,
|
SendMessageElement,
|
||||||
SendTextElement,
|
SendTextElement,
|
||||||
FaceType,
|
|
||||||
GrayTipElement,
|
|
||||||
GroupNotify,
|
|
||||||
} from '@/core';
|
} from '@/core';
|
||||||
import faceConfig from '@/core/external/face_config.json';
|
import faceConfig from '@/core/external/face_config.json';
|
||||||
import { NapCatOneBot11Adapter, OB11Message, OB11MessageData, OB11MessageDataType, OB11MessageFileBase, OB11MessageForward, OB11MessageImage, OB11MessageVideo, } from '@/onebot';
|
import {
|
||||||
|
NapCatOneBot11Adapter,
|
||||||
|
OB11Message,
|
||||||
|
OB11MessageData,
|
||||||
|
OB11MessageDataType,
|
||||||
|
OB11MessageFileBase,
|
||||||
|
OB11MessageForward,
|
||||||
|
OB11MessageImage,
|
||||||
|
OB11MessageVideo,
|
||||||
|
} from '@/onebot';
|
||||||
import {OB11Construct} from '@/onebot/helper/data';
|
import {OB11Construct} from '@/onebot/helper/data';
|
||||||
import {EventType} from '@/onebot/event/OneBotEvent';
|
import {EventType} from '@/onebot/event/OneBotEvent';
|
||||||
import {encodeCQCode} from '@/onebot/helper/cqcode';
|
import {encodeCQCode} from '@/onebot/helper/cqcode';
|
||||||
@@ -30,7 +39,7 @@ import { OB11FriendAddNoticeEvent } from '@/onebot/event/notice/OB11FriendAddNot
|
|||||||
import {ForwardMsgBuilder} from '@/common/forward-msg-builder';
|
import {ForwardMsgBuilder} from '@/common/forward-msg-builder';
|
||||||
import {NapProtoMsg} from '@napneko/nap-proto-core';
|
import {NapProtoMsg} from '@napneko/nap-proto-core';
|
||||||
import {OB11GroupIncreaseEvent} from '../event/notice/OB11GroupIncreaseEvent';
|
import {OB11GroupIncreaseEvent} from '../event/notice/OB11GroupIncreaseEvent';
|
||||||
import { OB11GroupDecreaseEvent, GroupDecreaseSubType } from '../event/notice/OB11GroupDecreaseEvent';
|
import {GroupDecreaseSubType, OB11GroupDecreaseEvent} from '../event/notice/OB11GroupDecreaseEvent';
|
||||||
import {GroupAdmin} from '@/core/packet/transformer/proto/message/groupAdmin';
|
import {GroupAdmin} from '@/core/packet/transformer/proto/message/groupAdmin';
|
||||||
import {OB11GroupAdminNoticeEvent} from '../event/notice/OB11GroupAdminNoticeEvent';
|
import {OB11GroupAdminNoticeEvent} from '../event/notice/OB11GroupAdminNoticeEvent';
|
||||||
import {GroupChange, GroupChangeInfo, GroupInvite, PushMsgBody} from '@/core/packet/transformer/proto';
|
import {GroupChange, GroupChangeInfo, GroupInvite, PushMsgBody} from '@/core/packet/transformer/proto';
|
||||||
@@ -264,7 +273,6 @@ export class OneBotMsgApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 丢弃该消息段
|
// 丢弃该消息段
|
||||||
if (!replyMsg || records.msgRandom !== replyMsg.msgRandom) {
|
if (!replyMsg || records.msgRandom !== replyMsg.msgRandom) {
|
||||||
this.core.context.logger.logError(
|
this.core.context.logger.logError(
|
||||||
@@ -355,15 +363,22 @@ export class OneBotMsgApi {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
multiForwardMsgElement: async (_, msg, _wrapper, context) => {
|
multiForwardMsgElement: async (element, msg, _wrapper, context) => {
|
||||||
const parentMsgPeer = msg.parentMsgPeer ?? {
|
const parentMsgPeer = msg.parentMsgPeer ?? {
|
||||||
chatType: msg.chatType,
|
chatType: msg.chatType,
|
||||||
guildId: '',
|
guildId: '',
|
||||||
peerUid: msg.peerUid,
|
peerUid: msg.peerUid,
|
||||||
};
|
};
|
||||||
const multiMsgs = await this.getMultiMessages(msg, parentMsgPeer);
|
let multiMsgs = await this.getMultiMessages(msg, parentMsgPeer);
|
||||||
// 拉取失败则跳过
|
// 拉取失败则跳过
|
||||||
if (!multiMsgs) return null;
|
if (!multiMsgs || multiMsgs.length === 0) {
|
||||||
|
try {
|
||||||
|
multiMsgs = await this.core.apis.PacketApi.pkt.operation.FetchForwardMsg(element.resId);
|
||||||
|
} catch (e) {
|
||||||
|
this.core.context.logger.logError('Protocol FetchForwardMsg fallback failed!', e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
const forward: OB11MessageForward = {
|
const forward: OB11MessageForward = {
|
||||||
type: OB11MessageDataType.forward,
|
type: OB11MessageDataType.forward,
|
||||||
data: {id: msg.msgId}
|
data: {id: msg.msgId}
|
||||||
@@ -692,7 +707,10 @@ export class OneBotMsgApi {
|
|||||||
if (grayTipElement.subElementType == NTGrayTipElementSubTypeV2.GRAYTIP_ELEMENT_SUBTYPE_JSON) {
|
if (grayTipElement.subElementType == NTGrayTipElementSubTypeV2.GRAYTIP_ELEMENT_SUBTYPE_JSON) {
|
||||||
if (grayTipElement.jsonGrayTipElement.busiId == 1061) {
|
if (grayTipElement.jsonGrayTipElement.busiId == 1061) {
|
||||||
const PokeEvent = await this.obContext.apis.FriendApi.parsePrivatePokeEvent(grayTipElement, Number(await this.core.apis.UserApi.getUinByUidV2(msg.peerUid)));
|
const PokeEvent = await this.obContext.apis.FriendApi.parsePrivatePokeEvent(grayTipElement, Number(await this.core.apis.UserApi.getUinByUidV2(msg.peerUid)));
|
||||||
if (PokeEvent) { return PokeEvent; };
|
if (PokeEvent) {
|
||||||
|
return PokeEvent;
|
||||||
|
}
|
||||||
|
;
|
||||||
} else if (grayTipElement.jsonGrayTipElement.busiId == 19324 && msg.peerUid !== '') {
|
} else if (grayTipElement.jsonGrayTipElement.busiId == 19324 && msg.peerUid !== '') {
|
||||||
return new OB11FriendAddNoticeEvent(this.core, Number(await this.core.apis.UserApi.getUinByUidV2(msg.peerUid)));
|
return new OB11FriendAddNoticeEvent(this.core, Number(await this.core.apis.UserApi.getUinByUidV2(msg.peerUid)));
|
||||||
}
|
}
|
||||||
@@ -998,6 +1016,7 @@ export class OneBotMsgApi {
|
|||||||
return {path, fileName: inputdata.name ?? fileName};
|
return {path, fileName: inputdata.name ?? fileName};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async handleObfuckName(name: string) {
|
async handleObfuckName(name: string) {
|
||||||
const contextMsgFile = FileNapCatOneBotUUID.decode(name);
|
const contextMsgFile = FileNapCatOneBotUUID.decode(name);
|
||||||
if (contextMsgFile && contextMsgFile.msgId && contextMsgFile.elementId) {
|
if (contextMsgFile && contextMsgFile.msgId && contextMsgFile.elementId) {
|
||||||
@@ -1021,6 +1040,7 @@ export class OneBotMsgApi {
|
|||||||
}
|
}
|
||||||
throw new Error('文件名解析失败');
|
throw new Error('文件名解析失败');
|
||||||
}
|
}
|
||||||
|
|
||||||
groupChangDecreseType2String(type: number): GroupDecreaseSubType {
|
groupChangDecreseType2String(type: number): GroupDecreaseSubType {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 130:
|
case 130:
|
||||||
|
Reference in New Issue
Block a user