From c350734b4f4cd7a8e2230c305a249ffe1de7ea71 Mon Sep 17 00:00:00 2001 From: Mrs4s Date: Mon, 8 Nov 2021 17:36:22 +0800 Subject: [PATCH] update GuildMessageReactionsUpdatedEvent fields --- client/entities.go | 2 ++ client/guild.go | 60 ----------------------------------------- client/guild_msg.go | 65 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 60 deletions(-) diff --git a/client/entities.go b/client/entities.go index 3f1ca86e..271f3d0b 100644 --- a/client/entities.go +++ b/client/entities.go @@ -223,6 +223,8 @@ type ( GuildMessageReactionsUpdatedEvent struct { OperatorId uint64 // OperatorId 操作者TinyId, 只有自身消息被贴表情才会有值 EmojiId int32 // EmojiId 被贴的表情, 只有自身消息被贴表情才会有值 + GuildId uint64 + ChannelId uint64 MessageId uint64 CurrentReactions []*message.GuildMessageEmojiReaction } diff --git a/client/guild.go b/client/guild.go index 5f4b9c41..9cdcb39b 100644 --- a/client/guild.go +++ b/client/guild.go @@ -5,7 +5,6 @@ import ( "github.com/Mrs4s/MiraiGo/binary" "github.com/Mrs4s/MiraiGo/client/pb/channel" - "github.com/Mrs4s/MiraiGo/client/pb/msg" "github.com/Mrs4s/MiraiGo/client/pb/oidb" "github.com/Mrs4s/MiraiGo/internal/packets" "github.com/Mrs4s/MiraiGo/utils" @@ -82,7 +81,6 @@ type ( func init() { decoders["trpc.group_pro.synclogic.SyncLogic.PushFirstView"] = decodeGuildPushFirstView - decoders["MsgPush.PushGroupProMsg"] = decodeGuildMessagePushPacket } func (s *GuildService) FindGuild(guildId uint64) *GuildInfo { @@ -330,64 +328,6 @@ func (c *QQClient) buildSyncChannelFirstViewPacket() (uint16, []byte) { return seq, packet } -func decodeGuildMessagePushPacket(c *QQClient, _ *incomingPacketInfo, payload []byte) (interface{}, error) { - push := new(channel.MsgOnlinePush) - if err := proto.Unmarshal(payload, push); err != nil { - return nil, errors.Wrap(err, "failed to unmarshal protobuf message") - } - for _, m := range push.Msgs { - if m.Head.ContentHead.GetType() == 3841 { - // todo: 回头 event flow 的处理移出去重构下逻辑, 先暂时这样方便改 - var common *msg.CommonElem - if m.Body != nil { - for _, e := range m.Body.RichText.Elems { - if e.CommonElem != nil { - common = e.CommonElem - break - } - } - } - if m.Head.ContentHead.GetSubType() == 2 { // todo: tips? - continue - } - if common == nil || common.GetServiceType() != 500 { - continue - } - eventBody := new(channel.EventBody) - if err := proto.Unmarshal(common.PbElem, eventBody); err != nil { - c.Error("failed to unmarshal guild channel event body: %v", err) - continue - } - if eventBody.UpdateMsg != nil { - if eventBody.UpdateMsg.GetEventType() == 1 || eventBody.UpdateMsg.GetEventType() == 2 { // todo: 撤回消息 - continue - } - if eventBody.UpdateMsg.GetEventType() == 4 { // 消息贴表情更新 (包含添加或删除) - t, err := c.GuildService.pullRoamMsgByEventFlow(m.Head.RoutingHead.GetGuildId(), m.Head.RoutingHead.GetChannelId(), eventBody.UpdateMsg.GetMsgSeq(), eventBody.UpdateMsg.GetMsgSeq(), eventBody.UpdateMsg.GetEventVersion()-1) - if err != nil || len(t) == 0 { - c.Error("process guild event flow error: pull eventMsg message error: %v", err) - continue - } - // 自己的消息被贴表情会单独推送一个tips, 这里不需要解析 - if t[0].Head.RoutingHead.GetFromTinyid() == c.GuildService.TinyId { - continue - } - // todo: 如果是别人消息被贴表情, 会在在后续继续推送一个 empty tips, 可以从那个消息获取到 OperatorId - c.dispatchGuildMessageReactionsUpdatedEvent(&GuildMessageReactionsUpdatedEvent{ - MessageId: t[0].Head.ContentHead.GetSeq(), - CurrentReactions: decodeGuildMessageEmojiReactions(t[0]), - }) - } - } - continue - } - if cm := c.parseGuildChannelMessage(m); cm != nil { - c.dispatchGuildChannelMessage(cm) - } - } - return nil, nil -} - func decodeGuildPushFirstView(c *QQClient, _ *incomingPacketInfo, payload []byte) (interface{}, error) { firstViewMsg := new(channel.FirstViewMsg) if err := proto.Unmarshal(payload, firstViewMsg); err != nil { diff --git a/client/guild_msg.go b/client/guild_msg.go index c1fdb0e0..46c09608 100644 --- a/client/guild_msg.go +++ b/client/guild_msg.go @@ -1,6 +1,7 @@ package client import ( + "github.com/pkg/errors" "strconv" "github.com/Mrs4s/MiraiGo/client/pb/channel" @@ -9,6 +10,10 @@ import ( "google.golang.org/protobuf/proto" ) +func init() { + decoders["MsgPush.PushGroupProMsg"] = decodeGuildMessagePushPacket +} + func (c *QQClient) parseGuildChannelMessage(msg *channel.ChannelMsgContent) *message.GuildChannelMessage { guild := c.GuildService.FindGuild(msg.Head.RoutingHead.GetGuildId()) if guild == nil { @@ -29,6 +34,66 @@ func (c *QQClient) parseGuildChannelMessage(msg *channel.ChannelMsgContent) *mes } } +func decodeGuildMessagePushPacket(c *QQClient, _ *incomingPacketInfo, payload []byte) (interface{}, error) { + push := new(channel.MsgOnlinePush) + if err := proto.Unmarshal(payload, push); err != nil { + return nil, errors.Wrap(err, "failed to unmarshal protobuf message") + } + for _, m := range push.Msgs { + if m.Head.ContentHead.GetType() == 3841 { + // todo: 回头 event flow 的处理移出去重构下逻辑, 先暂时这样方便改 + var common *msg.CommonElem + if m.Body != nil { + for _, e := range m.Body.RichText.Elems { + if e.CommonElem != nil { + common = e.CommonElem + break + } + } + } + if m.Head.ContentHead.GetSubType() == 2 { // todo: tips? + continue + } + if common == nil || common.GetServiceType() != 500 { + continue + } + eventBody := new(channel.EventBody) + if err := proto.Unmarshal(common.PbElem, eventBody); err != nil { + c.Error("failed to unmarshal guild channel event body: %v", err) + continue + } + if eventBody.UpdateMsg != nil { + if eventBody.UpdateMsg.GetEventType() == 1 || eventBody.UpdateMsg.GetEventType() == 2 { // todo: 撤回消息 + continue + } + if eventBody.UpdateMsg.GetEventType() == 4 { // 消息贴表情更新 (包含添加或删除) + t, err := c.GuildService.pullRoamMsgByEventFlow(m.Head.RoutingHead.GetGuildId(), m.Head.RoutingHead.GetChannelId(), eventBody.UpdateMsg.GetMsgSeq(), eventBody.UpdateMsg.GetMsgSeq(), eventBody.UpdateMsg.GetEventVersion()-1) + if err != nil || len(t) == 0 { + c.Error("process guild event flow error: pull eventMsg message error: %v", err) + continue + } + // 自己的消息被贴表情会单独推送一个tips, 这里不需要解析 + if t[0].Head.RoutingHead.GetFromTinyid() == c.GuildService.TinyId { + continue + } + // todo: 如果是别人消息被贴表情, 会在在后续继续推送一个 empty tips, 可以从那个消息获取到 OperatorId + c.dispatchGuildMessageReactionsUpdatedEvent(&GuildMessageReactionsUpdatedEvent{ + GuildId: m.Head.RoutingHead.GetGuildId(), + ChannelId: m.Head.RoutingHead.GetChannelId(), + MessageId: t[0].Head.ContentHead.GetSeq(), + CurrentReactions: decodeGuildMessageEmojiReactions(t[0]), + }) + } + } + continue + } + if cm := c.parseGuildChannelMessage(m); cm != nil { + c.dispatchGuildChannelMessage(cm) + } + } + return nil, nil +} + func decodeGuildMessageEmojiReactions(content *channel.ChannelMsgContent) (r []*message.GuildMessageEmojiReaction) { r = []*message.GuildMessageEmojiReaction{} var common *msg.CommonElem