SendGroupMessage 发送群聊消息,默认会对消息进行预处理
(groupUin uint32, elements []message2.IMessageElement, needPreprocess ...bool)
| 48 | |
| 49 | // SendGroupMessage 发送群聊消息,默认会对消息进行预处理 |
| 50 | func (c *QQClient) SendGroupMessage(groupUin uint32, elements []message2.IMessageElement, needPreprocess ...bool) (*message2.GroupMessage, error) { |
| 51 | if needPreprocess == nil || needPreprocess[0] { |
| 52 | elements = c.preProcessGroupMessage(groupUin, elements) |
| 53 | } |
| 54 | body := message2.PackElementsToBody(elements) |
| 55 | route := &message.RoutingHead{ |
| 56 | Grp: &message.Grp{GroupCode: proto.Some(groupUin)}, |
| 57 | } |
| 58 | mr := crypto.RandU32() |
| 59 | ret, _, err := c.SendRawMessage(route, body, mr) |
| 60 | if err != nil || ret.GroupSequence.IsNone() { |
| 61 | return nil, err |
| 62 | } |
| 63 | group := c.GetCachedGroupInfo(groupUin) |
| 64 | minfo := c.GetCachedMemberInfo(c.Uin, groupUin) |
| 65 | resp := &message2.GroupMessage{ |
| 66 | ID: ret.GroupSequence.Unwrap(), |
| 67 | InternalID: mr, |
| 68 | GroupUin: groupUin, |
| 69 | GroupName: group.GroupName, |
| 70 | Sender: &message2.Sender{ |
| 71 | Uin: c.Uin, |
| 72 | UID: c.GetUID(c.Uin), |
| 73 | Nickname: c.NickName(), |
| 74 | CardName: minfo.MemberCard, |
| 75 | IsFriend: true, |
| 76 | }, |
| 77 | Time: ret.Timestamp1, |
| 78 | Elements: elements, |
| 79 | OriginalObject: nil, |
| 80 | } |
| 81 | return resp, nil |
| 82 | } |
| 83 | |
| 84 | // SendPrivateMessage 发送私聊消息,默认会对消息进行预处理 |
| 85 | func (c *QQClient) SendPrivateMessage(uin uint32, elements []message2.IMessageElement, needPreprocess ...bool) (*message2.PrivateMessage, error) { |
no test coverage detected