Skip to content

Commit

Permalink
Merge pull request #11 from JustAnotherID/feat/friend-event
Browse files Browse the repository at this point in the history
  • Loading branch information
Redmomn authored Apr 16, 2024
2 parents ed03302 + c706d2f commit fd298cc
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 1 deletion.
2 changes: 2 additions & 0 deletions client/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions client/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
20 changes: 19 additions & 1 deletion client/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
41 changes: 41 additions & 0 deletions event/friend.go
Original file line number Diff line number Diff line change
@@ -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,
}
}

0 comments on commit fd298cc

Please sign in to comment.