style: lint

This commit is contained in:
手瓜一十雪
2024-10-15 09:06:47 +08:00
parent 964874bdad
commit 030ba15952
27 changed files with 167 additions and 167 deletions

View File

@@ -1,9 +1,9 @@
import {LogWrapper} from "@/common/log";
import {LRUCache} from "@/common/lru-cache";
import WebSocket, {Data} from "ws";
import crypto, {createHash} from "crypto";
import {NapCatCore} from "@/core";
import {PacketHexStr} from "@/core/packet/packer";
import { LogWrapper } from "@/common/log";
import { LRUCache } from "@/common/lru-cache";
import WebSocket, { Data } from "ws";
import crypto, { createHash } from "crypto";
import { NapCatCore } from "@/core";
import { PacketHexStr } from "@/core/packet/packer";
export interface RecvPacket {
type: string, // 仅recv
@@ -24,7 +24,7 @@ export class PacketClient {
private maxReconnectAttempts: number = 5;
private cb = new LRUCache<string, (json: RecvPacketData) => Promise<void>>(500); // trace_id-type callback
private readonly clientUrl: string = '';
private readonly napCatCore: NapCatCore
private readonly napCatCore: NapCatCore;
private readonly logger: LogWrapper;
constructor(url: string, core: NapCatCore) {
@@ -39,7 +39,7 @@ export class PacketClient {
private randText(len: number) {
let text = '';
let possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
for (let i = 0; i < len; i++) {
text += possible.charAt(Math.floor(Math.random() * possible.length));
}
@@ -147,10 +147,10 @@ export class PacketClient {
private async handleMessage(message: Data): Promise<void> {
try {
let json: RecvPacket = JSON.parse(message.toString());
let trace_id_md5 = json.trace_id_md5;
let action = json?.type ?? 'init';
let event = this.cb.get(trace_id_md5 + action);
const json: RecvPacket = JSON.parse(message.toString());
const trace_id_md5 = json.trace_id_md5;
const action = json?.type ?? 'init';
const event = this.cb.get(trace_id_md5 + action);
if (event) {
await event(json.data);
}
@@ -168,8 +168,8 @@ export class PacketClient {
this.logger.logError('NapCat.Packet is not init');
return undefined;
}
let md5 = crypto.createHash('md5').update(data).digest('hex');
let trace_id = (this.randText(4) + md5 + data).slice(0, data.length / 2);
const md5 = crypto.createHash('md5').update(data).digest('hex');
const trace_id = (this.randText(4) + md5 + data).slice(0, data.length / 2);
this.sendCommand(cmd, data, trace_id, rsp, 5000, async () => {
await this.napCatCore.context.session.getMsgService().sendSsoCmdReqByContend(cmd, trace_id);
}).then((res) => resolve(res)).catch((e) => reject(e));

View File

@@ -1,12 +1,12 @@
import {PushMsgBody} from "@/core/packet/proto/message/message";
import {NapProtoEncodeStructType} from "@/core/packet/proto/NapProto";
import { PushMsgBody } from "@/core/packet/proto/message/message";
import { NapProtoEncodeStructType } from "@/core/packet/proto/NapProto";
import * as crypto from "crypto";
import {PacketForwardNode} from "@/core/packet/msg/entity/forward";
import { PacketForwardNode } from "@/core/packet/msg/entity/forward";
export class PacketMsgBuilder {
buildFakeMsg(selfUid: string, element: PacketForwardNode[]): NapProtoEncodeStructType<typeof PushMsgBody>[] {
return element.map((node): NapProtoEncodeStructType<typeof PushMsgBody> => {
const avatar = `https://q.qlogo.cn/headimg_dl?dst_uin=${node.senderId}&spec=640&img_type=jpg`
const avatar = `https://q.qlogo.cn/headimg_dl?dst_uin=${node.senderId}&spec=640&img_type=jpg`;
return {
responseHead: {
fromUid: "",
@@ -46,7 +46,7 @@ export class PacketMsgBuilder {
)
}
}
}
};
});
}
}

View File

@@ -1,5 +1,5 @@
import {NapProtoEncodeStructType, NapProtoMsg} from "@/core/packet/proto/NapProto";
import {Elem, MentionExtra} from "@/core/packet/proto/message/element";
import { NapProtoEncodeStructType, NapProtoMsg } from "@/core/packet/proto/NapProto";
import { Elem, MentionExtra } from "@/core/packet/proto/message/element";
import {
AtType,
SendArkElement,
@@ -54,23 +54,23 @@ export class PacketMsgAtElement extends PacketMsgTextElement {
constructor(element: SendTextElement) {
super(element);
this.targetUid = element.textElement.atNtUid;
this.atAll = element.textElement.atType === AtType.atAll
this.atAll = element.textElement.atType === AtType.atAll;
}
buildElement(): NapProtoEncodeStructType<typeof Elem> {
const res = new NapProtoMsg(MentionExtra).encode({
type: this.atAll ? 1 : 2,
uin: 0,
field5: 0,
uid: this.targetUid,
}
)
type: this.atAll ? 1 : 2,
uin: 0,
field5: 0,
uid: this.targetUid,
}
);
return {
text: {
str: this.text,
pbReserve: res
}
}
};
}
}

View File

@@ -1,5 +1,5 @@
import {IPacketMsgElement} from "@/core/packet/msg/element";
import {SendMessageElement} from "@/core";
import { IPacketMsgElement } from "@/core/packet/msg/element";
import { SendMessageElement } from "@/core";
export interface PacketForwardNode {
groupId?: number

View File

@@ -5,14 +5,14 @@ import { OidbSvcTrpcTcp0X9067_202 } from "@/core/packet/proto/oidb/Oidb.0x9067_2
import { OidbSvcTrpcTcp0X8FC_2, OidbSvcTrpcTcp0X8FC_2_Body } from "@/core/packet/proto/oidb/Oidb.0x8FC_2";
import { OidbSvcTrpcTcp0XFE1_2 } from "@/core/packet/proto/oidb/Oidb.fe1_2";
import { OidbSvcTrpcTcp0XED3_1 } from "@/core/packet/proto/oidb/Oidb.ed3_1";
import {LongMsgResult, SendLongMsgReq} from "@/core/packet/proto/message/action";
import {PacketMsgBuilder} from "@/core/packet/msg/builder";
import {PacketForwardNode} from "@/core/packet/msg/entity/forward";
import { LongMsgResult, SendLongMsgReq } from "@/core/packet/proto/message/action";
import { PacketMsgBuilder } from "@/core/packet/msg/builder";
import { PacketForwardNode } from "@/core/packet/msg/entity/forward";
export type PacketHexStr = string & { readonly hexNya: unique symbol };
export class PacketPacker {
private packetBuilder: PacketMsgBuilder
private packetBuilder: PacketMsgBuilder;
constructor() {
this.packetBuilder = new PacketMsgBuilder();
@@ -79,7 +79,7 @@ export class PacketPacker {
}
packStatusPacket(uin: number): PacketHexStr {
let oidb_0xfe1_2 = new NapProtoMsg(OidbSvcTrpcTcp0XFE1_2).encode({
const oidb_0xfe1_2 = new NapProtoMsg(OidbSvcTrpcTcp0XFE1_2).encode({
uin: uin,
key: [{ key: 27372 }]
});
@@ -98,7 +98,7 @@ export class PacketPacker {
}
}
}
)
);
// console.log("packUploadForwardMsg LONGMSGRESULT!!!", this.toHexStr(longMsgResultData));
const payload = zlib.gzipSync(Buffer.from(longMsgResultData));
// console.log("packUploadForwardMsg PAYLOAD!!!", payload);
@@ -116,7 +116,7 @@ export class PacketPacker {
field1: 4, field2: 1, field3: 7, field4: 0
}
}
)
);
// console.log("packUploadForwardMsg REQ!!!", req);
return this.toHexStr(req);
}

View File

@@ -1,6 +1,6 @@
import {ScalarType} from "@protobuf-ts/runtime";
import {ProtoField} from "../NapProto";
import {PushMsgBody} from "@/core/packet/proto/message/message";
import { ScalarType } from "@protobuf-ts/runtime";
import { ProtoField } from "../NapProto";
import { PushMsgBody } from "@/core/packet/proto/message/message";
export const LongMsgResult = {
action: ProtoField(2, () => LongMsgAction)

View File

@@ -20,7 +20,7 @@ export const Elem = {
srcMsg: ProtoField(45, () => SrcMsg, true),
lightAppElem: ProtoField(51, () => LightAppElem, true),
commonElem: ProtoField(53, () => CommonElem, true),
}
};
export const Text = {
str: ProtoField(1, ScalarType.STRING, true),
@@ -29,7 +29,7 @@ export const Text = {
attr7Buf: ProtoField(4, ScalarType.BYTES, true),
buf: ProtoField(11, ScalarType.BYTES, true),
pbReserve: ProtoField(12, ScalarType.BYTES, true),
}
};
export const Face = {
index: ProtoField(1, ScalarType.INT32, true),
@@ -41,7 +41,7 @@ export const OnlineImage = {
guid: ProtoField(1, ScalarType.BYTES),
filePath: ProtoField(2, ScalarType.BYTES),
oldVerSendFile: ProtoField(3, ScalarType.BYTES),
}
};
export const NotOnlineImage = {
filePath: ProtoField(1, ScalarType.STRING),
@@ -73,7 +73,7 @@ export const NotOnlineImage = {
x400Width: ProtoField(27, ScalarType.INT32),
x400Height: ProtoField(28, ScalarType.INT32),
pbRes: ProtoField(29, () => NotOnlineImage_PbReserve),
}
};
export const NotOnlineImage_PbReserve = {
subType: ProtoField(1, ScalarType.INT32),
@@ -84,7 +84,7 @@ export const NotOnlineImage_PbReserve = {
field20: ProtoField(20, () => NotOnlineImage_PbReserve2),
url: ProtoField(30, ScalarType.STRING),
md5Str: ProtoField(31, ScalarType.STRING),
}
};
export const NotOnlineImage_PbReserve2 = {
field1: ProtoField(1, ScalarType.INT32),
@@ -93,12 +93,12 @@ export const NotOnlineImage_PbReserve2 = {
field4: ProtoField(4, ScalarType.INT32),
field5: ProtoField(5, ScalarType.INT32),
field7: ProtoField(7, ScalarType.STRING),
}
};
export const TransElem = {
elemType: ProtoField(1, ScalarType.INT32),
elemValue: ProtoField(2, ScalarType.BYTES),
}
};
export const MarketFace = {
faceName: ProtoField(1, ScalarType.BYTES),
@@ -114,7 +114,7 @@ export const MarketFace = {
imageHeight: ProtoField(11, ScalarType.INT32),
mobileparam: ProtoField(12, ScalarType.BYTES),
pbReserve: ProtoField(13, ScalarType.BYTES),
}
};
export const CustomFace = {
guid: ProtoField(1, ScalarType.BYTES),
@@ -151,12 +151,12 @@ export const CustomFace = {
x400Width: ProtoField(32, ScalarType.INT32),
x400Height: ProtoField(33, ScalarType.INT32),
pbRes: ProtoField(34, () => CustomFace_PbReserve, true),
}
};
export const CustomFace_PbReserve = {
subType: ProtoField(1, ScalarType.INT32),
summary: ProtoField(9, ScalarType.STRING),
}
};
export const ElemFlags2 = {
colorTextId: ProtoField(1, ScalarType.UINT32),
@@ -173,7 +173,7 @@ export const ElemFlags2 = {
customFont: ProtoField(12, ScalarType.UINT32),
pcSupportDef: ProtoField(13, () => PcSupportDef),
crmFlags: ProtoField(14, ScalarType.UINT32, true),
}
};
export const PcSupportDef = {
pcPtlBegin: ProtoField(1, ScalarType.UINT32),
@@ -182,12 +182,12 @@ export const PcSupportDef = {
macPtlEnd: ProtoField(4, ScalarType.UINT32),
ptlsSupport: ProtoField(5, ScalarType.INT32, false, true),
ptlsNotSupport: ProtoField(6, ScalarType.UINT32, false, true),
}
};
export const Instance = {
appId: ProtoField(1, ScalarType.UINT32),
instId: ProtoField(2, ScalarType.UINT32),
}
};
export const RichMsg = {
template1: ProtoField(1, ScalarType.BYTES, true),
@@ -195,7 +195,7 @@ export const RichMsg = {
msgResId: ProtoField(3, ScalarType.BYTES, true),
rand: ProtoField(4, ScalarType.INT32, true),
seq: ProtoField(5, ScalarType.UINT32, true),
}
};
export const GroupFile = {
filename: ProtoField(1, ScalarType.BYTES),
@@ -208,7 +208,7 @@ export const GroupFile = {
batchItemId: ProtoField(8, ScalarType.BYTES),
feedMsgTime: ProtoField(9, ScalarType.INT32),
pbReserve: ProtoField(10, ScalarType.BYTES),
}
};
export const ExtraInfo = {
nick: ProtoField(1, ScalarType.BYTES),
@@ -223,7 +223,7 @@ export const ExtraInfo = {
msgStateFlag: ProtoField(10, ScalarType.INT32),
apnsSoundType: ProtoField(11, ScalarType.INT32),
newGroupFlag: ProtoField(12, ScalarType.INT32),
}
};
export const VideoFile = {
fileUuid: ProtoField(1, ScalarType.STRING),
@@ -250,7 +250,7 @@ export const VideoFile = {
thumbDownloadFlag: ProtoField(22, ScalarType.INT32),
videoDownloadFlag: ProtoField(23, ScalarType.INT32),
pbReserve: ProtoField(24, ScalarType.BYTES),
}
};
export const AnonymousGroupMessage = {
flags: ProtoField(1, ScalarType.INT32),
@@ -260,7 +260,7 @@ export const AnonymousGroupMessage = {
expireTime: ProtoField(5, ScalarType.INT32),
bubbleId: ProtoField(6, ScalarType.INT32),
rankColor: ProtoField(7, ScalarType.BYTES),
}
};
export const CustomElem = {
desc: ProtoField(1, ScalarType.BYTES),
@@ -268,7 +268,7 @@ export const CustomElem = {
enumType: ProtoField(3, ScalarType.INT32),
ext: ProtoField(4, ScalarType.BYTES),
sound: ProtoField(5, ScalarType.BYTES),
}
};
export const GeneralFlags = {
bubbleDiyTextId: ProtoField(1, ScalarType.INT32),
@@ -304,29 +304,29 @@ export const SrcMsg = {
sourceMsg: ProtoField(9, ScalarType.BYTES, true),
toUin: ProtoField(10, ScalarType.UINT64, true),
troopName: ProtoField(11, ScalarType.BYTES, true),
}
};
export const LightAppElem = {
data: ProtoField(1, ScalarType.BYTES),
msgResid: ProtoField(2, ScalarType.BYTES, true),
}
};
export const CommonElem = {
serviceType: ProtoField(1, ScalarType.INT32),
pbElem: ProtoField(2, ScalarType.BYTES),
businessType: ProtoField(3, ScalarType.UINT32),
}
};
export const FaceExtra = {
faceId: ProtoField(1, ScalarType.INT32, true),
}
};
export const MentionExtra = {
type: ProtoField(3, ScalarType.INT32, true),
uin: ProtoField(4, ScalarType.UINT32, true),
field5: ProtoField(5, ScalarType.INT32, true),
uid: ProtoField(9, ScalarType.STRING, true),
}
};
export const QFaceExtra = {
field1: ProtoField(1, ScalarType.STRING, true),
@@ -337,10 +337,10 @@ export const QFaceExtra = {
field6: ProtoField(6, ScalarType.STRING, true),
preview: ProtoField(7, ScalarType.STRING, true),
field9: ProtoField(9, ScalarType.INT32, true),
}
};
export const QSmallFaceExtra = {
faceId: ProtoField(1, ScalarType.UINT32),
preview: ProtoField(2, ScalarType.STRING),
preview2: ProtoField(3, ScalarType.STRING),
}
};

