diff --git a/client/decoders.go b/client/decoders.go index 9a404ee3..d005ea8d 100644 --- a/client/decoders.go +++ b/client/decoders.go @@ -776,6 +776,22 @@ func decodeOnlinePushReqPacket(c *QQClient, seq uint16, payload []byte) (interfa c.dispatchLeaveGroupEvent(&GroupLeaveEvent{Group: g}) } groupLeaveLock.Unlock() + case 290: + t := ¬ify.GeneralGrayTipInfo{} + _ = proto.Unmarshal(probuf, t) + var sender int64 + for _, templ := range t.MsgTemplParam { + if templ.Name == "uin_str1" { + sender, _ = strconv.ParseInt(templ.Value, 10, 64) + } + } + if sender == 0 { + return nil, nil + } + c.dispatchFriendNotifyEvent(&FriendPokeNotifyEvent{ + Sender: sender, + Receiver: c.Uin, + }) case 0x44: s44 := pb.Sub44{} if err := proto.Unmarshal(probuf, &s44); err != nil { diff --git a/client/entities.go b/client/entities.go index d4f10c56..deb6766f 100644 --- a/client/entities.go +++ b/client/entities.go @@ -44,7 +44,6 @@ type ( Nickname string Remark string FaceId int16 - //msgSeqList *utils.Cache } @@ -130,7 +129,7 @@ type ( Member *GroupMemberInfo } - IGroupNotifyEvent interface { + INotifyEvent interface { From() int64 Content() string } diff --git a/client/events.go b/client/events.go index 83a23c0d..441b6bc5 100644 --- a/client/events.go +++ b/client/events.go @@ -26,7 +26,8 @@ type eventHandlers struct { disconnectHandlers []func(*QQClient, *ClientDisconnectedEvent) logHandlers []func(*QQClient, *LogEvent) serverUpdatedHandlers []func(*QQClient, *ServerUpdatedEvent) bool - notifyHandlers []func(*QQClient, IGroupNotifyEvent) + groupNotifyHandlers []func(*QQClient, INotifyEvent) + friendNotifyHandlers []func(*QQClient, INotifyEvent) offlineFileHandlers []func(*QQClient, *OfflineFileEvent) groupMessageReceiptHandlers sync.Map } @@ -119,8 +120,12 @@ func (c *QQClient) OnLog(f func(*QQClient, *LogEvent)) { c.eventHandlers.logHandlers = append(c.eventHandlers.logHandlers, f) } -func (c *QQClient) OnGroupNotify(f func(*QQClient, IGroupNotifyEvent)) { - c.eventHandlers.notifyHandlers = append(c.eventHandlers.notifyHandlers, f) +func (c *QQClient) OnGroupNotify(f func(*QQClient, INotifyEvent)) { + c.eventHandlers.groupNotifyHandlers = append(c.eventHandlers.groupNotifyHandlers, f) +} + +func (c *QQClient) OnFriendNotify(f func(*QQClient, INotifyEvent)) { + c.eventHandlers.friendNotifyHandlers = append(c.eventHandlers.friendNotifyHandlers, f) } func NewUinFilterPrivate(uin int64) func(*message.PrivateMessage) bool { @@ -320,11 +325,22 @@ func (c *QQClient) dispatchNewFriendEvent(e *NewFriendEvent) { } } -func (c *QQClient) dispatchGroupNotifyEvent(e IGroupNotifyEvent) { +func (c *QQClient) dispatchGroupNotifyEvent(e INotifyEvent) { if e == nil { return } - for _, f := range c.eventHandlers.notifyHandlers { + for _, f := range c.eventHandlers.groupNotifyHandlers { + cover(func() { + f(c, e) + }) + } +} + +func (c *QQClient) dispatchFriendNotifyEvent(e INotifyEvent) { + if e == nil { + return + } + for _, f := range c.eventHandlers.friendNotifyHandlers { cover(func() { f(c, e) }) diff --git a/client/notify.go b/client/notify.go index c52c9206..915a06be 100644 --- a/client/notify.go +++ b/client/notify.go @@ -28,6 +28,12 @@ type ( Uin int64 Nick string } + + // FriendPokeNotifyEvent 好友戳一戳提示事件 + FriendPokeNotifyEvent struct { + Sender int64 + Receiver int64 + } ) // grayTipProcessor 提取出来专门用于处理群内 notify tips @@ -88,6 +94,14 @@ func (e *GroupPokeNotifyEvent) Content() string { return fmt.Sprintf("%d戳了戳%d", e.Sender, e.Receiver) } +func (e *FriendPokeNotifyEvent) From() int64 { + return e.Sender +} + +func (e *FriendPokeNotifyEvent) Content() string { + return fmt.Sprintf("%d戳了戳%d", e.Sender, e.Receiver) +} + func (e *GroupRedBagLuckyKingNotifyEvent) From() int64 { return e.GroupCode }