1
0
mirror of https://github.com/Mrs4s/MiraiGo.git synced 2025-05-04 19:17:38 +08:00

supported NewFriendRequestEvent.

This commit is contained in:
Mrs4s 2020-07-16 05:21:09 +08:00
parent 6edec8d4d6
commit 2f1e831448
6 changed files with 106 additions and 36 deletions

View File

@ -36,6 +36,7 @@ qq-android协议的golang实现 移植于Mirai
- [x] 收到邀请进群通知 - [x] 收到邀请进群通知
- [x] 收到其他用户进群请求 - [x] 收到其他用户进群请求
- [ ] 新好友 - [ ] 新好友
- [x] 新好友请求
#### 主动操作 #### 主动操作
- [x] 发送群消息 - [x] 发送群消息
@ -48,7 +49,7 @@ qq-android协议的golang实现 移植于Mirai
- [ ] 获取/刷新讨论组列表 - [ ] 获取/刷新讨论组列表
- [ ] 处理加群请求 - [ ] 处理加群请求
- [ ] 处理好友请求 - [ ] 处理好友请求
- [ ] 撤回消息 - [ ] 撤回消息
- [ ] 群公告设置 - [ ] 群公告设置
- [ ] 群设置 - [ ] 群设置
- [ ] 修改群成员Card - [ ] 修改群成员Card

View File

@ -503,3 +503,24 @@ func (c *QQClient) buildSystemMsgNewGroupPacket() (uint16, []byte) {
packet := packets.BuildUniPacket(c.Uin, seq, "ProfileService.Pb.ReqSystemMsgNew.Group", 1, c.OutGoingPacketSessionId, EmptyBytes, c.sigInfo.d2Key, payload) packet := packets.BuildUniPacket(c.Uin, seq, "ProfileService.Pb.ReqSystemMsgNew.Group", 1, c.OutGoingPacketSessionId, EmptyBytes, c.sigInfo.d2Key, payload)
return seq, packet return seq, packet
} }
// ProfileService.Pb.ReqSystemMsgNew.Friend
func (c *QQClient) buildSystemMsgNewFriendPacket() (uint16, []byte) {
seq := c.nextSeq()
req := &structmsg.ReqSystemMsgNew{
MsgNum: 20,
Version: 1000,
Checktype: 2,
Flag: &structmsg.FlagInfo{
FrdMsgDiscuss2ManyChat: 1,
FrdMsgGetBusiCard: 1,
FrdMsgNeedWaitingMsg: 1,
FrdMsgUint32NeedAllUnreadMsg: 1,
GrpMsgMaskInviteAutoJoin: 1,
},
FriendMsgTypeFlag: 1,
}
payload, _ := proto.Marshal(req)
packet := packets.BuildUniPacket(c.Uin, seq, "ProfileService.Pb.ReqSystemMsgNew.Friend", 1, c.OutGoingPacketSessionId, EmptyBytes, c.sigInfo.d2Key, payload)
return seq, packet
}

View File