View File

@@ -1,8 +1,8 @@
import { ScalarType } from "@protobuf-ts/runtime";
import { ProtoField } from "../NapProto";
import {ForwardHead, Grp, GrpTmp, ResponseForward, ResponseGrp, Trans0X211, WPATmp} from "@/core/packet/proto/message/routing";
import {RichText} from "@/core/packet/proto/message/component";
import {C2C} from "@/core/packet/proto/message/c2c";
import { ForwardHead, Grp, GrpTmp, ResponseForward, ResponseGrp, Trans0X211, WPATmp } from "@/core/packet/proto/message/routing";
import { RichText } from "@/core/packet/proto/message/component";
import { C2C } from "@/core/packet/proto/message/c2c";
export const ContentHead = {
type: ProtoField(1, ScalarType.UINT32),

View File

@@ -9,8 +9,8 @@ export const OidbSvcTrpcTcp0X8FC_2_Body = {
expiredTime: ProtoField(6, ScalarType.SINT32),
uinName: ProtoField(7, ScalarType.STRING),
targetName: ProtoField(8, ScalarType.STRING),
}
};
export const OidbSvcTrpcTcp0X8FC_2 = {
groupUin: ProtoField(1, ScalarType.UINT32),
body: ProtoField(3, ScalarType.BYTES),
}
};

