Skip to content

Commit

Permalink
feat: MemberSpecialTitleUpdatedEvent.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrs4s committed Aug 8, 2021
1 parent 1d900b3 commit afa6db1
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 11 deletions.
16 changes: 16 additions & 0 deletions client/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions client/group_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 {
Expand Down
60 changes: 57 additions & 3 deletions client/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package client

import (
"fmt"
"github.com/Mrs4s/MiraiGo/utils"
"strconv"
"strings"

"github.com/Mrs4s/MiraiGo/client/pb/notify"
)
Expand Down Expand Up @@ -30,6 +32,13 @@ type (
Nick string
}

// MemberSpecialTitleUpdatedEvent 群成员头衔更新事件
MemberSpecialTitleUpdatedEvent struct {
GroupCode int64
Uin int64
NewTitle string
}

// FriendPokeNotifyEvent 好友戳一戳提示事件
FriendPokeNotifyEvent struct {
Sender int64
Expand All @@ -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
Expand All @@ -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,
})
Expand All @@ -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:
Expand All @@ -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
}
Expand Down
13 changes: 8 additions & 5 deletions client/online_push.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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),
})
Expand All @@ -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
Expand Down

0 comments on commit afa6db1

Please sign in to comment.