diff --git a/client/events.go b/client/events.go index 52c39a14..143c8fb7 100644 --- a/client/events.go +++ b/client/events.go @@ -33,6 +33,7 @@ type eventHandlers struct { serverUpdatedHandlers []func(*QQClient, *ServerUpdatedEvent) bool groupNotifyHandlers []func(*QQClient, INotifyEvent) friendNotifyHandlers []func(*QQClient, INotifyEvent) + memberTitleUpdatedHandlers []func(*QQClient, *MemberSpecialTitleUpdatedEvent) offlineFileHandlers []func(*QQClient, *OfflineFileEvent) otherClientStatusChangedHandlers []func(*QQClient, *OtherClientStatusChangedEvent) groupDigestHandlers []func(*QQClient, *GroupDigestEvent) @@ -151,6 +152,10 @@ func (c *QQClient) OnFriendNotify(f func(*QQClient, INotifyEvent)) { c.eventHandlers.friendNotifyHandlers = append(c.eventHandlers.friendNotifyHandlers, f) } +func (c *QQClient) OnMemberSpecialTitleUpdated(f func(*QQClient, *MemberSpecialTitleUpdatedEvent)) { + c.eventHandlers.memberTitleUpdatedHandlers = append(c.eventHandlers.memberTitleUpdatedHandlers, f) +} + // OnGroupDigest 群精华消息事件注册 func (c *QQClient) OnGroupDigest(f func(*QQClient, *GroupDigestEvent)) { c.eventHandlers.groupDigestHandlers = append(c.eventHandlers.groupDigestHandlers, f) @@ -408,6 +413,17 @@ func (c *QQClient) dispatchFriendNotifyEvent(e INotifyEvent) { } } +func (c *QQClient) dispatchMemberSpecialTitleUpdateEvent(e *MemberSpecialTitleUpdatedEvent) { + if e == nil { + return + } + for _, f := range c.eventHandlers.memberTitleUpdatedHandlers { + cover(func() { + f(c, e) + }) + } +} + func (c *QQClient) dispatchDisconnectEvent(e *ClientDisconnectedEvent) { if e == nil { return diff --git a/client/group_msg.go b/client/group_msg.go index d57a47c7..4618b3b7 100644 --- a/client/group_msg.go +++ b/client/group_msg.go @@ -105,7 +105,7 @@ func (c *QQClient) sendGroupMessage(groupCode int64, forward bool, m *message.Se }) defer c.onGroupMessageReceipt(eid) imgCount := 0 - frag := true + serviceFlag := true for _, e := range m.Elements { switch e.Type() { case message.Image: @@ -114,10 +114,10 @@ func (c *QQClient) sendGroupMessage(groupCode int64, forward bool, m *message.Se forward = true fallthrough case message.Reply, message.Voice, message.Service: - frag = false + serviceFlag = false } } - if !forward && frag && (imgCount > 1 || message.EstimateLength(m.Elements) > 100) { + if !forward && serviceFlag && (imgCount > 1 || message.EstimateLength(m.Elements) > 100) { div := int32(rand.Uint32()) fragmented := m.ToFragmented() for i, elems := range fragmented { diff --git a/client/notify.go b/client/notify.go index e41940cd..275fd042 100644 --- a/client/notify.go +++ b/client/notify.go @@ -2,7 +2,9 @@ package client import ( "fmt" + "github.com/Mrs4s/MiraiGo/utils" "strconv" + "strings" "github.com/Mrs4s/MiraiGo/client/pb/notify" ) @@ -30,6 +32,13 @@ type ( Nick string } + // MemberSpecialTitleUpdatedEvent 群成员头衔更新事件 + MemberSpecialTitleUpdatedEvent struct { + GroupCode int64 + Uin int64 + NewTitle string + } + // FriendPokeNotifyEvent 好友戳一戳提示事件 FriendPokeNotifyEvent struct { Sender int64 @@ -38,7 +47,7 @@ type ( ) // grayTipProcessor 提取出来专门用于处理群内 notify tips -func (c *QQClient) grayTipProcessor(groupID int64, tipInfo *notify.GeneralGrayTipInfo) { +func (c *QQClient) grayTipProcessor(groupCode int64, tipInfo *notify.GeneralGrayTipInfo) { if tipInfo.BusiType == 12 && tipInfo.BusiId == 1061 { sender := int64(0) receiver := c.Uin @@ -52,7 +61,7 @@ func (c *QQClient) grayTipProcessor(groupID int64, tipInfo *notify.GeneralGrayTi } if sender != 0 { c.dispatchGroupNotifyEvent(&GroupPokeNotifyEvent{ - GroupCode: groupID, + GroupCode: groupCode, Sender: sender, Receiver: receiver, }) @@ -71,7 +80,7 @@ func (c *QQClient) grayTipProcessor(groupID int64, tipInfo *notify.GeneralGrayTi } } c.dispatchGroupNotifyEvent(&MemberHonorChangedNotifyEvent{ - GroupCode: groupID, + GroupCode: groupCode, Honor: func() HonorType { switch tipInfo.TemplId { case 1052: @@ -90,6 +99,51 @@ func (c *QQClient) grayTipProcessor(groupID int64, tipInfo *notify.GeneralGrayTi } } +// msgGrayTipProcessor 用于处理群内 aio notify tips +func (c *QQClient) msgGrayTipProcessor(groupCode int64, tipInfo *notify.AIOGrayTipsInfo) { + if len(tipInfo.Content) == 0 { + return + } + type tipCommand struct { + Command int `json:"cmd"` + Data string `json:"data"` + Text string `json:"text"` + } + content := utils.B2S(tipInfo.Content) + var tipCmds []*tipCommand + start := -1 + for i := 0; i < len(content); i++ { + if content[i] == '<' && len(content) > i+1 && content[i+1] == '{' { + start = i + 1 + } + if content[i] == '>' && content[i-1] == '}' && start != -1 { + tip := &tipCommand{} + if err := json.Unmarshal(utils.S2B(content[start:i]), tip); err == nil { + tipCmds = append(tipCmds, tip) + } + start = -1 + } + } + // 好像只能这么判断 + switch { + case strings.Contains(content, "头衔"): + event := &MemberSpecialTitleUpdatedEvent{GroupCode: groupCode} + for _, cmd := range tipCmds { + if cmd.Command == 5 { + event.Uin, _ = strconv.ParseInt(cmd.Data, 10, 64) + } + if cmd.Command == 1 { + event.NewTitle = cmd.Text + } + } + if event.Uin == 0 { + c.Error("process special title updated tips error: missing cmd") + return + } + c.dispatchMemberSpecialTitleUpdateEvent(event) + } +} + func (e *GroupPokeNotifyEvent) From() int64 { return e.GroupCode } diff --git a/client/online_push.go b/client/online_push.go index 5eb68040..526a1c3a 100644 --- a/client/online_push.go +++ b/client/online_push.go @@ -42,7 +42,7 @@ func decodeOnlinePushReqPacket(c *QQClient, info *incomingPacketInfo, payload [] // 0x2dc if m.MsgType == 732 { r := binary.NewReader(m.VMsg) - groupID := int64(uint32(r.ReadInt32())) + groupCode := int64(uint32(r.ReadInt32())) iType := r.ReadByte() r.ReadByte() switch iType { @@ -55,7 +55,7 @@ func decodeOnlinePushReqPacket(c *QQClient, info *incomingPacketInfo, payload [] target := int64(uint32(r.ReadInt32())) t := r.ReadInt32() c.dispatchGroupMuteEvent(&GroupMuteEvent{ - GroupCode: groupID, + GroupCode: groupCode, OperatorUin: operator, TargetUin: target, Time: t, @@ -70,7 +70,7 @@ func decodeOnlinePushReqPacket(c *QQClient, info *incomingPacketInfo, payload [] continue } c.dispatchGroupMessageRecalledEvent(&GroupMessageRecalledEvent{ - GroupCode: groupID, + GroupCode: groupCode, OperatorUin: b.OptMsgRecall.Uin, AuthorUin: rm.AuthorUin, MessageId: rm.Seq, @@ -79,12 +79,12 @@ func decodeOnlinePushReqPacket(c *QQClient, info *incomingPacketInfo, payload [] } } if b.OptGeneralGrayTip != nil { - c.grayTipProcessor(groupID, b.OptGeneralGrayTip) + c.grayTipProcessor(groupCode, b.OptGeneralGrayTip) } if b.OptMsgRedTips != nil { if b.OptMsgRedTips.LuckyFlag == 1 { // 运气王提示 c.dispatchGroupNotifyEvent(&GroupRedBagLuckyKingNotifyEvent{ - GroupCode: groupID, + GroupCode: groupCode, Sender: int64(b.OptMsgRedTips.SenderUin), LuckyKing: int64(b.OptMsgRedTips.LuckyUin), }) @@ -104,6 +104,9 @@ func decodeOnlinePushReqPacket(c *QQClient, info *incomingPacketInfo, payload [] OperatorNick: string(digest.OperNick), }) } + if b.OptMsgGrayTips != nil { + c.msgGrayTipProcessor(groupCode, b.OptMsgGrayTips) + } } } // 0x210