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] =?UTF-8?q?feat:=20=E8=A2=AB=E7=82=B9=E8=B5=9E=E4=BA=8B?=
 =?UTF-8?q?=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<ProfileLikeTip> {
+class likeDetail$Type extends MessageType<likeDetail> {
     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>): ProfileLikeTip {
+    create(value?: PartialMessage<likeDetail>): likeDetail {
         const message = globalThis.Object.create((this.messagePrototype!));
+        message.txt = "";
+        message.uin = 0n;
+        message.nickname = "";
         if (value !== undefined)
-            reflectionMergePartial<ProfileLikeTip>(this, message, value);
+            reflectionMergePartial<likeDetail>(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<ProfileLikeTip> {
         }
         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<ProfileLikeTip> {
     }
 }
 /**
- * @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<ProfileLikeDetail> {
+class likeMsg$Type extends MessageType<likeMsg> {
     constructor() {
-        super("SysMessage.ProfileLikeDetail", [
-            { no: 14, name: "like_detail", kind: "message", T: () => LikeDetail }
-        ]);
-    }
-    create(value?: PartialMessage<ProfileLikeDetail>): ProfileLikeDetail {
-        const message = globalThis.Object.create((this.messagePrototype!));
-        if (value !== undefined)
-            reflectionMergePartial<ProfileLikeDetail>(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<LikeDetail> {
-    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>): LikeDetail {
+    create(value?: PartialMessage<likeMsg>): likeMsg {
         const message = globalThis.Object.create((this.messagePrototype!));
         message.times = 0;
         message.time = 0;
         if (value !== undefined)
-            reflectionMergePartial<LikeDetail>(this, message, value);
+            reflectionMergePartial<likeMsg>(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<LikeDetail> {
                 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<LikeDetail> {
         }
         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<LikeDetail> {
     }
 }
 /**
- * @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<TextTip> {
+class profileLikeTip$Type extends MessageType<profileLikeTip> {
     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>): TextTip {
+    create(value?: PartialMessage<profileLikeTip>): profileLikeTip {
         const message = globalThis.Object.create((this.messagePrototype!));
-        message.txt = "";
-        message.qq = 0n;
-        message.nick = "";
         if (value !== undefined)
-            reflectionMergePartial<TextTip>(this, message, value);
+            reflectionMergePartial<profileLikeTip>(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<TextTip> {
         }
         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<TextTip> {
     }
 }
 /**
- * @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)));