mirror of
https://github.com/Mrs4s/MiraiGo.git
synced 2025-05-04 11:07:40 +08:00
supported NewFriendRequestEvent.
This commit is contained in:
parent
6edec8d4d6
commit
2f1e831448
@ -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
|
||||||
|
@ -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
|
||||||
|
}
|
||||||
|
@ -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"
|
||||||
@ -95,19 +94,20 @@ func NewClientMd5(uin int64, passwordMd5 [16]byte) *QQClient {
|
|||||||
RandomKey: make([]byte, 16),
|
RandomKey: make([]byte, 16),
|
||||||
OutGoingPacketSessionId: []byte{0x02, 0xB0, 0x5B, 0x8B},
|
OutGoingPacketSessionId: []byte{0x02, 0xB0, 0x5B, 0x8B},
|
||||||
decoders: map[string]func(*QQClient, uint16, []byte) (interface{}, error){
|
decoders: map[string]func(*QQClient, uint16, []byte) (interface{}, error){
|
||||||
"wtlogin.login": decodeLoginResponse,
|
"wtlogin.login": decodeLoginResponse,
|
||||||
"StatSvc.register": decodeClientRegisterResponse,
|
"StatSvc.register": decodeClientRegisterResponse,
|
||||||
"MessageSvc.PushNotify": decodeSvcNotify,
|
"MessageSvc.PushNotify": decodeSvcNotify,
|
||||||
"OnlinePush.PbPushGroupMsg": decodeGroupMessagePacket,
|
"OnlinePush.PbPushGroupMsg": decodeGroupMessagePacket,
|
||||||
"OnlinePush.ReqPush": decodeOnlinePushReqPacket,
|
"OnlinePush.ReqPush": decodeOnlinePushReqPacket,
|
||||||
"OnlinePush.PbPushTransMsg": decodeOnlinePushTransPacket,
|
"OnlinePush.PbPushTransMsg": decodeOnlinePushTransPacket,
|
||||||
"ConfigPushSvc.PushReq": decodePushReqPacket,
|
"ConfigPushSvc.PushReq": decodePushReqPacket,
|
||||||
"MessageSvc.PbGetMsg": decodeMessageSvcPacket,
|
"MessageSvc.PbGetMsg": decodeMessageSvcPacket,
|
||||||
"friendlist.getFriendGroupList": decodeFriendGroupListResponse,
|
"friendlist.getFriendGroupList": decodeFriendGroupListResponse,
|
||||||
"friendlist.GetTroopListReqV2": decodeGroupListResponse,
|
"friendlist.GetTroopListReqV2": decodeGroupListResponse,
|
||||||
"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 {
|
||||||
|
@ -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,27 +531,49 @@ func decodeSystemMsgGroupPacket(c *QQClient, _ uint16, payload []byte) (interfac
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
st := rsp.Groupmsgs[0]
|
st := rsp.Groupmsgs[0]
|
||||||
// 其他SubType不关心
|
if st.Msg != nil {
|
||||||
if st.Msg.SubType == 1 {
|
// 其他SubType不关心
|
||||||
switch st.Msg.C2CInviteJoinGroupFlag {
|
if st.Msg.SubType == 1 {
|
||||||
case 0: //成员申请
|
switch st.Msg.C2CInviteJoinGroupFlag {
|
||||||
c.dispatchJoinGroupRequest(&UserJoinGroupRequest{
|
case 0: //成员申请
|
||||||
RequestId: st.MsgSeq,
|
c.dispatchJoinGroupRequest(&UserJoinGroupRequest{
|
||||||
Message: st.Msg.MsgAdditional,
|
RequestId: st.MsgSeq,
|
||||||
RequesterUin: st.ReqUin,
|
Message: st.Msg.MsgAdditional,
|
||||||
RequesterNick: st.Msg.ReqUinNick,
|
RequesterUin: st.ReqUin,
|
||||||
GroupCode: st.Msg.GroupCode,
|
RequesterNick: st.Msg.ReqUinNick,
|
||||||
GroupName: st.Msg.GroupName,
|
GroupCode: st.Msg.GroupCode,
|
||||||
})
|
GroupName: st.Msg.GroupName,
|
||||||
case 1: // 被邀请
|
})
|
||||||
c.dispatchGroupInvitedEvent(&GroupInvitedEvent{
|
case 1: // 被邀请
|
||||||
EventId: st.MsgSeq,
|
c.dispatchGroupInvitedEvent(&GroupInvitedEvent{
|
||||||
InvitorUin: st.Msg.ActionUin,
|
EventId: st.MsgSeq,
|
||||||
InvitorNick: st.Msg.ActionUinNick,
|
InvitorUin: st.Msg.ActionUin,
|
||||||
GroupCode: st.Msg.GroupCode,
|
InvitorNick: st.Msg.ActionUinNick,
|
||||||
GroupName: st.Msg.GroupName,
|
GroupCode: st.Msg.GroupCode,
|
||||||
})
|
GroupName: st.Msg.GroupName,
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil, nil
|
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
|
||||||
|
}
|
||||||
|
@ -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
|
||||||
|
@ -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 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user