From c706d2fda783418297cc73670404744abbad0efc Mon Sep 17 00:00:00 2001 From: JustAnotherID Date: Tue, 16 Apr 2024 23:30:49 +0800 Subject: [PATCH] feat: friend request and recall event --- client/base.go | 2 ++ client/event.go | 4 ++++ client/listener.go | 20 +++++++++++++++++++- event/friend.go | 41 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 event/friend.go diff --git a/client/base.go b/client/base.go index a338e362..30068b6f 100644 --- a/client/base.go +++ b/client/base.go @@ -66,6 +66,8 @@ type QQClient struct { GroupMemberLeaveEvent EventHandle[*event.GroupMemberDecrease] // 成员退群 GroupMuteEvent EventHandle[*event.GroupMute] GroupRecallEvent EventHandle[*event.GroupRecall] + FriendRequestEvent EventHandle[*event.FriendRequest] // 好友申请 + FriendRecallEvent EventHandle[*event.FriendRecall] } func (c *QQClient) SendOidbPacket(pkt *oidb.OidbPacket) error { diff --git a/client/event.go b/client/event.go index 6fff8af0..a442d4b4 100644 --- a/client/event.go +++ b/client/event.go @@ -66,6 +66,10 @@ func OnEvent(client *QQClient, msg any) { client.GroupMuteEvent.dispatch(client, msg) case *event.GroupRecall: client.GroupRecallEvent.dispatch(client, msg) + case *event.FriendRequest: + client.FriendRequestEvent.dispatch(client, msg) + case *event.FriendRecall: + client.FriendRecallEvent.dispatch(client, msg) case nil: networkLogger.Errorf("nil event msg, ignore") default: diff --git a/client/listener.go b/client/listener.go index 33762907..cdd4e3f1 100644 --- a/client/listener.go +++ b/client/listener.go @@ -78,7 +78,25 @@ func decodeOlPushServicePacket(c *QQClient, pkt *wtlogin.SSOPacket) (any, error) return nil, err } return eventConverter.ParseInviteNotice(&pb), nil - case 0x2DC: // grp event, 732 + case 0x210: // friend event, 528 + subType := pkg.ContentHead.SubType.Unwrap() + switch subType { + case 35: // friend request notice + pb := message.FriendRequest{} + err = proto.Unmarshal(pkg.Body.MsgContent, &pb) + if err != nil { + return nil, err + } + return eventConverter.ParseFriendRequestNotice(&msg, &pb), nil + case 138: // friend recall + pb := message.FriendRecall{} + err = proto.Unmarshal(pkg.Body.MsgContent, &pb) + if err != nil { + return nil, err + } + return eventConverter.ParseFriendRecallEvent(&pb), nil + } + case 0x2DC: // grp event, 732 subType := pkg.ContentHead.SubType.Unwrap() switch subType { case 20: // nudget(grp_id only) diff --git a/event/friend.go b/event/friend.go new file mode 100644 index 00000000..35e36210 --- /dev/null +++ b/event/friend.go @@ -0,0 +1,41 @@ +package event + +import ( + "github.com/LagrangeDev/LagrangeGo/packets/pb/message" +) + +type ( + FriendRequest struct { + SourceUin uint32 + SourceUid string + Msg string + Source string + } + + FriendRecall struct { + FromUid string + Sequence uint64 + Time uint32 + Random uint32 + } +) + +func ParseFriendRequestNotice(msg *message.PushMsg, event *message.FriendRequest) *FriendRequest { + info := event.Info + return &FriendRequest{ + SourceUin: msg.Message.ResponseHead.FromUin, + SourceUid: info.SourceUid, + Msg: info.Message, + Source: info.Source, + } +} + +func ParseFriendRecallEvent(event *message.FriendRecall) *FriendRecall { + info := event.Info + return &FriendRecall{ + FromUid: info.FromUid, + Sequence: uint64(info.Sequence), + Time: info.Time, + Random: info.Random, + } +}