From 1e63a2a7e77c40ba66dc146dd1253cc8c1969ac9 Mon Sep 17 00:00:00 2001 From: Alen Date: Wed, 11 Sep 2024 02:28:47 +0800 Subject: [PATCH 1/4] =?UTF-8?q?test:=20=E8=A2=AB=E8=B5=9E=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6(=E6=9C=AA=E5=AE=8C=E6=88=90)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/proto/ProfileLikeTip.proto | 22 +++ src/core/proto/ProfileLikeTip.ts | 281 ++++++++++++++++++++++++++++ src/onebot/index.ts | 58 +++--- 3 files changed, 339 insertions(+), 22 deletions(-) create mode 100644 src/core/proto/ProfileLikeTip.proto create mode 100644 src/core/proto/ProfileLikeTip.ts diff --git a/src/core/proto/ProfileLikeTip.proto b/src/core/proto/ProfileLikeTip.proto new file mode 100644 index 00000000..df3a3b5e --- /dev/null +++ b/src/core/proto/ProfileLikeTip.proto @@ -0,0 +1,22 @@ +syntax = 'proto3'; +package SysMessage; + +message ProfileLikeTip { + ProfileLikeDetail profile_like_detail = 203; +} + +message ProfileLikeDetail { + LikeDetail like_detail = 14; +} + +message LikeDetail { + int32 times = 1; + int32 time = 2; + TextTip text_tip = 3; +} + +message TextTip { + string txt = 1; + int64 qq = 2; + string nick = 3; +} \ No newline at end of file diff --git a/src/core/proto/ProfileLikeTip.ts b/src/core/proto/ProfileLikeTip.ts new file mode 100644 index 00000000..6427b808 --- /dev/null +++ b/src/core/proto/ProfileLikeTip.ts @@ -0,0 +1,281 @@ +// @generated by protobuf-ts 2.9.4 +// @generated from protobuf file "ProfileLikeTip.proto" (package "SysMessage", syntax proto3) +// tslint:disable +import type { BinaryWriteOptions } from "@protobuf-ts/runtime"; +import type { IBinaryWriter } from "@protobuf-ts/runtime"; +import { WireType } from "@protobuf-ts/runtime"; +import type { BinaryReadOptions } from "@protobuf-ts/runtime"; +import type { IBinaryReader } from "@protobuf-ts/runtime"; +import { UnknownFieldHandler } from "@protobuf-ts/runtime"; +import type { PartialMessage } from "@protobuf-ts/runtime"; +import { reflectionMergePartial } from "@protobuf-ts/runtime"; +import { MessageType } from "@protobuf-ts/runtime"; +/** + * @generated from protobuf message SysMessage.ProfileLikeTip + */ +export interface ProfileLikeTip { + /** + * @generated from protobuf field: SysMessage.ProfileLikeDetail profile_like_detail = 203; + */ + profileLikeDetail?: ProfileLikeDetail; +} +/** + * @generated from protobuf message SysMessage.ProfileLikeDetail + */ +export interface ProfileLikeDetail { + /** + * @generated from protobuf field: SysMessage.LikeDetail like_detail = 14; + */ + likeDetail?: LikeDetail; +} +/** + * @generated from protobuf message SysMessage.LikeDetail + */ +export interface LikeDetail { + /** + * @generated from protobuf field: int32 times = 1; + */ + times: number; + /** + * @generated from protobuf field: int32 time = 2; + */ + time: number; + /** + * @generated from protobuf field: SysMessage.TextTip text_tip = 3; + */ + textTip?: TextTip; +} +/** + * @generated from protobuf message SysMessage.TextTip + */ +export interface TextTip { + /** + * @generated from protobuf field: string txt = 1; + */ + txt: string; + /** + * @generated from protobuf field: int64 qq = 2; + */ + qq: bigint; + /** + * @generated from protobuf field: string nick = 3; + */ + nick: string; +} +// @generated message type with reflection information, may provide speed optimized methods +class ProfileLikeTip$Type extends MessageType { + constructor() { + super("SysMessage.ProfileLikeTip", [ + { no: 203, name: "profile_like_detail", kind: "message", T: () => ProfileLikeDetail } + ]); + } + create(value?: PartialMessage): ProfileLikeTip { + const message = globalThis.Object.create((this.messagePrototype!)); + if (value !== undefined) + reflectionMergePartial(this, message, value); + return message; + } + internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: ProfileLikeTip): ProfileLikeTip { + let message = target ?? this.create(), end = reader.pos + length; + while (reader.pos < end) { + let [fieldNo, wireType] = reader.tag(); + switch (fieldNo) { + case /* SysMessage.ProfileLikeDetail profile_like_detail */ 203: + message.profileLikeDetail = ProfileLikeDetail.internalBinaryRead(reader, reader.uint32(), options, message.profileLikeDetail); + break; + default: + let u = options.readUnknownField; + if (u === "throw") + throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`); + let d = reader.skip(wireType); + if (u !== false) + (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d); + } + } + return message; + } + internalBinaryWrite(message: ProfileLikeTip, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter { + /* SysMessage.ProfileLikeDetail profile_like_detail = 203; */ + if (message.profileLikeDetail) + ProfileLikeDetail.internalBinaryWrite(message.profileLikeDetail, writer.tag(203, WireType.LengthDelimited).fork(), options).join(); + let u = options.writeUnknownFields; + if (u !== false) + (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer); + return writer; + } +} +/** + * @generated MessageType for protobuf message SysMessage.ProfileLikeTip + */ +export const ProfileLikeTip = new ProfileLikeTip$Type(); +// @generated message type with reflection information, may provide speed optimized methods +class ProfileLikeDetail$Type extends MessageType { + constructor() { + super("SysMessage.ProfileLikeDetail", [ + { no: 14, name: "like_detail", kind: "message", T: () => LikeDetail } + ]); + } + create(value?: PartialMessage): ProfileLikeDetail { + const message = globalThis.Object.create((this.messagePrototype!)); + if (value !== undefined) + reflectionMergePartial(this, message, value); + return message; + } + internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: ProfileLikeDetail): ProfileLikeDetail { + let message = target ?? this.create(), end = reader.pos + length; + while (reader.pos < end) { + let [fieldNo, wireType] = reader.tag(); + switch (fieldNo) { + case /* SysMessage.LikeDetail like_detail */ 14: + message.likeDetail = LikeDetail.internalBinaryRead(reader, reader.uint32(), options, message.likeDetail); + break; + default: + let u = options.readUnknownField; + if (u === "throw") + throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`); + let d = reader.skip(wireType); + if (u !== false) + (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d); + } + } + return message; + } + internalBinaryWrite(message: ProfileLikeDetail, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter { + /* SysMessage.LikeDetail like_detail = 14; */ + if (message.likeDetail) + LikeDetail.internalBinaryWrite(message.likeDetail, writer.tag(14, WireType.LengthDelimited).fork(), options).join(); + let u = options.writeUnknownFields; + if (u !== false) + (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer); + return writer; + } +} +/** + * @generated MessageType for protobuf message SysMessage.ProfileLikeDetail + */ +export const ProfileLikeDetail = new ProfileLikeDetail$Type(); +// @generated message type with reflection information, may provide speed optimized methods +class LikeDetail$Type extends MessageType { + constructor() { + super("SysMessage.LikeDetail", [ + { no: 1, name: "times", kind: "scalar", T: 5 /*ScalarType.INT32*/ }, + { no: 2, name: "time", kind: "scalar", T: 5 /*ScalarType.INT32*/ }, + { no: 3, name: "text_tip", kind: "message", T: () => TextTip } + ]); + } + create(value?: PartialMessage): LikeDetail { + const message = globalThis.Object.create((this.messagePrototype!)); + message.times = 0; + message.time = 0; + if (value !== undefined) + reflectionMergePartial(this, message, value); + return message; + } + internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: LikeDetail): LikeDetail { + let message = target ?? this.create(), end = reader.pos + length; + while (reader.pos < end) { + let [fieldNo, wireType] = reader.tag(); + switch (fieldNo) { + case /* int32 times */ 1: + message.times = reader.int32(); + break; + case /* int32 time */ 2: + message.time = reader.int32(); + break; + case /* SysMessage.TextTip text_tip */ 3: + message.textTip = TextTip.internalBinaryRead(reader, reader.uint32(), options, message.textTip); + break; + default: + let u = options.readUnknownField; + if (u === "throw") + throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`); + let d = reader.skip(wireType); + if (u !== false) + (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d); + } + } + return message; + } + internalBinaryWrite(message: LikeDetail, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter { + /* int32 times = 1; */ + if (message.times !== 0) + writer.tag(1, WireType.Varint).int32(message.times); + /* int32 time = 2; */ + if (message.time !== 0) + writer.tag(2, WireType.Varint).int32(message.time); + /* SysMessage.TextTip text_tip = 3; */ + if (message.textTip) + TextTip.internalBinaryWrite(message.textTip, writer.tag(3, WireType.LengthDelimited).fork(), options).join(); + let u = options.writeUnknownFields; + if (u !== false) + (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer); + return writer; + } +} +/** + * @generated MessageType for protobuf message SysMessage.LikeDetail + */ +export const LikeDetail = new LikeDetail$Type(); +// @generated message type with reflection information, may provide speed optimized methods +class TextTip$Type extends MessageType { + constructor() { + super("SysMessage.TextTip", [ + { no: 1, name: "txt", kind: "scalar", T: 9 /*ScalarType.STRING*/ }, + { no: 2, name: "qq", kind: "scalar", T: 3 /*ScalarType.INT64*/, L: 0 /*LongType.BIGINT*/ }, + { no: 3, name: "nick", kind: "scalar", T: 9 /*ScalarType.STRING*/ } + ]); + } + create(value?: PartialMessage): TextTip { + const message = globalThis.Object.create((this.messagePrototype!)); + message.txt = ""; + message.qq = 0n; + message.nick = ""; + if (value !== undefined) + reflectionMergePartial(this, message, value); + return message; + } + internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: TextTip): TextTip { + let message = target ?? this.create(), end = reader.pos + length; + while (reader.pos < end) { + let [fieldNo, wireType] = reader.tag(); + switch (fieldNo) { + case /* string txt */ 1: + message.txt = reader.string(); + break; + case /* int64 qq */ 2: + message.qq = reader.int64().toBigInt(); + break; + case /* string nick */ 3: + message.nick = reader.string(); + break; + default: + let u = options.readUnknownField; + if (u === "throw") + throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`); + let d = reader.skip(wireType); + if (u !== false) + (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d); + } + } + return message; + } + internalBinaryWrite(message: TextTip, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter { + /* string txt = 1; */ + if (message.txt !== "") + writer.tag(1, WireType.LengthDelimited).string(message.txt); + /* int64 qq = 2; */ + if (message.qq !== 0n) + writer.tag(2, WireType.Varint).int64(message.qq); + /* string nick = 3; */ + if (message.nick !== "") + writer.tag(3, WireType.LengthDelimited).string(message.nick); + let u = options.writeUnknownFields; + if (u !== false) + (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer); + return writer; + } +} +/** + * @generated MessageType for protobuf message SysMessage.TextTip + */ +export const TextTip = new TextTip$Type(); diff --git a/src/onebot/index.ts b/src/onebot/index.ts index ec40761e..58e3ffdc 100644 --- a/src/onebot/index.ts +++ b/src/onebot/index.ts @@ -43,6 +43,10 @@ import { OB11FriendRecallNoticeEvent } from '@/onebot/event/notice/OB11FriendRec import { OB11GroupRecallNoticeEvent } from '@/onebot/event/notice/OB11GroupRecallNoticeEvent'; import { LRUCache } from '@/common/lru-cache'; import { NodeIKernelRecentContactListener } from '@/core/listeners/NodeIKernelRecentContactListener'; +import { SysMessage } from '@/core/proto/SysMessage'; +import { ProfileLikeTip } from '@/core/proto/ProfileLikeTip'; +import util from 'util'; +import { time } from 'console'; //OneBot实现类 export class NapCatOneBot11Adapter { @@ -238,35 +242,45 @@ export class NapCatOneBot11Adapter { private initMsgListener() { const msgListener = new NodeIKernelMsgListener(); - /* - msgListener.onRecvSysMsg = async () => { + msgListener.onRecvSysMsg = async (msg) => { + console.log('收到系统消息', util.inspect(msg, { depth: null, maxArrayLength: null })); const sysMsg = SysMessage.fromBinary(Uint8Array.from(msg)); if (sysMsg.msgSpec.length === 0) { return; } + console.log( '收到系统消息:Uint8Array:', util.inspect(Uint8Array.from(msg), { depth: null, maxArrayLength: null })); const { msgType, subType, subSubType } = sysMsg.msgSpec[0]; - if (msgType === 732 && subType === 16 && subSubType === 16) { - const greyTip = GreyTipWrapper.fromBinary(Uint8Array.from(sysMsg.bodyWrapper!.wrappedBody.slice(7))); - if (greyTip.subTypeId === 36) { - const emojiLikeToOthers = EmojiLikeToOthersWrapper1 - .fromBinary(greyTip.rest) - .wrapper! - .body!; - if (emojiLikeToOthers.attributes?.operation !== 1) { // Un-like - return; - } - const eventOrEmpty = await this.apis.GroupApi.createGroupEmojiLikeEvent( - greyTip.groupCode.toString(), - await this.core.apis.UserApi.getUinByUidV2(emojiLikeToOthers.attributes!.senderUid), - emojiLikeToOthers.msgSpec!.msgSeq.toString(), - emojiLikeToOthers.attributes!.emojiId, - ); - // eslint-disable-next-line @typescript-eslint/no-unused-expressions - eventOrEmpty && await this.networkManager.emitEvent(eventOrEmpty); + this.core.context.logger.log('收到系统消息类型', msgType, subType, subSubType); + if (msgType === 528 && subType === 39 && subSubType === 39) { + console.log(util.inspect(sysMsg.bodyWrapper!.wrappedBody, { depth: null, maxArrayLength: null })); + const profileLikeTip = ProfileLikeTip.fromBinary(Uint8Array.from(sysMsg.bodyWrapper!.wrappedBody)); + console.log("点赞提示: ", profileLikeTip); + if (profileLikeTip.profileLikeDetail?.likeDetail) { + const detail = profileLikeTip.profileLikeDetail.likeDetail.textTip; + console.log("点赞详情: ", detail, "时间: ", Date.parse(profileLikeTip.profileLikeDetail.likeDetail.time.toString())); } - } + }; + // if (msgType === 732 && subType === 16 && subSubType === 16) { + // const greyTip = GreyTipWrapper.fromBinary(Uint8Array.from(sysMsg.bodyWrapper!.wrappedBody.slice(7))); + // if (greyTip.subTypeId === 36) { + // const emojiLikeToOthers = EmojiLikeToOthersWrapper1 + // .fromBinary(greyTip.rest) + // .wrapper! + // .body!; + // if (emojiLikeToOthers.attributes?.operation !== 1) { // Un-like + // return; + // } + // const eventOrEmpty = await this.apis.GroupApi.createGroupEmojiLikeEvent( + // greyTip.groupCode.toString(), + // await this.core.apis.UserApi.getUinByUidV2(emojiLikeToOthers.attributes!.senderUid), + // emojiLikeToOthers.msgSpec!.msgSeq.toString(), + // emojiLikeToOthers.attributes!.emojiId, + // ); + // // eslint-disable-next-line @typescript-eslint/no-unused-expressions + // eventOrEmpty && await this.networkManager.emitEvent(eventOrEmpty); + // } + // } }; - */ msgListener.onInputStatusPush = async data => { const uin = await this.core.apis.UserApi.getUinByUidV2(data.fromUin); From b8457d4affacf4d82b426aa5e217dc6ae624f16d Mon Sep 17 00:00:00 2001 From: Alen <33656288+cnxysoft@users.noreply.github.com> Date: Wed, 11 Sep 2024 16:32:28 +0800 Subject: [PATCH 2/4] =?UTF-8?q?feat:=20=E8=A2=AB=E7=82=B9=E8=B5=9E?= =?UTF-8?q?=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/proto/ProfileLikeTip.proto | 26 +-- src/core/proto/ProfileLikeTip.ts | 215 +++++++----------- .../event/notice/OB11ProfileLikeEvent.ts | 19 ++ src/onebot/index.ts | 28 +-- 4 files changed, 125 insertions(+), 163 deletions(-) create mode 100644 src/onebot/event/notice/OB11ProfileLikeEvent.ts diff --git a/src/core/proto/ProfileLikeTip.proto b/src/core/proto/ProfileLikeTip.proto index df3a3b5e..887f045c 100644 --- a/src/core/proto/ProfileLikeTip.proto +++ b/src/core/proto/ProfileLikeTip.proto @@ -1,22 +1,18 @@ -syntax = 'proto3'; +syntax = "proto3"; package SysMessage; -message ProfileLikeTip { - ProfileLikeDetail profile_like_detail = 203; +message likeDetail { + string txt = 1; + int64 uin = 3; + string nickname = 5; } -message ProfileLikeDetail { - LikeDetail like_detail = 14; +message likeMsg { + int32 times = 1; + int32 time = 2; + likeDetail detail = 3; } -message LikeDetail { - int32 times = 1; - int32 time = 2; - TextTip text_tip = 3; +message profileLikeTip { + likeMsg msg = 14; } - -message TextTip { - string txt = 1; - int64 qq = 2; - string nick = 3; -} \ No newline at end of file diff --git a/src/core/proto/ProfileLikeTip.ts b/src/core/proto/ProfileLikeTip.ts index 6427b808..01ffa2e1 100644 --- a/src/core/proto/ProfileLikeTip.ts +++ b/src/core/proto/ProfileLikeTip.ts @@ -1,5 +1,5 @@ // @generated by protobuf-ts 2.9.4 -// @generated from protobuf file "ProfileLikeTip.proto" (package "SysMessage", syntax proto3) +// @generated from protobuf file "ProfilelikeTip.proto" (package "SysMessage", syntax proto3) // tslint:disable import type { BinaryWriteOptions } from "@protobuf-ts/runtime"; import type { IBinaryWriter } from "@protobuf-ts/runtime"; @@ -11,27 +11,26 @@ import type { PartialMessage } from "@protobuf-ts/runtime"; import { reflectionMergePartial } from "@protobuf-ts/runtime"; import { MessageType } from "@protobuf-ts/runtime"; /** - * @generated from protobuf message SysMessage.ProfileLikeTip + * @generated from protobuf message SysMessage.likeDetail */ -export interface ProfileLikeTip { +export interface likeDetail { /** - * @generated from protobuf field: SysMessage.ProfileLikeDetail profile_like_detail = 203; + * @generated from protobuf field: string txt = 1; */ - profileLikeDetail?: ProfileLikeDetail; + txt: string; + /** + * @generated from protobuf field: int64 uin = 3; + */ + uin: bigint; + /** + * @generated from protobuf field: string nickname = 5; + */ + nickname: string; } /** - * @generated from protobuf message SysMessage.ProfileLikeDetail + * @generated from protobuf message SysMessage.likeMsg */ -export interface ProfileLikeDetail { - /** - * @generated from protobuf field: SysMessage.LikeDetail like_detail = 14; - */ - likeDetail?: LikeDetail; -} -/** - * @generated from protobuf message SysMessage.LikeDetail - */ -export interface LikeDetail { +export interface likeMsg { /** * @generated from protobuf field: int32 times = 1; */ @@ -41,47 +40,50 @@ export interface LikeDetail { */ time: number; /** - * @generated from protobuf field: SysMessage.TextTip text_tip = 3; + * @generated from protobuf field: SysMessage.likeDetail detail = 3; */ - textTip?: TextTip; + detail?: likeDetail; } /** - * @generated from protobuf message SysMessage.TextTip + * @generated from protobuf message SysMessage.profileLikeTip */ -export interface TextTip { +export interface profileLikeTip { /** - * @generated from protobuf field: string txt = 1; + * @generated from protobuf field: SysMessage.likeMsg msg = 14; */ - txt: string; - /** - * @generated from protobuf field: int64 qq = 2; - */ - qq: bigint; - /** - * @generated from protobuf field: string nick = 3; - */ - nick: string; + msg?: likeMsg; } // @generated message type with reflection information, may provide speed optimized methods -class ProfileLikeTip$Type extends MessageType { +class likeDetail$Type extends MessageType { constructor() { - super("SysMessage.ProfileLikeTip", [ - { no: 203, name: "profile_like_detail", kind: "message", T: () => ProfileLikeDetail } + super("SysMessage.likeDetail", [ + { no: 1, name: "txt", kind: "scalar", T: 9 /*ScalarType.STRING*/ }, + { no: 3, name: "uin", kind: "scalar", T: 3 /*ScalarType.INT64*/, L: 0 /*LongType.BIGINT*/ }, + { no: 5, name: "nickname", kind: "scalar", T: 9 /*ScalarType.STRING*/ } ]); } - create(value?: PartialMessage): ProfileLikeTip { + create(value?: PartialMessage): likeDetail { const message = globalThis.Object.create((this.messagePrototype!)); + message.txt = ""; + message.uin = 0n; + message.nickname = ""; if (value !== undefined) - reflectionMergePartial(this, message, value); + reflectionMergePartial(this, message, value); return message; } - internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: ProfileLikeTip): ProfileLikeTip { + internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: likeDetail): likeDetail { let message = target ?? this.create(), end = reader.pos + length; while (reader.pos < end) { let [fieldNo, wireType] = reader.tag(); switch (fieldNo) { - case /* SysMessage.ProfileLikeDetail profile_like_detail */ 203: - message.profileLikeDetail = ProfileLikeDetail.internalBinaryRead(reader, reader.uint32(), options, message.profileLikeDetail); + case /* string txt */ 1: + message.txt = reader.string(); + break; + case /* int64 uin */ 3: + message.uin = reader.int64().toBigInt(); + break; + case /* string nickname */ 5: + message.nickname = reader.string(); break; default: let u = options.readUnknownField; @@ -94,10 +96,16 @@ class ProfileLikeTip$Type extends MessageType { } return message; } - internalBinaryWrite(message: ProfileLikeTip, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter { - /* SysMessage.ProfileLikeDetail profile_like_detail = 203; */ - if (message.profileLikeDetail) - ProfileLikeDetail.internalBinaryWrite(message.profileLikeDetail, writer.tag(203, WireType.LengthDelimited).fork(), options).join(); + internalBinaryWrite(message: likeDetail, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter { + /* string txt = 1; */ + if (message.txt !== "") + writer.tag(1, WireType.LengthDelimited).string(message.txt); + /* int64 uin = 3; */ + if (message.uin !== 0n) + writer.tag(3, WireType.Varint).int64(message.uin); + /* string nickname = 5; */ + if (message.nickname !== "") + writer.tag(5, WireType.LengthDelimited).string(message.nickname); let u = options.writeUnknownFields; if (u !== false) (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer); @@ -105,73 +113,27 @@ class ProfileLikeTip$Type extends MessageType { } } /** - * @generated MessageType for protobuf message SysMessage.ProfileLikeTip + * @generated MessageType for protobuf message SysMessage.likeDetail */ -export const ProfileLikeTip = new ProfileLikeTip$Type(); +export const likeDetail = new likeDetail$Type(); // @generated message type with reflection information, may provide speed optimized methods -class ProfileLikeDetail$Type extends MessageType { +class likeMsg$Type extends MessageType { constructor() { - super("SysMessage.ProfileLikeDetail", [ - { no: 14, name: "like_detail", kind: "message", T: () => LikeDetail } - ]); - } - create(value?: PartialMessage): ProfileLikeDetail { - const message = globalThis.Object.create((this.messagePrototype!)); - if (value !== undefined) - reflectionMergePartial(this, message, value); - return message; - } - internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: ProfileLikeDetail): ProfileLikeDetail { - let message = target ?? this.create(), end = reader.pos + length; - while (reader.pos < end) { - let [fieldNo, wireType] = reader.tag(); - switch (fieldNo) { - case /* SysMessage.LikeDetail like_detail */ 14: - message.likeDetail = LikeDetail.internalBinaryRead(reader, reader.uint32(), options, message.likeDetail); - break; - default: - let u = options.readUnknownField; - if (u === "throw") - throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`); - let d = reader.skip(wireType); - if (u !== false) - (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d); - } - } - return message; - } - internalBinaryWrite(message: ProfileLikeDetail, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter { - /* SysMessage.LikeDetail like_detail = 14; */ - if (message.likeDetail) - LikeDetail.internalBinaryWrite(message.likeDetail, writer.tag(14, WireType.LengthDelimited).fork(), options).join(); - let u = options.writeUnknownFields; - if (u !== false) - (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer); - return writer; - } -} -/** - * @generated MessageType for protobuf message SysMessage.ProfileLikeDetail - */ -export const ProfileLikeDetail = new ProfileLikeDetail$Type(); -// @generated message type with reflection information, may provide speed optimized methods -class LikeDetail$Type extends MessageType { - constructor() { - super("SysMessage.LikeDetail", [ + super("SysMessage.likeMsg", [ { no: 1, name: "times", kind: "scalar", T: 5 /*ScalarType.INT32*/ }, { no: 2, name: "time", kind: "scalar", T: 5 /*ScalarType.INT32*/ }, - { no: 3, name: "text_tip", kind: "message", T: () => TextTip } + { no: 3, name: "detail", kind: "message", T: () => likeDetail } ]); } - create(value?: PartialMessage): LikeDetail { + create(value?: PartialMessage): likeMsg { const message = globalThis.Object.create((this.messagePrototype!)); message.times = 0; message.time = 0; if (value !== undefined) - reflectionMergePartial(this, message, value); + reflectionMergePartial(this, message, value); return message; } - internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: LikeDetail): LikeDetail { + internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: likeMsg): likeMsg { let message = target ?? this.create(), end = reader.pos + length; while (reader.pos < end) { let [fieldNo, wireType] = reader.tag(); @@ -182,8 +144,8 @@ class LikeDetail$Type extends MessageType { case /* int32 time */ 2: message.time = reader.int32(); break; - case /* SysMessage.TextTip text_tip */ 3: - message.textTip = TextTip.internalBinaryRead(reader, reader.uint32(), options, message.textTip); + case /* SysMessage.likeDetail detail */ 3: + message.detail = likeDetail.internalBinaryRead(reader, reader.uint32(), options, message.detail); break; default: let u = options.readUnknownField; @@ -196,16 +158,16 @@ class LikeDetail$Type extends MessageType { } return message; } - internalBinaryWrite(message: LikeDetail, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter { + internalBinaryWrite(message: likeMsg, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter { /* int32 times = 1; */ if (message.times !== 0) writer.tag(1, WireType.Varint).int32(message.times); /* int32 time = 2; */ if (message.time !== 0) writer.tag(2, WireType.Varint).int32(message.time); - /* SysMessage.TextTip text_tip = 3; */ - if (message.textTip) - TextTip.internalBinaryWrite(message.textTip, writer.tag(3, WireType.LengthDelimited).fork(), options).join(); + /* SysMessage.likeDetail detail = 3; */ + if (message.detail) + likeDetail.internalBinaryWrite(message.detail, writer.tag(3, WireType.LengthDelimited).fork(), options).join(); let u = options.writeUnknownFields; if (u !== false) (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer); @@ -213,40 +175,29 @@ class LikeDetail$Type extends MessageType { } } /** - * @generated MessageType for protobuf message SysMessage.LikeDetail + * @generated MessageType for protobuf message SysMessage.likeMsg */ -export const LikeDetail = new LikeDetail$Type(); +export const likeMsg = new likeMsg$Type(); // @generated message type with reflection information, may provide speed optimized methods -class TextTip$Type extends MessageType { +class profileLikeTip$Type extends MessageType { constructor() { - super("SysMessage.TextTip", [ - { no: 1, name: "txt", kind: "scalar", T: 9 /*ScalarType.STRING*/ }, - { no: 2, name: "qq", kind: "scalar", T: 3 /*ScalarType.INT64*/, L: 0 /*LongType.BIGINT*/ }, - { no: 3, name: "nick", kind: "scalar", T: 9 /*ScalarType.STRING*/ } + super("SysMessage.profileLikeTip", [ + { no: 14, name: "msg", kind: "message", T: () => likeMsg } ]); } - create(value?: PartialMessage): TextTip { + create(value?: PartialMessage): profileLikeTip { const message = globalThis.Object.create((this.messagePrototype!)); - message.txt = ""; - message.qq = 0n; - message.nick = ""; if (value !== undefined) - reflectionMergePartial(this, message, value); + reflectionMergePartial(this, message, value); return message; } - internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: TextTip): TextTip { + internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: profileLikeTip): profileLikeTip { let message = target ?? this.create(), end = reader.pos + length; while (reader.pos < end) { let [fieldNo, wireType] = reader.tag(); switch (fieldNo) { - case /* string txt */ 1: - message.txt = reader.string(); - break; - case /* int64 qq */ 2: - message.qq = reader.int64().toBigInt(); - break; - case /* string nick */ 3: - message.nick = reader.string(); + case /* SysMessage.likeMsg msg */ 14: + message.msg = likeMsg.internalBinaryRead(reader, reader.uint32(), options, message.msg); break; default: let u = options.readUnknownField; @@ -259,16 +210,10 @@ class TextTip$Type extends MessageType { } return message; } - internalBinaryWrite(message: TextTip, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter { - /* string txt = 1; */ - if (message.txt !== "") - writer.tag(1, WireType.LengthDelimited).string(message.txt); - /* int64 qq = 2; */ - if (message.qq !== 0n) - writer.tag(2, WireType.Varint).int64(message.qq); - /* string nick = 3; */ - if (message.nick !== "") - writer.tag(3, WireType.LengthDelimited).string(message.nick); + internalBinaryWrite(message: profileLikeTip, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter { + /* SysMessage.likeMsg msg = 14; */ + if (message.msg) + likeMsg.internalBinaryWrite(message.msg, writer.tag(14, WireType.LengthDelimited).fork(), options).join(); let u = options.writeUnknownFields; if (u !== false) (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer); @@ -276,6 +221,6 @@ class TextTip$Type extends MessageType { } } /** - * @generated MessageType for protobuf message SysMessage.TextTip + * @generated MessageType for protobuf message SysMessage.profileLikeTip */ -export const TextTip = new TextTip$Type(); +export const profileLikeTip = new profileLikeTip$Type(); diff --git a/src/onebot/event/notice/OB11ProfileLikeEvent.ts b/src/onebot/event/notice/OB11ProfileLikeEvent.ts new file mode 100644 index 00000000..3c790764 --- /dev/null +++ b/src/onebot/event/notice/OB11ProfileLikeEvent.ts @@ -0,0 +1,19 @@ +import { OB11BaseNoticeEvent } from './OB11BaseNoticeEvent'; +import { NapCatCore } from '@/core'; + +export class OB11ProfileLikeEvent extends OB11BaseNoticeEvent { + notice_type = 'notify'; + sub_type = 'profile_like'; + operator_id: number; + operator_nick: string; + times: number; + time: number; + + constructor(core: NapCatCore, operatorId: number, operatorNick: string, times: number, time: number) { + super(core); + this.operator_id = operatorId; + this.operator_nick = operatorNick; + this.times = times; + this.time = time; + } +} diff --git a/src/onebot/index.ts b/src/onebot/index.ts index 58e3ffdc..b6e7a1b5 100644 --- a/src/onebot/index.ts +++ b/src/onebot/index.ts @@ -44,9 +44,8 @@ import { OB11GroupRecallNoticeEvent } from '@/onebot/event/notice/OB11GroupRecal import { LRUCache } from '@/common/lru-cache'; import { NodeIKernelRecentContactListener } from '@/core/listeners/NodeIKernelRecentContactListener'; import { SysMessage } from '@/core/proto/SysMessage'; -import { ProfileLikeTip } from '@/core/proto/ProfileLikeTip'; -import util from 'util'; -import { time } from 'console'; +import { profileLikeTip } from '@/core/proto/ProfileLikeTip'; +import { OB11ProfileLikeEvent } from './event/notice/OB11ProfileLikeEvent'; //OneBot实现类 export class NapCatOneBot11Adapter { @@ -243,22 +242,25 @@ export class NapCatOneBot11Adapter { const msgListener = new NodeIKernelMsgListener(); msgListener.onRecvSysMsg = async (msg) => { - console.log('收到系统消息', util.inspect(msg, { depth: null, maxArrayLength: null })); const sysMsg = SysMessage.fromBinary(Uint8Array.from(msg)); if (sysMsg.msgSpec.length === 0) { return; } - console.log( '收到系统消息:Uint8Array:', util.inspect(Uint8Array.from(msg), { depth: null, maxArrayLength: null })); const { msgType, subType, subSubType } = sysMsg.msgSpec[0]; - this.core.context.logger.log('收到系统消息类型', msgType, subType, subSubType); if (msgType === 528 && subType === 39 && subSubType === 39) { - console.log(util.inspect(sysMsg.bodyWrapper!.wrappedBody, { depth: null, maxArrayLength: null })); - const profileLikeTip = ProfileLikeTip.fromBinary(Uint8Array.from(sysMsg.bodyWrapper!.wrappedBody)); - console.log("点赞提示: ", profileLikeTip); - if (profileLikeTip.profileLikeDetail?.likeDetail) { - const detail = profileLikeTip.profileLikeDetail.likeDetail.textTip; - console.log("点赞详情: ", detail, "时间: ", Date.parse(profileLikeTip.profileLikeDetail.likeDetail.time.toString())); - } + const likeTip = profileLikeTip.fromBinary(Uint8Array.from(sysMsg.bodyWrapper!.wrappedBody.slice(12))); + this.core.context.logger.logDebug("收到点赞通知消息"); + if (!likeTip.msg) return; + const detail = likeTip.msg.detail; + if (!detail) return; + const times = detail.txt.match(/\d+/) ?? "0"; + await this.networkManager.emitEvent(new OB11ProfileLikeEvent( + this.core, + Number(detail.uin), + detail.nickname, + parseInt(times[0], 10), + likeTip.msg.time, + )).catch(e => this.context.logger.logError('处理被点赞事件失败', e)); }; // if (msgType === 732 && subType === 16 && subSubType === 16) { // const greyTip = GreyTipWrapper.fromBinary(Uint8Array.from(sysMsg.bodyWrapper!.wrappedBody.slice(7))); From 1025a075934b1992cc468caeb76f688f42c6438d Mon Sep 17 00:00:00 2001 From: Alen <33656288+cnxysoft@users.noreply.github.com> Date: Wed, 11 Sep 2024 16:35:23 +0800 Subject: [PATCH 3/4] revert --- src/onebot/index.ts | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/src/onebot/index.ts b/src/onebot/index.ts index b6e7a1b5..a87c3220 100644 --- a/src/onebot/index.ts +++ b/src/onebot/index.ts @@ -262,26 +262,28 @@ export class NapCatOneBot11Adapter { likeTip.msg.time, )).catch(e => this.context.logger.logError('处理被点赞事件失败', e)); }; - // if (msgType === 732 && subType === 16 && subSubType === 16) { - // const greyTip = GreyTipWrapper.fromBinary(Uint8Array.from(sysMsg.bodyWrapper!.wrappedBody.slice(7))); - // if (greyTip.subTypeId === 36) { - // const emojiLikeToOthers = EmojiLikeToOthersWrapper1 - // .fromBinary(greyTip.rest) - // .wrapper! - // .body!; - // if (emojiLikeToOthers.attributes?.operation !== 1) { // Un-like - // return; - // } - // const eventOrEmpty = await this.apis.GroupApi.createGroupEmojiLikeEvent( - // greyTip.groupCode.toString(), - // await this.core.apis.UserApi.getUinByUidV2(emojiLikeToOthers.attributes!.senderUid), - // emojiLikeToOthers.msgSpec!.msgSeq.toString(), - // emojiLikeToOthers.attributes!.emojiId, - // ); - // // eslint-disable-next-line @typescript-eslint/no-unused-expressions - // eventOrEmpty && await this.networkManager.emitEvent(eventOrEmpty); - // } - // } + /* + if (msgType === 732 && subType === 16 && subSubType === 16) { + const greyTip = GreyTipWrapper.fromBinary(Uint8Array.from(sysMsg.bodyWrapper!.wrappedBody.slice(7))); + if (greyTip.subTypeId === 36) { + const emojiLikeToOthers = EmojiLikeToOthersWrapper1 + .fromBinary(greyTip.rest) + .wrapper! + .body!; + if (emojiLikeToOthers.attributes?.operation !== 1) { // Un-like + return; + } + const eventOrEmpty = await this.apis.GroupApi.createGroupEmojiLikeEvent( + greyTip.groupCode.toString(), + await this.core.apis.UserApi.getUinByUidV2(emojiLikeToOthers.attributes!.senderUid), + emojiLikeToOthers.msgSpec!.msgSeq.toString(), + emojiLikeToOthers.attributes!.emojiId, + ); + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + eventOrEmpty && await this.networkManager.emitEvent(eventOrEmpty); + } + } + */ }; msgListener.onInputStatusPush = async data => { From 676766c99ef7843c96e7b067597ff95540fa9513 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Wed, 11 Sep 2024 19:56:51 +0800 Subject: [PATCH 4/4] refactor: protobuf --- package.json | 1 + .../proto/EmojiLikeToOthers.proto | 0 .../{ => external}/proto/GreyTipWrapper.proto | 0 .../{ => external}/proto/ProfileLikeTip.proto | 0 .../{ => external}/proto/SysMessage.proto | 0 src/core/proto/EmojiLikeToOthers.ts | 341 -------------- src/core/proto/GreyTipWrapper.ts | 104 ----- src/core/proto/ProfileLike.ts | 83 ++++ src/core/proto/ProfileLikeTip.ts | 226 --------- src/core/proto/SysMessage.ts | 435 ------------------ src/onebot/index.ts | 16 +- 11 files changed, 92 insertions(+), 1114 deletions(-) rename src/core/{ => external}/proto/EmojiLikeToOthers.proto (100%) rename src/core/{ => external}/proto/GreyTipWrapper.proto (100%) rename src/core/{ => external}/proto/ProfileLikeTip.proto (100%) rename src/core/{ => external}/proto/SysMessage.proto (100%) delete mode 100644 src/core/proto/EmojiLikeToOthers.ts delete mode 100644 src/core/proto/GreyTipWrapper.ts create mode 100644 src/core/proto/ProfileLike.ts delete mode 100644 src/core/proto/ProfileLikeTip.ts delete mode 100644 src/core/proto/SysMessage.ts diff --git a/package.json b/package.json index f8a0c1a5..8290b5fb 100644 --- a/package.json +++ b/package.json @@ -57,6 +57,7 @@ "image-size": "^1.1.1", "json-schema-to-ts": "^3.1.0", "log4js": "^6.9.1", + "protobufjs": "~7.4.0", "qrcode-terminal": "^0.12.0", "silk-wasm": "^3.6.1", "strtok3": "8.0.1", diff --git a/src/core/proto/EmojiLikeToOthers.proto b/src/core/external/proto/EmojiLikeToOthers.proto similarity index 100% rename from src/core/proto/EmojiLikeToOthers.proto rename to src/core/external/proto/EmojiLikeToOthers.proto diff --git a/src/core/proto/GreyTipWrapper.proto b/src/core/external/proto/GreyTipWrapper.proto similarity index 100% rename from src/core/proto/GreyTipWrapper.proto rename to src/core/external/proto/GreyTipWrapper.proto diff --git a/src/core/proto/ProfileLikeTip.proto b/src/core/external/proto/ProfileLikeTip.proto similarity index 100% rename from src/core/proto/ProfileLikeTip.proto rename to src/core/external/proto/ProfileLikeTip.proto diff --git a/src/core/proto/SysMessage.proto b/src/core/external/proto/SysMessage.proto similarity index 100% rename from src/core/proto/SysMessage.proto rename to src/core/external/proto/SysMessage.proto diff --git a/src/core/proto/EmojiLikeToOthers.ts b/src/core/proto/EmojiLikeToOthers.ts deleted file mode 100644 index cc6da7f0..00000000 --- a/src/core/proto/EmojiLikeToOthers.ts +++ /dev/null @@ -1,341 +0,0 @@ -// @generated by protobuf-ts 2.9.4 -// @generated from protobuf file "EmojiLikeToOthers.proto" (package "SysMessage", syntax proto3) -// tslint:disable -import type { - BinaryReadOptions, - BinaryWriteOptions, - IBinaryReader, - IBinaryWriter, - PartialMessage, -} from '@protobuf-ts/runtime'; -import { MessageType, reflectionMergePartial, UnknownFieldHandler, WireType } from '@protobuf-ts/runtime'; - -/** - * @generated from protobuf message SysMessage.EmojiLikeToOthersWrapper1 - */ -export interface EmojiLikeToOthersWrapper1 { - /** - * @generated from protobuf field: SysMessage.EmojiLikeToOthersWrapper2 wrapper = 1; - */ - wrapper?: EmojiLikeToOthersWrapper2; -} -/** - * @generated from protobuf message SysMessage.EmojiLikeToOthersWrapper2 - */ -export interface EmojiLikeToOthersWrapper2 { - /** - * @generated from protobuf field: SysMessage.EmojiLikeToOthersWrapper3 body = 1; - */ - body?: EmojiLikeToOthersWrapper3; -} -/** - * @generated from protobuf message SysMessage.EmojiLikeToOthersWrapper3 - */ -export interface EmojiLikeToOthersWrapper3 { - /** - * @generated from protobuf field: SysMessage.EmojiLikeToOthersMsgSpec msgSpec = 2; - */ - msgSpec?: EmojiLikeToOthersMsgSpec; - /** - * @generated from protobuf field: SysMessage.EmojiLikeToOthersAttributes attributes = 3; - */ - attributes?: EmojiLikeToOthersAttributes; -} -/** - * @generated from protobuf message SysMessage.EmojiLikeToOthersMsgSpec - */ -export interface EmojiLikeToOthersMsgSpec { - /** - * @generated from protobuf field: uint32 msgSeq = 1; - */ - msgSeq: number; -} -/** - * @generated from protobuf message SysMessage.EmojiLikeToOthersAttributes - */ -export interface EmojiLikeToOthersAttributes { - /** - * @generated from protobuf field: string emojiId = 1; - */ - emojiId: string; - /** - * @generated from protobuf field: string senderUid = 4; - */ - senderUid: string; - /** - * @generated from protobuf field: SysMessage.EmojiLikeToOthersAttributes.Operation operation = 5; - */ - operation: EmojiLikeToOthersAttributes_Operation; -} -/** - * @generated from protobuf enum SysMessage.EmojiLikeToOthersAttributes.Operation - */ -export enum EmojiLikeToOthersAttributes_Operation { - /** - * @generated from protobuf enum value: FALLBACK = 0; - */ - FALLBACK = 0, - /** - * @generated from protobuf enum value: LIKE = 1; - */ - LIKE = 1, - /** - * @generated from protobuf enum value: UNLIKE = 2; - */ - UNLIKE = 2 -} -// @generated message type with reflection information, may provide speed optimized methods -class EmojiLikeToOthersWrapper1$Type extends MessageType { - constructor() { - super("SysMessage.EmojiLikeToOthersWrapper1", [ - { no: 1, name: "wrapper", kind: "message", T: () => EmojiLikeToOthersWrapper2 } - ]); - } - create(value?: PartialMessage): EmojiLikeToOthersWrapper1 { - const message = globalThis.Object.create((this.messagePrototype!)); - if (value !== undefined) - reflectionMergePartial(this, message, value); - return message; - } - internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: EmojiLikeToOthersWrapper1): EmojiLikeToOthersWrapper1 { - let message = target ?? this.create(), end = reader.pos + length; - while (reader.pos < end) { - let [fieldNo, wireType] = reader.tag(); - switch (fieldNo) { - case /* SysMessage.EmojiLikeToOthersWrapper2 wrapper */ 1: - message.wrapper = EmojiLikeToOthersWrapper2.internalBinaryRead(reader, reader.uint32(), options, message.wrapper); - break; - default: - let u = options.readUnknownField; - if (u === "throw") - throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`); - let d = reader.skip(wireType); - if (u !== false) - (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d); - } - } - return message; - } - internalBinaryWrite(message: EmojiLikeToOthersWrapper1, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter { - /* SysMessage.EmojiLikeToOthersWrapper2 wrapper = 1; */ - if (message.wrapper) - EmojiLikeToOthersWrapper2.internalBinaryWrite(message.wrapper, writer.tag(1, WireType.LengthDelimited).fork(), options).join(); - let u = options.writeUnknownFields; - if (u !== false) - (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer); - return writer; - } -} -/** - * @generated MessageType for protobuf message SysMessage.EmojiLikeToOthersWrapper1 - */ -export const EmojiLikeToOthersWrapper1 = new EmojiLikeToOthersWrapper1$Type(); -// @generated message type with reflection information, may provide speed optimized methods -class EmojiLikeToOthersWrapper2$Type extends MessageType { - constructor() { - super("SysMessage.EmojiLikeToOthersWrapper2", [ - { no: 1, name: "body", kind: "message", T: () => EmojiLikeToOthersWrapper3 } - ]); - } - create(value?: PartialMessage): EmojiLikeToOthersWrapper2 { - const message = globalThis.Object.create((this.messagePrototype!)); - if (value !== undefined) - reflectionMergePartial(this, message, value); - return message; - } - internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: EmojiLikeToOthersWrapper2): EmojiLikeToOthersWrapper2 { - let message = target ?? this.create(), end = reader.pos + length; - while (reader.pos < end) { - let [fieldNo, wireType] = reader.tag(); - switch (fieldNo) { - case /* SysMessage.EmojiLikeToOthersWrapper3 body */ 1: - message.body = EmojiLikeToOthersWrapper3.internalBinaryRead(reader, reader.uint32(), options, message.body); - break; - default: - let u = options.readUnknownField; - if (u === "throw") - throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`); - let d = reader.skip(wireType); - if (u !== false) - (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d); - } - } - return message; - } - internalBinaryWrite(message: EmojiLikeToOthersWrapper2, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter { - /* SysMessage.EmojiLikeToOthersWrapper3 body = 1; */ - if (message.body) - EmojiLikeToOthersWrapper3.internalBinaryWrite(message.body, writer.tag(1, WireType.LengthDelimited).fork(), options).join(); - let u = options.writeUnknownFields; - if (u !== false) - (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer); - return writer; - } -} -/** - * @generated MessageType for protobuf message SysMessage.EmojiLikeToOthersWrapper2 - */ -export const EmojiLikeToOthersWrapper2 = new EmojiLikeToOthersWrapper2$Type(); -// @generated message type with reflection information, may provide speed optimized methods -class EmojiLikeToOthersWrapper3$Type extends MessageType { - constructor() { - super("SysMessage.EmojiLikeToOthersWrapper3", [ - { no: 2, name: "msgSpec", kind: "message", T: () => EmojiLikeToOthersMsgSpec }, - { no: 3, name: "attributes", kind: "message", T: () => EmojiLikeToOthersAttributes } - ]); - } - create(value?: PartialMessage): EmojiLikeToOthersWrapper3 { - const message = globalThis.Object.create((this.messagePrototype!)); - if (value !== undefined) - reflectionMergePartial(this, message, value); - return message; - } - internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: EmojiLikeToOthersWrapper3): EmojiLikeToOthersWrapper3 { - let message = target ?? this.create(), end = reader.pos + length; - while (reader.pos < end) { - let [fieldNo, wireType] = reader.tag(); - switch (fieldNo) { - case /* SysMessage.EmojiLikeToOthersMsgSpec msgSpec */ 2: - message.msgSpec = EmojiLikeToOthersMsgSpec.internalBinaryRead(reader, reader.uint32(), options, message.msgSpec); - break; - case /* SysMessage.EmojiLikeToOthersAttributes attributes */ 3: - message.attributes = EmojiLikeToOthersAttributes.internalBinaryRead(reader, reader.uint32(), options, message.attributes); - break; - default: - let u = options.readUnknownField; - if (u === "throw") - throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`); - let d = reader.skip(wireType); - if (u !== false) - (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d); - } - } - return message; - } - internalBinaryWrite(message: EmojiLikeToOthersWrapper3, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter { - /* SysMessage.EmojiLikeToOthersMsgSpec msgSpec = 2; */ - if (message.msgSpec) - EmojiLikeToOthersMsgSpec.internalBinaryWrite(message.msgSpec, writer.tag(2, WireType.LengthDelimited).fork(), options).join(); - /* SysMessage.EmojiLikeToOthersAttributes attributes = 3; */ - if (message.attributes) - EmojiLikeToOthersAttributes.internalBinaryWrite(message.attributes, writer.tag(3, WireType.LengthDelimited).fork(), options).join(); - let u = options.writeUnknownFields; - if (u !== false) - (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer); - return writer; - } -} -/** - * @generated MessageType for protobuf message SysMessage.EmojiLikeToOthersWrapper3 - */ -export const EmojiLikeToOthersWrapper3 = new EmojiLikeToOthersWrapper3$Type(); -// @generated message type with reflection information, may provide speed optimized methods -class EmojiLikeToOthersMsgSpec$Type extends MessageType { - constructor() { - super("SysMessage.EmojiLikeToOthersMsgSpec", [ - { no: 1, name: "msgSeq", kind: "scalar", T: 13 /*ScalarType.UINT32*/ } - ]); - } - create(value?: PartialMessage): EmojiLikeToOthersMsgSpec { - const message = globalThis.Object.create((this.messagePrototype!)); - message.msgSeq = 0; - if (value !== undefined) - reflectionMergePartial(this, message, value); - return message; - } - internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: EmojiLikeToOthersMsgSpec): EmojiLikeToOthersMsgSpec { - let message = target ?? this.create(), end = reader.pos + length; - while (reader.pos < end) { - let [fieldNo, wireType] = reader.tag(); - switch (fieldNo) { - case /* uint32 msgSeq */ 1: - message.msgSeq = reader.uint32(); - break; - default: - let u = options.readUnknownField; - if (u === "throw") - throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`); - let d = reader.skip(wireType); - if (u !== false) - (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d); - } - } - return message; - } - internalBinaryWrite(message: EmojiLikeToOthersMsgSpec, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter { - /* uint32 msgSeq = 1; */ - if (message.msgSeq !== 0) - writer.tag(1, WireType.Varint).uint32(message.msgSeq); - let u = options.writeUnknownFields; - if (u !== false) - (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer); - return writer; - } -} -/** - * @generated MessageType for protobuf message SysMessage.EmojiLikeToOthersMsgSpec - */ -export const EmojiLikeToOthersMsgSpec = new EmojiLikeToOthersMsgSpec$Type(); -// @generated message type with reflection information, may provide speed optimized methods -class EmojiLikeToOthersAttributes$Type extends MessageType { - constructor() { - super("SysMessage.EmojiLikeToOthersAttributes", [ - { no: 1, name: "emojiId", kind: "scalar", T: 9 /*ScalarType.STRING*/ }, - { no: 4, name: "senderUid", kind: "scalar", T: 9 /*ScalarType.STRING*/ }, - { no: 5, name: "operation", kind: "enum", T: () => ["SysMessage.EmojiLikeToOthersAttributes.Operation", EmojiLikeToOthersAttributes_Operation] } - ]); - } - create(value?: PartialMessage): EmojiLikeToOthersAttributes { - const message = globalThis.Object.create((this.messagePrototype!)); - message.emojiId = ""; - message.senderUid = ""; - message.operation = 0; - if (value !== undefined) - reflectionMergePartial(this, message, value); - return message; - } - internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: EmojiLikeToOthersAttributes): EmojiLikeToOthersAttributes { - let message = target ?? this.create(), end = reader.pos + length; - while (reader.pos < end) { - let [fieldNo, wireType] = reader.tag(); - switch (fieldNo) { - case /* string emojiId */ 1: - message.emojiId = reader.string(); - break; - case /* string senderUid */ 4: - message.senderUid = reader.string(); - break; - case /* SysMessage.EmojiLikeToOthersAttributes.Operation operation */ 5: - message.operation = reader.int32(); - break; - default: - let u = options.readUnknownField; - if (u === "throw") - throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`); - let d = reader.skip(wireType); - if (u !== false) - (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d); - } - } - return message; - } - internalBinaryWrite(message: EmojiLikeToOthersAttributes, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter { - /* string emojiId = 1; */ - if (message.emojiId !== "") - writer.tag(1, WireType.LengthDelimited).string(message.emojiId); - /* string senderUid = 4; */ - if (message.senderUid !== "") - writer.tag(4, WireType.LengthDelimited).string(message.senderUid); - /* SysMessage.EmojiLikeToOthersAttributes.Operation operation = 5; */ - if (message.operation !== 0) - writer.tag(5, WireType.Varint).int32(message.operation); - let u = options.writeUnknownFields; - if (u !== false) - (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer); - return writer; - } -} -/** - * @generated MessageType for protobuf message SysMessage.EmojiLikeToOthersAttributes - */ -export const EmojiLikeToOthersAttributes = new EmojiLikeToOthersAttributes$Type(); diff --git a/src/core/proto/GreyTipWrapper.ts b/src/core/proto/GreyTipWrapper.ts deleted file mode 100644 index 3c76a1e0..00000000 --- a/src/core/proto/GreyTipWrapper.ts +++ /dev/null @@ -1,104 +0,0 @@ -// @generated by protobuf-ts 2.9.4 -// @generated from protobuf file "GreyTipWrapper.proto" (package "SysMessage", syntax proto3) -// tslint:disable -import type { - BinaryReadOptions, - BinaryWriteOptions, - IBinaryReader, - IBinaryWriter, - PartialMessage, -} from '@protobuf-ts/runtime'; -import { MessageType, reflectionMergePartial, UnknownFieldHandler, WireType } from '@protobuf-ts/runtime'; - -/** - * @generated from protobuf message SysMessage.GreyTipWrapper - */ -export interface GreyTipWrapper { - /** - * @generated from protobuf field: uint32 subTypeId = 1; - */ - subTypeId: number; - /** - * @generated from protobuf field: uint32 groupCode = 4; - */ - groupCode: number; - /** - * @generated from protobuf field: uint32 subTypeIdMinusOne = 13; - */ - subTypeIdMinusOne: number; - /** - * @generated from protobuf field: bytes rest = 44; - */ - rest: Uint8Array; -} -// @generated message type with reflection information, may provide speed optimized methods -class GreyTipWrapper$Type extends MessageType { - constructor() { - super("SysMessage.GreyTipWrapper", [ - { no: 1, name: "subTypeId", kind: "scalar", T: 13 /*ScalarType.UINT32*/ }, - { no: 4, name: "groupCode", kind: "scalar", T: 13 /*ScalarType.UINT32*/ }, - { no: 13, name: "subTypeIdMinusOne", kind: "scalar", T: 13 /*ScalarType.UINT32*/ }, - { no: 44, name: "rest", kind: "scalar", T: 12 /*ScalarType.BYTES*/ } - ]); - } - create(value?: PartialMessage): GreyTipWrapper { - const message = globalThis.Object.create((this.messagePrototype!)); - message.subTypeId = 0; - message.groupCode = 0; - message.subTypeIdMinusOne = 0; - message.rest = new Uint8Array(0); - if (value !== undefined) - reflectionMergePartial(this, message, value); - return message; - } - internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: GreyTipWrapper): GreyTipWrapper { - let message = target ?? this.create(), end = reader.pos + length; - while (reader.pos < end) { - let [fieldNo, wireType] = reader.tag(); - switch (fieldNo) { - case /* uint32 subTypeId */ 1: - message.subTypeId = reader.uint32(); - break; - case /* uint32 groupCode */ 4: - message.groupCode = reader.uint32(); - break; - case /* uint32 subTypeIdMinusOne */ 13: - message.subTypeIdMinusOne = reader.uint32(); - break; - case /* bytes rest */ 44: - message.rest = reader.bytes(); - break; - default: - let u = options.readUnknownField; - if (u === "throw") - throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`); - let d = reader.skip(wireType); - if (u !== false) - (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d); - } - } - return message; - } - internalBinaryWrite(message: GreyTipWrapper, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter { - /* uint32 subTypeId = 1; */ - if (message.subTypeId !== 0) - writer.tag(1, WireType.Varint).uint32(message.subTypeId); - /* uint32 groupCode = 4; */ - if (message.groupCode !== 0) - writer.tag(4, WireType.Varint).uint32(message.groupCode); - /* uint32 subTypeIdMinusOne = 13; */ - if (message.subTypeIdMinusOne !== 0) - writer.tag(13, WireType.Varint).uint32(message.subTypeIdMinusOne); - /* bytes rest = 44; */ - if (message.rest.length) - writer.tag(44, WireType.LengthDelimited).bytes(message.rest); - let u = options.writeUnknownFields; - if (u !== false) - (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer); - return writer; - } -} -/** - * @generated MessageType for protobuf message SysMessage.GreyTipWrapper - */ -export const GreyTipWrapper = new GreyTipWrapper$Type(); diff --git a/src/core/proto/ProfileLike.ts b/src/core/proto/ProfileLike.ts new file mode 100644 index 00000000..b0a603fa --- /dev/null +++ b/src/core/proto/ProfileLike.ts @@ -0,0 +1,83 @@ +import * as pb from 'protobufjs'; + +// Proto: from src/core/proto/ProfileLike.proto +// Auther: Mlikiowa + +export interface LikeDetailType { + txt: string; + uin: pb.Long; + nickname: string; +} +export interface LikeMsgType { + times: number; + time: number; + detail: LikeDetailType; +} + +export interface ProfileLikeTipType { + msg: LikeMsgType; +} +export interface SysMessageHeaderType { + id: string; + timestamp: number; + sender: string; +} + +export interface SysMessageMsgSpecType { + msgType: number; + subType: number; + subSubType: number; + msgSeq: number; + time: number; + msgId: pb.Long; + other: number; +} +export interface SysMessageBodyWrapperType { + wrappedBody: Uint8Array; +} +export interface SysMessageType { + header: SysMessageHeaderType[]; + msgSpec: SysMessageMsgSpecType[]; + bodyWrapper: SysMessageBodyWrapperType; +} + +export const SysMessageHeader = new pb.Type("SysMessageHeader") + .add(new pb.Field("PeerNumber", 1, "uint32")) + .add(new pb.Field("PeerString", 2, "string")) + .add(new pb.Field("Uin", 5, "uint32")) + .add(new pb.Field("Uid", 6, "string", "optional")); + +export const SysMessageMsgSpec = new pb.Type("SysMessageMsgSpec") + .add(new pb.Field("msgType", 1, "uint32")) + .add(new pb.Field("subType", 2, "uint32")) + .add(new pb.Field("subSubType", 3, "uint32")) + .add(new pb.Field("msgSeq", 5, "uint32")) + .add(new pb.Field("time", 6, "uint32")) + .add(new pb.Field("msgId", 12, "uint64")) + .add(new pb.Field("other", 13, "uint32")); + +export const SysMessageBodyWrapper = new pb.Type("SysMessageBodyWrapper") + .add(new pb.Field("wrappedBody", 2, "bytes")); + +export const SysMessage = new pb.Type("SysMessage") + .add(SysMessageHeader) + .add(SysMessageMsgSpec) + .add(SysMessageBodyWrapper) + .add(new pb.Field("header", 1, "SysMessageHeader", "repeated")) + .add(new pb.Field("msgSpec", 2, "SysMessageMsgSpec", "repeated")) + .add(new pb.Field("bodyWrapper", 3, "SysMessageBodyWrapper")); + +export const likeDetail = new pb.Type("likeDetail") + .add(new pb.Field("txt", 1, "string")) + .add(new pb.Field("uin", 3, "int64")) + .add(new pb.Field("nickname", 5, "string")); + +export const likeMsg = new pb.Type("likeMsg") + .add(likeDetail) + .add(new pb.Field("times", 1, "int32")) + .add(new pb.Field("time", 2, "int32")) + .add(new pb.Field("detail", 3, "likeDetail")); + +export const profileLikeTip = new pb.Type("profileLikeTip") + .add(likeMsg) + .add(new pb.Field("msg", 14, "likeMsg")); \ No newline at end of file diff --git a/src/core/proto/ProfileLikeTip.ts b/src/core/proto/ProfileLikeTip.ts deleted file mode 100644 index 01ffa2e1..00000000 --- a/src/core/proto/ProfileLikeTip.ts +++ /dev/null @@ -1,226 +0,0 @@ -// @generated by protobuf-ts 2.9.4 -// @generated from protobuf file "ProfilelikeTip.proto" (package "SysMessage", syntax proto3) -// tslint:disable -import type { BinaryWriteOptions } from "@protobuf-ts/runtime"; -import type { IBinaryWriter } from "@protobuf-ts/runtime"; -import { WireType } from "@protobuf-ts/runtime"; -import type { BinaryReadOptions } from "@protobuf-ts/runtime"; -import type { IBinaryReader } from "@protobuf-ts/runtime"; -import { UnknownFieldHandler } from "@protobuf-ts/runtime"; -import type { PartialMessage } from "@protobuf-ts/runtime"; -import { reflectionMergePartial } from "@protobuf-ts/runtime"; -import { MessageType } from "@protobuf-ts/runtime"; -/** - * @generated from protobuf message SysMessage.likeDetail - */ -export interface likeDetail { - /** - * @generated from protobuf field: string txt = 1; - */ - txt: string; - /** - * @generated from protobuf field: int64 uin = 3; - */ - uin: bigint; - /** - * @generated from protobuf field: string nickname = 5; - */ - nickname: string; -} -/** - * @generated from protobuf message SysMessage.likeMsg - */ -export interface likeMsg { - /** - * @generated from protobuf field: int32 times = 1; - */ - times: number; - /** - * @generated from protobuf field: int32 time = 2; - */ - time: number; - /** - * @generated from protobuf field: SysMessage.likeDetail detail = 3; - */ - detail?: likeDetail; -} -/** - * @generated from protobuf message SysMessage.profileLikeTip - */ -export interface profileLikeTip { - /** - * @generated from protobuf field: SysMessage.likeMsg msg = 14; - */ - msg?: likeMsg; -} -// @generated message type with reflection information, may provide speed optimized methods -class likeDetail$Type extends MessageType { - constructor() { - super("SysMessage.likeDetail", [ - { no: 1, name: "txt", kind: "scalar", T: 9 /*ScalarType.STRING*/ }, - { no: 3, name: "uin", kind: "scalar", T: 3 /*ScalarType.INT64*/, L: 0 /*LongType.BIGINT*/ }, - { no: 5, name: "nickname", kind: "scalar", T: 9 /*ScalarType.STRING*/ } - ]); - } - create(value?: PartialMessage): likeDetail { - const message = globalThis.Object.create((this.messagePrototype!)); - message.txt = ""; - message.uin = 0n; - message.nickname = ""; - if (value !== undefined) - reflectionMergePartial(this, message, value); - return message; - } - internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: likeDetail): likeDetail { - let message = target ?? this.create(), end = reader.pos + length; - while (reader.pos < end) { - let [fieldNo, wireType] = reader.tag(); - switch (fieldNo) { - case /* string txt */ 1: - message.txt = reader.string(); - break; - case /* int64 uin */ 3: - message.uin = reader.int64().toBigInt(); - break; - case /* string nickname */ 5: - message.nickname = reader.string(); - break; - default: - let u = options.readUnknownField; - if (u === "throw") - throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`); - let d = reader.skip(wireType); - if (u !== false) - (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d); - } - } - return message; - } - internalBinaryWrite(message: likeDetail, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter { - /* string txt = 1; */ - if (message.txt !== "") - writer.tag(1, WireType.LengthDelimited).string(message.txt); - /* int64 uin = 3; */ - if (message.uin !== 0n) - writer.tag(3, WireType.Varint).int64(message.uin); - /* string nickname = 5; */ - if (message.nickname !== "") - writer.tag(5, WireType.LengthDelimited).string(message.nickname); - let u = options.writeUnknownFields; - if (u !== false) - (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer); - return writer; - } -} -/** - * @generated MessageType for protobuf message SysMessage.likeDetail - */ -export const likeDetail = new likeDetail$Type(); -// @generated message type with reflection information, may provide speed optimized methods -class likeMsg$Type extends MessageType { - constructor() { - super("SysMessage.likeMsg", [ - { no: 1, name: "times", kind: "scalar", T: 5 /*ScalarType.INT32*/ }, - { no: 2, name: "time", kind: "scalar", T: 5 /*ScalarType.INT32*/ }, - { no: 3, name: "detail", kind: "message", T: () => likeDetail } - ]); - } - create(value?: PartialMessage): likeMsg { - const message = globalThis.Object.create((this.messagePrototype!)); - message.times = 0; - message.time = 0; - if (value !== undefined) - reflectionMergePartial(this, message, value); - return message; - } - internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: likeMsg): likeMsg { - let message = target ?? this.create(), end = reader.pos + length; - while (reader.pos < end) { - let [fieldNo, wireType] = reader.tag(); - switch (fieldNo) { - case /* int32 times */ 1: - message.times = reader.int32(); - break; - case /* int32 time */ 2: - message.time = reader.int32(); - break; - case /* SysMessage.likeDetail detail */ 3: - message.detail = likeDetail.internalBinaryRead(reader, reader.uint32(), options, message.detail); - break; - default: - let u = options.readUnknownField; - if (u === "throw") - throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`); - let d = reader.skip(wireType); - if (u !== false) - (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d); - } - } - return message; - } - internalBinaryWrite(message: likeMsg, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter { - /* int32 times = 1; */ - if (message.times !== 0) - writer.tag(1, WireType.Varint).int32(message.times); - /* int32 time = 2; */ - if (message.time !== 0) - writer.tag(2, WireType.Varint).int32(message.time); - /* SysMessage.likeDetail detail = 3; */ - if (message.detail) - likeDetail.internalBinaryWrite(message.detail, writer.tag(3, WireType.LengthDelimited).fork(), options).join(); - let u = options.writeUnknownFields; - if (u !== false) - (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer); - return writer; - } -} -/** - * @generated MessageType for protobuf message SysMessage.likeMsg - */ -export const likeMsg = new likeMsg$Type(); -// @generated message type with reflection information, may provide speed optimized methods -class profileLikeTip$Type extends MessageType { - constructor() { - super("SysMessage.profileLikeTip", [ - { no: 14, name: "msg", kind: "message", T: () => likeMsg } - ]); - } - create(value?: PartialMessage): profileLikeTip { - const message = globalThis.Object.create((this.messagePrototype!)); - if (value !== undefined) - reflectionMergePartial(this, message, value); - return message; - } - internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: profileLikeTip): profileLikeTip { - let message = target ?? this.create(), end = reader.pos + length; - while (reader.pos < end) { - let [fieldNo, wireType] = reader.tag(); - switch (fieldNo) { - case /* SysMessage.likeMsg msg */ 14: - message.msg = likeMsg.internalBinaryRead(reader, reader.uint32(), options, message.msg); - break; - default: - let u = options.readUnknownField; - if (u === "throw") - throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`); - let d = reader.skip(wireType); - if (u !== false) - (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d); - } - } - return message; - } - internalBinaryWrite(message: profileLikeTip, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter { - /* SysMessage.likeMsg msg = 14; */ - if (message.msg) - likeMsg.internalBinaryWrite(message.msg, writer.tag(14, WireType.LengthDelimited).fork(), options).join(); - let u = options.writeUnknownFields; - if (u !== false) - (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer); - return writer; - } -} -/** - * @generated MessageType for protobuf message SysMessage.profileLikeTip - */ -export const profileLikeTip = new profileLikeTip$Type(); diff --git a/src/core/proto/SysMessage.ts b/src/core/proto/SysMessage.ts deleted file mode 100644 index 09bf02fe..00000000 --- a/src/core/proto/SysMessage.ts +++ /dev/null @@ -1,435 +0,0 @@ -// @generated by protobuf-ts 2.9.4 -// @generated from protobuf file "SysMessage.proto" (package "SysMessage", syntax proto3) -// tslint:disable -import type { - BinaryReadOptions, - BinaryWriteOptions, - IBinaryReader, - IBinaryWriter, - PartialMessage, -} from '@protobuf-ts/runtime'; -import { MessageType, reflectionMergePartial, UnknownFieldHandler, WireType } from '@protobuf-ts/runtime'; - -/** - * @generated from protobuf message SysMessage.SysMessage - */ -export interface SysMessage { - /** - * @generated from protobuf field: repeated SysMessage.SysMessageHeader header = 1; - */ - header: SysMessageHeader[]; - /** - * @generated from protobuf field: repeated SysMessage.SysMessageMsgSpec msgSpec = 2; - */ - msgSpec: SysMessageMsgSpec[]; - /** - * @generated from protobuf field: SysMessage.SysMessageBodyWrapper bodyWrapper = 3; - */ - bodyWrapper?: SysMessageBodyWrapper; -} -/** - * @generated from protobuf message SysMessage.SysMessageHeader - */ -export interface SysMessageHeader { - /** - * @generated from protobuf field: uint32 PeerNumber = 1 [json_name = "PeerNumber"]; - */ - peerNumber: number; - /** - * @generated from protobuf field: string PeerString = 2 [json_name = "PeerString"]; - */ - peerString: string; - /** - * @generated from protobuf field: uint32 Uin = 5 [json_name = "Uin"]; - */ - uin: number; - /** - * @generated from protobuf field: optional string Uid = 6 [json_name = "Uid"]; - */ - uid?: string; -} -/** - * @generated from protobuf message SysMessage.SysMessageMsgSpec - */ -export interface SysMessageMsgSpec { - /** - * @generated from protobuf field: uint32 msgType = 1; - */ - msgType: number; - /** - * @generated from protobuf field: uint32 subType = 2; - */ - subType: number; - /** - * @generated from protobuf field: uint32 subSubType = 3; - */ - subSubType: number; - /** - * @generated from protobuf field: uint32 msgSeq = 5; - */ - msgSeq: number; - /** - * @generated from protobuf field: uint32 time = 6; - */ - time: number; - /** - * @generated from protobuf field: uint64 msgId = 12; - */ - msgId: bigint; - /** - * @generated from protobuf field: uint32 other = 13; - */ - other: number; -} -/** - * @generated from protobuf message SysMessage.SysMessageBodyWrapper - */ -export interface SysMessageBodyWrapper { - /** - * @generated from protobuf field: bytes wrappedBody = 2; - */ - wrappedBody: Uint8Array; // Find the first [08], or ignore the first 7 bytes? - // And it becomes another ProtoBuf message. -} -/** - * @generated from protobuf message SysMessage.KeyValuePair - */ -export interface KeyValuePair { - /** - * @generated from protobuf field: string key = 1; - */ - key: string; - /** - * @generated from protobuf field: string value = 2; - */ - value: string; -} -// @generated message type with reflection information, may provide speed optimized methods -class SysMessage$Type extends MessageType { - constructor() { - super("SysMessage.SysMessage", [ - { no: 1, name: "header", kind: "message", repeat: 1 /*RepeatType.PACKED*/, T: () => SysMessageHeader }, - { no: 2, name: "msgSpec", kind: "message", repeat: 1 /*RepeatType.PACKED*/, T: () => SysMessageMsgSpec }, - { no: 3, name: "bodyWrapper", kind: "message", T: () => SysMessageBodyWrapper } - ]); - } - create(value?: PartialMessage): SysMessage { - const message = globalThis.Object.create((this.messagePrototype!)); - message.header = []; - message.msgSpec = []; - if (value !== undefined) - reflectionMergePartial(this, message, value); - return message; - } - internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: SysMessage): SysMessage { - let message = target ?? this.create(), end = reader.pos + length; - while (reader.pos < end) { - let [fieldNo, wireType] = reader.tag(); - switch (fieldNo) { - case /* repeated SysMessage.SysMessageHeader header */ 1: - message.header.push(SysMessageHeader.internalBinaryRead(reader, reader.uint32(), options)); - break; - case /* repeated SysMessage.SysMessageMsgSpec msgSpec */ 2: - message.msgSpec.push(SysMessageMsgSpec.internalBinaryRead(reader, reader.uint32(), options)); - break; - case /* SysMessage.SysMessageBodyWrapper bodyWrapper */ 3: - message.bodyWrapper = SysMessageBodyWrapper.internalBinaryRead(reader, reader.uint32(), options, message.bodyWrapper); - break; - default: - let u = options.readUnknownField; - if (u === "throw") - throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`); - let d = reader.skip(wireType); - if (u !== false) - (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d); - } - } - return message; - } - internalBinaryWrite(message: SysMessage, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter { - /* repeated SysMessage.SysMessageHeader header = 1; */ - for (let i = 0; i < message.header.length; i++) - SysMessageHeader.internalBinaryWrite(message.header[i], writer.tag(1, WireType.LengthDelimited).fork(), options).join(); - /* repeated SysMessage.SysMessageMsgSpec msgSpec = 2; */ - for (let i = 0; i < message.msgSpec.length; i++) - SysMessageMsgSpec.internalBinaryWrite(message.msgSpec[i], writer.tag(2, WireType.LengthDelimited).fork(), options).join(); - /* SysMessage.SysMessageBodyWrapper bodyWrapper = 3; */ - if (message.bodyWrapper) - SysMessageBodyWrapper.internalBinaryWrite(message.bodyWrapper, writer.tag(3, WireType.LengthDelimited).fork(), options).join(); - let u = options.writeUnknownFields; - if (u !== false) - (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer); - return writer; - } -} -/** - * @generated MessageType for protobuf message SysMessage.SysMessage - */ -export const SysMessage = new SysMessage$Type(); -// @generated message type with reflection information, may provide speed optimized methods -class SysMessageHeader$Type extends MessageType { - constructor() { - super("SysMessage.SysMessageHeader", [ - { no: 1, name: "PeerNumber", kind: "scalar", jsonName: "PeerNumber", T: 13 /*ScalarType.UINT32*/ }, - { no: 2, name: "PeerString", kind: "scalar", jsonName: "PeerString", T: 9 /*ScalarType.STRING*/ }, - { no: 5, name: "Uin", kind: "scalar", jsonName: "Uin", T: 13 /*ScalarType.UINT32*/ }, - { no: 6, name: "Uid", kind: "scalar", jsonName: "Uid", opt: true, T: 9 /*ScalarType.STRING*/ } - ]); - } - create(value?: PartialMessage): SysMessageHeader { - const message = globalThis.Object.create((this.messagePrototype!)); - message.peerNumber = 0; - message.peerString = ""; - message.uin = 0; - if (value !== undefined) - reflectionMergePartial(this, message, value); - return message; - } - internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: SysMessageHeader): SysMessageHeader { - let message = target ?? this.create(), end = reader.pos + length; - while (reader.pos < end) { - let [fieldNo, wireType] = reader.tag(); - switch (fieldNo) { - case /* uint32 PeerNumber = 1 [json_name = "PeerNumber"];*/ 1: - message.peerNumber = reader.uint32(); - break; - case /* string PeerString = 2 [json_name = "PeerString"];*/ 2: - message.peerString = reader.string(); - break; - case /* uint32 Uin = 5 [json_name = "Uin"];*/ 5: - message.uin = reader.uint32(); - break; - case /* optional string Uid = 6 [json_name = "Uid"];*/ 6: - message.uid = reader.string(); - break; - default: - let u = options.readUnknownField; - if (u === "throw") - throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`); - let d = reader.skip(wireType); - if (u !== false) - (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d); - } - } - return message; - } - internalBinaryWrite(message: SysMessageHeader, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter { - /* uint32 PeerNumber = 1 [json_name = "PeerNumber"]; */ - if (message.peerNumber !== 0) - writer.tag(1, WireType.Varint).uint32(message.peerNumber); - /* string PeerString = 2 [json_name = "PeerString"]; */ - if (message.peerString !== "") - writer.tag(2, WireType.LengthDelimited).string(message.peerString); - /* uint32 Uin = 5 [json_name = "Uin"]; */ - if (message.uin !== 0) - writer.tag(5, WireType.Varint).uint32(message.uin); - /* optional string Uid = 6 [json_name = "Uid"]; */ - if (message.uid !== undefined) - writer.tag(6, WireType.LengthDelimited).string(message.uid); - let u = options.writeUnknownFields; - if (u !== false) - (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer); - return writer; - } -} -/** - * @generated MessageType for protobuf message SysMessage.SysMessageHeader - */ -export const SysMessageHeader = new SysMessageHeader$Type(); -// @generated message type with reflection information, may provide speed optimized methods -class SysMessageMsgSpec$Type extends MessageType { - constructor() { - super("SysMessage.SysMessageMsgSpec", [ - { no: 1, name: "msgType", kind: "scalar", T: 13 /*ScalarType.UINT32*/ }, - { no: 2, name: "subType", kind: "scalar", T: 13 /*ScalarType.UINT32*/ }, - { no: 3, name: "subSubType", kind: "scalar", T: 13 /*ScalarType.UINT32*/ }, - { no: 5, name: "msgSeq", kind: "scalar", T: 13 /*ScalarType.UINT32*/ }, - { no: 6, name: "time", kind: "scalar", T: 13 /*ScalarType.UINT32*/ }, - { no: 12, name: "msgId", kind: "scalar", T: 4 /*ScalarType.UINT64*/, L: 0 /*LongType.BIGINT*/ }, - { no: 13, name: "other", kind: "scalar", T: 13 /*ScalarType.UINT32*/ } - ]); - } - create(value?: PartialMessage): SysMessageMsgSpec { - const message = globalThis.Object.create((this.messagePrototype!)); - message.msgType = 0; - message.subType = 0; - message.subSubType = 0; - message.msgSeq = 0; - message.time = 0; - message.msgId = 0n; - message.other = 0; - if (value !== undefined) - reflectionMergePartial(this, message, value); - return message; - } - internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: SysMessageMsgSpec): SysMessageMsgSpec { - let message = target ?? this.create(), end = reader.pos + length; - while (reader.pos < end) { - let [fieldNo, wireType] = reader.tag(); - switch (fieldNo) { - case /* uint32 msgType */ 1: - message.msgType = reader.uint32(); - break; - case /* uint32 subType */ 2: - message.subType = reader.uint32(); - break; - case /* uint32 subSubType */ 3: - message.subSubType = reader.uint32(); - break; - case /* uint32 msgSeq */ 5: - message.msgSeq = reader.uint32(); - break; - case /* uint32 time */ 6: - message.time = reader.uint32(); - break; - case /* uint64 msgId */ 12: - message.msgId = reader.uint64().toBigInt(); - break; - case /* uint32 other */ 13: - message.other = reader.uint32(); - break; - default: - let u = options.readUnknownField; - if (u === "throw") - throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`); - let d = reader.skip(wireType); - if (u !== false) - (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d); - } - } - return message; - } - internalBinaryWrite(message: SysMessageMsgSpec, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter { - /* uint32 msgType = 1; */ - if (message.msgType !== 0) - writer.tag(1, WireType.Varint).uint32(message.msgType); - /* uint32 subType = 2; */ - if (message.subType !== 0) - writer.tag(2, WireType.Varint).uint32(message.subType); - /* uint32 subSubType = 3; */ - if (message.subSubType !== 0) - writer.tag(3, WireType.Varint).uint32(message.subSubType); - /* uint32 msgSeq = 5; */ - if (message.msgSeq !== 0) - writer.tag(5, WireType.Varint).uint32(message.msgSeq); - /* uint32 time = 6; */ - if (message.time !== 0) - writer.tag(6, WireType.Varint).uint32(message.time); - /* uint64 msgId = 12; */ - if (message.msgId !== 0n) - writer.tag(12, WireType.Varint).uint64(message.msgId); - /* uint32 other = 13; */ - if (message.other !== 0) - writer.tag(13, WireType.Varint).uint32(message.other); - let u = options.writeUnknownFields; - if (u !== false) - (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer); - return writer; - } -} -/** - * @generated MessageType for protobuf message SysMessage.SysMessageMsgSpec - */ -export const SysMessageMsgSpec = new SysMessageMsgSpec$Type(); -// @generated message type with reflection information, may provide speed optimized methods -class SysMessageBodyWrapper$Type extends MessageType { - constructor() { - super("SysMessage.SysMessageBodyWrapper", [ - { no: 2, name: "wrappedBody", kind: "scalar", T: 12 /*ScalarType.BYTES*/ } - ]); - } - create(value?: PartialMessage): SysMessageBodyWrapper { - const message = globalThis.Object.create((this.messagePrototype!)); - message.wrappedBody = new Uint8Array(0); - if (value !== undefined) - reflectionMergePartial(this, message, value); - return message; - } - internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: SysMessageBodyWrapper): SysMessageBodyWrapper { - let message = target ?? this.create(), end = reader.pos + length; - while (reader.pos < end) { - let [fieldNo, wireType] = reader.tag(); - switch (fieldNo) { - case /* bytes wrappedBody */ 2: - message.wrappedBody = reader.bytes(); - break; - default: - let u = options.readUnknownField; - if (u === "throw") - throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`); - let d = reader.skip(wireType); - if (u !== false) - (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d); - } - } - return message; - } - internalBinaryWrite(message: SysMessageBodyWrapper, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter { - /* bytes wrappedBody = 2; */ - if (message.wrappedBody.length) - writer.tag(2, WireType.LengthDelimited).bytes(message.wrappedBody); - let u = options.writeUnknownFields; - if (u !== false) - (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer); - return writer; - } -} -/** - * @generated MessageType for protobuf message SysMessage.SysMessageBodyWrapper - */ -export const SysMessageBodyWrapper = new SysMessageBodyWrapper$Type(); -// @generated message type with reflection information, may provide speed optimized methods -class KeyValuePair$Type extends MessageType { - constructor() { - super("SysMessage.KeyValuePair", [ - { no: 1, name: "key", kind: "scalar", T: 9 /*ScalarType.STRING*/ }, - { no: 2, name: "value", kind: "scalar", T: 9 /*ScalarType.STRING*/ } - ]); - } - create(value?: PartialMessage): KeyValuePair { - const message = globalThis.Object.create((this.messagePrototype!)); - message.key = ""; - message.value = ""; - if (value !== undefined) - reflectionMergePartial(this, message, value); - return message; - } - internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: KeyValuePair): KeyValuePair { - let message = target ?? this.create(), end = reader.pos + length; - while (reader.pos < end) { - let [fieldNo, wireType] = reader.tag(); - switch (fieldNo) { - case /* string key */ 1: - message.key = reader.string(); - break; - case /* string value */ 2: - message.value = reader.string(); - break; - default: - let u = options.readUnknownField; - if (u === "throw") - throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`); - let d = reader.skip(wireType); - if (u !== false) - (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d); - } - } - return message; - } - internalBinaryWrite(message: KeyValuePair, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter { - /* string key = 1; */ - if (message.key !== "") - writer.tag(1, WireType.LengthDelimited).string(message.key); - /* string value = 2; */ - if (message.value !== "") - writer.tag(2, WireType.LengthDelimited).string(message.value); - let u = options.writeUnknownFields; - if (u !== false) - (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer); - return writer; - } -} -/** - * @generated MessageType for protobuf message SysMessage.KeyValuePair - */ -export const KeyValuePair = new KeyValuePair$Type(); diff --git a/src/onebot/index.ts b/src/onebot/index.ts index a87c3220..848a7358 100644 --- a/src/onebot/index.ts +++ b/src/onebot/index.ts @@ -43,9 +43,9 @@ import { OB11FriendRecallNoticeEvent } from '@/onebot/event/notice/OB11FriendRec import { OB11GroupRecallNoticeEvent } from '@/onebot/event/notice/OB11GroupRecallNoticeEvent'; import { LRUCache } from '@/common/lru-cache'; import { NodeIKernelRecentContactListener } from '@/core/listeners/NodeIKernelRecentContactListener'; -import { SysMessage } from '@/core/proto/SysMessage'; -import { profileLikeTip } from '@/core/proto/ProfileLikeTip'; import { OB11ProfileLikeEvent } from './event/notice/OB11ProfileLikeEvent'; +import { profileLikeTip, ProfileLikeTipType, SysMessage, SysMessageMsgSpecType, SysMessageType } from '@/core/proto/ProfileLike'; +import { Message } from 'protobufjs'; //OneBot实现类 export class NapCatOneBot11Adapter { @@ -240,18 +240,18 @@ export class NapCatOneBot11Adapter { private initMsgListener() { const msgListener = new NodeIKernelMsgListener(); - msgListener.onRecvSysMsg = async (msg) => { - const sysMsg = SysMessage.fromBinary(Uint8Array.from(msg)); + const sysMsg = SysMessage.decode(Uint8Array.from(msg)) as unknown as SysMessageType; if (sysMsg.msgSpec.length === 0) { return; } const { msgType, subType, subSubType } = sysMsg.msgSpec[0]; if (msgType === 528 && subType === 39 && subSubType === 39) { - const likeTip = profileLikeTip.fromBinary(Uint8Array.from(sysMsg.bodyWrapper!.wrappedBody.slice(12))); + const likeTip = profileLikeTip.decode(Uint8Array.from(sysMsg.bodyWrapper.wrappedBody.slice(12))) as unknown as ProfileLikeTipType; this.core.context.logger.logDebug("收到点赞通知消息"); - if (!likeTip.msg) return; - const detail = likeTip.msg.detail; + const likeMsg = likeTip.msg; + if (!likeMsg) return; + const detail = likeMsg.detail; if (!detail) return; const times = detail.txt.match(/\d+/) ?? "0"; await this.networkManager.emitEvent(new OB11ProfileLikeEvent( @@ -259,7 +259,7 @@ export class NapCatOneBot11Adapter { Number(detail.uin), detail.nickname, parseInt(times[0], 10), - likeTip.msg.time, + likeMsg.time, )).catch(e => this.context.logger.logError('处理被点赞事件失败', e)); }; /*