github.com/LagrangeDev/LagrangeGo@v0.0.0-20240512064304-ad4a85e10cb4/client/operation.go (about) 1 package client 2 3 import ( 4 "errors" 5 6 "github.com/LagrangeDev/LagrangeGo/client/packets/pb/message" 7 "github.com/LagrangeDev/LagrangeGo/internal/proto" 8 9 "github.com/LagrangeDev/LagrangeGo/client/entity" 10 "github.com/LagrangeDev/LagrangeGo/client/packets/oidb" 11 ) 12 13 // FetchFriends 获取好友列表信息 14 func (c *QQClient) FetchFriends() ([]*entity.Friend, error) { 15 pkt, err := oidb.BuildFetchFriendsReq() 16 if err != nil { 17 return nil, err 18 } 19 resp, err := c.sendOidbPacketAndWait(pkt) 20 if err != nil { 21 return nil, err 22 } 23 friends, err := oidb.ParseFetchFriendsResp(resp) 24 if err != nil { 25 return nil, err 26 } 27 return friends, nil 28 } 29 30 // FetchGroups 获取所有已加入的群的信息 31 func (c *QQClient) FetchGroups() ([]*entity.Group, error) { 32 pkt, err := oidb.BuildFetchGroupsReq() 33 if err != nil { 34 return nil, err 35 } 36 resp, err := c.sendOidbPacketAndWait(pkt) 37 if err != nil { 38 return nil, err 39 } 40 groups, err := oidb.ParseFetchGroupsResp(resp) 41 if err != nil { 42 return nil, err 43 } 44 return groups, nil 45 } 46 47 // FetchGroupMember 获取对应群的群成员信息,使用token可以获取下一页的群成员信息 48 func (c *QQClient) FetchGroupMember(groupID uint32, token string) ([]*entity.GroupMember, string, error) { 49 pkt, err := oidb.BuildFetchMembersReq(groupID, token) 50 if err != nil { 51 return nil, "", err 52 } 53 resp, err := c.sendOidbPacketAndWait(pkt) 54 if err != nil { 55 return nil, "", err 56 } 57 members, newToken, err := oidb.ParseFetchMembersResp(resp) 58 if err != nil { 59 return nil, "", err 60 } 61 return members, newToken, nil 62 } 63 64 func (c *QQClient) GroupRemark(groupID uint32, remark string) error { 65 pkt, err := oidb.BuildGroupRemarkReq(groupID, remark) 66 if err != nil { 67 return err 68 } 69 resp, err := c.sendOidbPacketAndWait(pkt) 70 if err != nil { 71 return err 72 } 73 return oidb.ParseGroupRemarkResp(resp) 74 } 75 76 func (c *QQClient) GroupRename(groupID uint32, name string) error { 77 pkt, err := oidb.BuildGroupRenameReq(groupID, name) 78 if err != nil { 79 return err 80 } 81 resp, err := c.sendOidbPacketAndWait(pkt) 82 if err != nil { 83 return err 84 } 85 return oidb.ParseGroupRenameResp(resp) 86 } 87 88 func (c *QQClient) GroupMuteGlobal(groupID uint32, isMute bool) error { 89 pkt, err := oidb.BuildGroupMuteGlobalReq(groupID, isMute) 90 if err != nil { 91 return err 92 } 93 resp, err := c.sendOidbPacketAndWait(pkt) 94 if err != nil { 95 return err 96 } 97 return oidb.ParseGroupMuteGlobalResp(resp) 98 } 99 100 func (c *QQClient) GroupMuteMember(groupID, duration, uin uint32) error { 101 uid := c.GetUid(uin, groupID) 102 if uid == "" { 103 return errors.New("uid not found") 104 } 105 pkt, err := oidb.BuildGroupMuteMemberReq(groupID, duration, uid) 106 if err != nil { 107 return err 108 } 109 resp, err := c.sendOidbPacketAndWait(pkt) 110 if err != nil { 111 return err 112 } 113 return oidb.ParseGroupMuteMemberResp(resp) 114 } 115 116 func (c *QQClient) GroupLeave(groupID uint32) error { 117 pkt, err := oidb.BuildGroupLeaveReq(groupID) 118 if err != nil { 119 return err 120 } 121 resp, err := c.sendOidbPacketAndWait(pkt) 122 if err != nil { 123 return err 124 } 125 return oidb.ParseGroupLeaveResp(resp) 126 } 127 128 func (c *QQClient) GroupSetAdmin(groupID, uin uint32, isAdmin bool) error { 129 uid := c.GetUid(uin, groupID) 130 if uid == "" { 131 return errors.New("uid not found") 132 } 133 pkt, err := oidb.BuildGroupSetAdminReq(groupID, uid, isAdmin) 134 if err != nil { 135 return err 136 } 137 resp, err := c.sendOidbPacketAndWait(pkt) 138 if err != nil { 139 return err 140 } 141 err = oidb.ParseGroupSetAdminResp(resp) 142 if err != nil { 143 return err 144 } 145 if m, _ := c.GetCachedMemberInfo(uin, groupID); m != nil { 146 m.Permission = entity.Admin 147 c.cache.RefreshGroupMember(groupID, m) 148 } 149 150 return nil 151 } 152 153 func (c *QQClient) GroupRenameMember(groupID, uin uint32, name string) error { 154 uid := c.GetUid(uin, groupID) 155 if uid == "" { 156 return errors.New("uid not found") 157 } 158 pkt, err := oidb.BuildGroupRenameMemberReq(groupID, uid, name) 159 if err != nil { 160 return err 161 } 162 resp, err := c.sendOidbPacketAndWait(pkt) 163 if err != nil { 164 return err 165 } 166 err = oidb.ParseGroupRenameMemberResp(resp) 167 if err != nil { 168 return err 169 } 170 if m, _ := c.GetCachedMemberInfo(uin, groupID); m != nil { 171 m.MemberCard = name 172 c.cache.RefreshGroupMember(groupID, m) 173 } 174 175 return nil 176 } 177 178 func (c *QQClient) GroupKickMember(groupID, uin uint32, rejectAddRequest bool) error { 179 uid := c.GetUid(uin, groupID) 180 if uid == "" { 181 return errors.New("uid not found") 182 } 183 pkt, err := oidb.BuildGroupKickMemberReq(groupID, uid, rejectAddRequest) 184 if err != nil { 185 return err 186 } 187 resp, err := c.sendOidbPacketAndWait(pkt) 188 if err != nil { 189 return err 190 } 191 return oidb.ParseGroupKickMemberResp(resp) 192 } 193 194 func (c *QQClient) GroupSetSpecialTitle(groupUin, uin uint32, title string) error { 195 uid := c.GetUid(uin, groupUin) 196 if uid == "" { 197 return errors.New("uid not found") 198 } 199 pkt, err := oidb.BuildGroupSetSpecialTitleReq(groupUin, uid, title) 200 if err != nil { 201 return err 202 } 203 resp, err := c.sendOidbPacketAndWait(pkt) 204 if err != nil { 205 return err 206 } 207 return oidb.ParseGroupSetSpecialTitleResp(resp) 208 } 209 210 func (c *QQClient) GroupPoke(groupID, uin uint32) error { 211 pkt, err := oidb.BuildGroupPokeReq(groupID, uin) 212 if err != nil { 213 return err 214 } 215 resp, err := c.sendOidbPacketAndWait(pkt) 216 if err != nil { 217 return err 218 } 219 return oidb.ParsePokeResp(resp) 220 } 221 222 func (c *QQClient) FriendPoke(uin uint32) error { 223 pkt, err := oidb.BuildFriendPokeReq(uin) 224 if err != nil { 225 return err 226 } 227 resp, err := c.sendOidbPacketAndWait(pkt) 228 if err != nil { 229 return err 230 } 231 return oidb.ParsePokeResp(resp) 232 } 233 234 func (c *QQClient) RecallGroupMessage(GrpUin, seq uint32) error { 235 packet := message.GroupRecallMsg{ 236 Type: 1, 237 GroupUin: GrpUin, 238 Field3: &message.GroupRecallMsgField3{ 239 Sequence: seq, 240 Field3: 0, 241 }, 242 Field4: &message.GroupRecallMsgField4{Field1: 0}, 243 } 244 pktData, err := proto.Marshal(&packet) 245 if err != nil { 246 return err 247 } 248 resp, err := c.sendUniPacketAndWait("trpc.msg.msg_svc.MsgService.SsoGroupRecallMsg", pktData) 249 if err != nil { 250 return err 251 } 252 if len(resp) == 0 { 253 return errors.New("empty response data") 254 } 255 return nil 256 }