View File

@@ -6,10 +6,10 @@ import { MultiMediaReqHead } from "./common/Ntv2.RichMedia";
export const OidbSvcTrpcTcp0X9067_202 = {
ReqHead: ProtoField(1, () => MultiMediaReqHead),
DownloadRKeyReq: ProtoField(4, () => OidbSvcTrpcTcp0X9067_202Key),
}
};
export const OidbSvcTrpcTcp0X9067_202Key = {
key: ProtoField(1, ScalarType.INT32, false, true),
}
};
//Rsp
export const OidbSvcTrpcTcp0X9067_202_RkeyList = {
@@ -17,10 +17,10 @@ export const OidbSvcTrpcTcp0X9067_202_RkeyList = {
time: ProtoField(4, ScalarType.UINT32),
type: ProtoField(5, ScalarType.UINT32),
}
};
export const OidbSvcTrpcTcp0X9067_202_Data = {
rkeyList: ProtoField(1, () => OidbSvcTrpcTcp0X9067_202_RkeyList, false, true),
}
};
export const OidbSvcTrpcTcp0X9067_202_Rsp_Body = {
data: ProtoField(4, () => OidbSvcTrpcTcp0X9067_202_Data),
}
};

View File

@@ -7,4 +7,4 @@ export const OidbSvcTrpcTcp0XED3_1 = {
groupUin: ProtoField(2, ScalarType.UINT32),
friendUin: ProtoField(5, ScalarType.UINT32),
ext: ProtoField(6, ScalarType.UINT32, true)
}
};