@ -3,7 +3,6 @@ package client
import ( import (
"crypto/md5" "crypto/md5"
"errors" "errors"
"fmt"
"github.com/Mrs4s/MiraiGo/binary" "github.com/Mrs4s/MiraiGo/binary"
"github.com/Mrs4s/MiraiGo/client/pb" "github.com/Mrs4s/MiraiGo/client/pb"
"github.com/Mrs4s/MiraiGo/message" "github.com/Mrs4s/MiraiGo/message"
@ -108,6 +107,7 @@ func NewClientMd5(uin int64, passwordMd5 [16]byte) *QQClient {
"friendlist.GetTroopMemberListReq": decodeGroupMemberListResponse, "friendlist.GetTroopMemberListReq": decodeGroupMemberListResponse,
"ImgStore.GroupPicUp": decodeGroupImageStoreResponse, "ImgStore.GroupPicUp": decodeGroupImageStoreResponse,
"ProfileService.Pb.ReqSystemMsgNew.Group": decodeSystemMsgGroupPacket, "ProfileService.Pb.ReqSystemMsgNew.Group": decodeSystemMsgGroupPacket,
"ProfileService.Pb.ReqSystemMsgNew.Friend": decodeSystemMsgFriendPacket,
}, },
handlers: map[uint16]func(interface{}, error){}, handlers: map[uint16]func(interface{}, error){},
sigInfo: &loginSigInfo{}, sigInfo: &loginSigInfo{},
@ -464,7 +464,7 @@ func (c *QQClient) loop() {
continue continue
} }
} }
fmt.Println(pkt.CommandName) //fmt.Println(pkt.CommandName)
go func() { go func() {
decoder, ok := c.decoders[pkt.CommandName] decoder, ok := c.decoders[pkt.CommandName]
if !ok { if !ok {

View File

@ -215,6 +215,9 @@ func decodeMessageSvcPacket(c *QQClient, _ uint16, payload []byte) (interface{},
} }
c.lastMessageSeq = message.Head.MsgSeq c.lastMessageSeq = message.Head.MsgSeq
c.dispatchFriendMessage(c.parsePrivateMessage(message)) c.dispatchFriendMessage(c.parsePrivateMessage(message))
case 187:
_, pkt := c.buildSystemMsgNewFriendPacket()
_ = c.send(pkt)
} }
} }
} }
@ -528,6 +531,7 @@ func decodeSystemMsgGroupPacket(c *QQClient, _ uint16, payload []byte) (interfac
return nil, nil return nil, nil
} }
st := rsp.Groupmsgs[0] st := rsp.Groupmsgs[0]
if st.Msg != nil {
// 其他SubType不关心 // 其他SubType不关心
if st.Msg.SubType == 1 { if st.Msg.SubType == 1 {
switch st.Msg.C2CInviteJoinGroupFlag { switch st.Msg.C2CInviteJoinGroupFlag {
@ -550,5 +554,26 @@ func decodeSystemMsgGroupPacket(c *QQClient, _ uint16, payload []byte) (interfac
}) })
} }
} }
}
return nil, nil
}
func decodeSystemMsgFriendPacket(c *QQClient, _ uint16, payload []byte) (interface{}, error) {
rsp := structmsg.RspSystemMsgNew{}
if err := proto.Unmarshal(payload, &rsp); err != nil {
return nil, err
}
if len(rsp.Friendmsgs) == 0 {
return nil, nil
}
st := rsp.Friendmsgs[0]
if st.Msg != nil {
c.dispatchNewFriendRequest(&NewFriendRequest{
RequestId: st.MsgSeq,
Message: st.Msg.MsgAdditional,
RequesterUin: st.ReqUin,
RequesterNick: st.Msg.ReqUinNick,
})
}
return nil, nil return nil, nil
} }

View File

@ -121,6 +121,13 @@ type (
GroupName string GroupName string
} }
NewFriendRequest struct {
RequestId int64
Message string
RequesterUin int64
RequesterNick string
}
groupMemberListResponse struct { groupMemberListResponse struct {
NextUin int64 NextUin int64
list []*GroupMemberInfo list []*GroupMemberInfo

View File

@ -18,6 +18,7 @@ type eventHandlers struct {
permissionChangedHandlers []func(*QQClient, *MemberPermissionChangedEvent) permissionChangedHandlers []func(*QQClient, *MemberPermissionChangedEvent)
groupInvitedHandlers []func(*QQClient, *GroupInvitedEvent) groupInvitedHandlers []func(*QQClient, *GroupInvitedEvent)
joinRequestHandlers []func(*QQClient, *UserJoinGroupRequest) joinRequestHandlers []func(*QQClient, *UserJoinGroupRequest)
friendRequestHandlers []func(*QQClient, *NewFriendRequest)
groupMessageReceiptHandlers sync.Map groupMessageReceiptHandlers sync.Map
} }
@ -77,6 +78,10 @@ func (c *QQClient) OnUserWantJoinGroup(f func(*QQClient, *UserJoinGroupRequest))
c.eventHandlers.joinRequestHandlers = append(c.eventHandlers.joinRequestHandlers, f) c.eventHandlers.joinRequestHandlers = append(c.eventHandlers.joinRequestHandlers, f)
} }
func (c *QQClient) OnNewFriendRequest(f func(*QQClient, *NewFriendRequest)) {
c.eventHandlers.friendRequestHandlers = append(c.eventHandlers.friendRequestHandlers, f)
}
func NewUinFilterPrivate(uin int64) func(*message.PrivateMessage) bool { func NewUinFilterPrivate(uin int64) func(*message.PrivateMessage) bool {
return func(msg *message.PrivateMessage) bool { return func(msg *message.PrivateMessage) bool {
return msg.Sender.Uin == uin return msg.Sender.Uin == uin
@ -230,6 +235,17 @@ func (c *QQClient) dispatchJoinGroupRequest(r *UserJoinGroupRequest) {
} }
} }
func (c *QQClient) dispatchNewFriendRequest(r *NewFriendRequest) {
if r == nil {
return
}
for _, f := range c.eventHandlers.friendRequestHandlers {
cover(func() {
f(c, r)
})
}
}
func cover(f func()) { func cover(f func()) {
defer func() { defer func() {
if pan := recover(); pan != nil { if pan := recover(); pan != nil {