diff --git a/README.md b/README.md index 6aab02d8..6a7a1566 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ qq-android协议的golang实现 移植于Mirai - [x] 收到其他用户进群请求 - [ ] 新好友 - [x] 新好友请求 +- [ ] 客户端离线 #### 主动操作 - [x] 发送群消息 diff --git a/client/builders.go b/client/builders.go index c7d7ccee..b3f88dcd 100644 --- a/client/builders.go +++ b/client/builders.go @@ -524,3 +524,42 @@ func (c *QQClient) buildSystemMsgNewFriendPacket() (uint16, []byte) { packet := packets.BuildUniPacket(c.Uin, seq, "ProfileService.Pb.ReqSystemMsgNew.Friend", 1, c.OutGoingPacketSessionId, EmptyBytes, c.sigInfo.d2Key, payload) return seq, packet } + +// ProfileService.Pb.ReqSystemMsgAction.Group +func (c *QQClient) buildSystemMsgGroupActionPacket(reqId, requester, group int64, isInvite, accept, block bool) (uint16, []byte) { + seq := c.nextSeq() + req := &structmsg.ReqSystemMsgAction{ + MsgType: 1, + MsgSeq: reqId, + ReqUin: requester, + SubType: 1, + SrcId: 3, + SubSrcId: func() int32 { + if isInvite { + return 10016 + } + return 31 + }(), + GroupMsgType: func() int32 { + if isInvite { + return 2 + } + return 1 + }(), + ActionInfo: &structmsg.SystemMsgActionInfo{ + Type: func() int32 { + if accept { + return 11 + } + return 12 + }(), + GroupCode: group, + Blacklist: block, + Sig: EmptyBytes, + }, + Language: 1000, + } + payload, _ := proto.Marshal(req) + packet := packets.BuildUniPacket(c.Uin, seq, "ProfileService.Pb.ReqSystemMsgAction.Group", 1, c.OutGoingPacketSessionId, EmptyBytes, c.sigInfo.d2Key, payload) + return seq, packet +} diff --git a/client/client.go b/client/client.go index 63e65e9d..1b1dc56a 100644 --- a/client/client.go +++ b/client/client.go @@ -344,6 +344,11 @@ func (c *QQClient) FindGroup(code int64) *GroupInfo { return nil } +func (c *QQClient) SolveGroupJoinRequest(req *UserJoinGroupRequest, accept bool) { + _, pkt := c.buildSystemMsgGroupActionPacket(req.RequestId, req.RequesterUin, req.GroupCode, false, accept, false) + _ = c.send(pkt) +} + func (g *GroupInfo) FindMember(uin int64) *GroupMemberInfo { for _, m := range g.Members { f := m diff --git a/client/decoders.go b/client/decoders.go index faef8022..f367a92f 100644 --- a/client/decoders.go +++ b/client/decoders.go @@ -543,6 +543,7 @@ func decodeSystemMsgGroupPacket(c *QQClient, _ uint16, payload []byte) (interfac RequesterNick: st.Msg.ReqUinNick, GroupCode: st.Msg.GroupCode, GroupName: st.Msg.GroupName, + client: c, }) case 1: // 被邀请 c.dispatchGroupInvitedEvent(&GroupInvitedEvent{ diff --git a/client/entities.go b/client/entities.go index 45ccb6f2..7c703540 100644 --- a/client/entities.go +++ b/client/entities.go @@ -119,6 +119,8 @@ type ( RequesterNick string GroupCode int64 GroupName string + + client *QQClient } NewFriendRequest struct { @@ -167,3 +169,11 @@ func (m *GroupMemberInfo) DisplayName() string { } return m.CardName } + +func (r *UserJoinGroupRequest) Accept() { + r.client.SolveGroupJoinRequest(r, true) +} + +func (r *UserJoinGroupRequest) Reject() { + r.client.SolveGroupJoinRequest(r, false) +}