View File

@@ -4,20 +4,20 @@ import { ProtoField } from "../NapProto";
export const OidbSvcTrpcTcp0XFE1_2 = {
uin: ProtoField(1, ScalarType.UINT32),
key: ProtoField(3, () => OidbSvcTrpcTcp0XFE1_2Key, false, true),
}
};
export const OidbSvcTrpcTcp0XFE1_2Key = {
key: ProtoField(1, ScalarType.UINT32)
}
};
export const OidbSvcTrpcTcp0XFE1_2RSP_Status = {
key: ProtoField(1, ScalarType.UINT32),
value: ProtoField(2, ScalarType.UINT64)
}
};
export const OidbSvcTrpcTcp0XFE1_2RSP_Data = {
status: ProtoField(2, () => OidbSvcTrpcTcp0XFE1_2RSP_Status)
}
};
export const OidbSvcTrpcTcp0XFE1_2RSP = {
data: ProtoField(1, () => OidbSvcTrpcTcp0XFE1_2RSP_Data)
}
};

View File

@@ -7,7 +7,7 @@ export const OidbSvcTrpcTcpBase = {
body: ProtoField(4, ScalarType.BYTES),
errorMsg: ProtoField(5, ScalarType.STRING, true),
isReserved: ProtoField(12, ScalarType.UINT32)
}
};
export const OidbSvcTrpcTcpBaseRsp = {
body: ProtoField(4, ScalarType.BYTES)
}
};

View File

@@ -4,35 +4,35 @@ import { ProtoField } from "../../NapProto";
export const NTV2RichMediaReq = {
ReqHead: ProtoField(1, ScalarType.BYTES),
DownloadRKeyReq: ProtoField(4, ScalarType.BYTES),
}
};
export const MultiMediaReqHead = {
Common: ProtoField(1, () => CommonHead),
Scene: ProtoField(2, () => SceneInfo),
Client: ProtoField(3, () => ClientMeta),
}
};
export const CommonHead = {
RequestId: ProtoField(1, ScalarType.UINT32),
Command: ProtoField(2, ScalarType.UINT32),
}
};
export const SceneInfo = {
RequestType: ProtoField(101, ScalarType.UINT32),
BusinessType: ProtoField(102, ScalarType.UINT32),
SceneType: ProtoField(200, ScalarType.UINT32),
}
};
export const ClientMeta = {
AgentType: ProtoField(1, ScalarType.UINT32),
}
};
export const C2CUserInfo = {
AccountType: ProtoField(1, ScalarType.UINT32),
TargetUid: ProtoField(2, ScalarType.STRING),
}
};
export const GroupInfo = {
GroupUin: ProtoField(1, ScalarType.UINT32),
}
};
export const DownloadReq = {
Node: ProtoField(1, ScalarType.BYTES),
Download: ProtoField(2, ScalarType.BYTES),
}
};
export const FileInfo = {
FileSize: ProtoField(1, ScalarType.UINT32),
FileHash: ProtoField(2, ScalarType.STRING),
@@ -43,7 +43,7 @@ export const FileInfo = {
Height: ProtoField(7, ScalarType.UINT32),
Time: ProtoField(8, ScalarType.UINT32),
Original: ProtoField(9, ScalarType.UINT32),
}
};
export const IndexNode = {
Info: ProtoField(1, ScalarType.BYTES),
FileUuid: ProtoField(2, ScalarType.STRING),
@@ -51,33 +51,33 @@ export const IndexNode = {
UploadTime: ProtoField(4, ScalarType.UINT32),
Ttl: ProtoField(5, ScalarType.UINT32),
subType: ProtoField(6, ScalarType.UINT32),
}
};
export const FileType = {
Type: ProtoField(1, ScalarType.UINT32),
PicFormat: ProtoField(2, ScalarType.UINT32),
VideoFormat: ProtoField(3, ScalarType.UINT32),
VoiceFormat: ProtoField(4, ScalarType.UINT32),
}
};
export const DownloadExt = {
Pic: ProtoField(1, ScalarType.BYTES),
Video: ProtoField(2, ScalarType.BYTES),
Ptt: ProtoField(3, ScalarType.BYTES),
}
};
export const VideoDownloadExt = {
BusiType: ProtoField(1, ScalarType.UINT32),
SceneType: ProtoField(2, ScalarType.UINT32),
SubBusiType: ProtoField(3, ScalarType.UINT32),
}
export const PicDownloadExt = {}
export const PttDownloadExt = {}
};
export const PicDownloadExt = {};
export const PttDownloadExt = {};
export const PicUrlExtInfo = {
OriginalParameter: ProtoField(1, ScalarType.STRING),
BigParameter: ProtoField(2, ScalarType.STRING),
ThumbParameter: ProtoField(3, ScalarType.STRING),
}
};
export const VideoExtInfo = {
VideoCodecFormat: ProtoField(1, ScalarType.UINT32),
}
};
export const MsgInfo = {
}
};

View File

@@ -1,11 +1,11 @@
import {PacketClient} from "@/core/packet/client";
import {PacketHighwayClient} from "@/core/packet/highway/highwayClient";
import {LogWrapper} from "@/common/log";
import { PacketClient } from "@/core/packet/client";
import { PacketHighwayClient } from "@/core/packet/highway/highwayClient";
import { LogWrapper } from "@/common/log";
export class PacketSession {
readonly logger: LogWrapper;
readonly client: PacketClient;
private highwayClient: PacketHighwayClient
private highwayClient: PacketHighwayClient;
constructor(logger: LogWrapper, client: PacketClient) {
this.logger = logger;