From 511e8c41edd21b0d676cd6d3624d85afc6012e7c Mon Sep 17 00:00:00 2001 From: Mrs4s Date: Mon, 15 Nov 2021 01:08:54 +0800 Subject: [PATCH] feat: guild at encode --- client/guild_msg.go | 7 +++++++ message/elements.go | 1 + message/message.go | 4 +++- message/pack.go | 46 +++++++++++++++++++++++++++------------------ 4 files changed, 39 insertions(+), 19 deletions(-) diff --git a/client/guild_msg.go b/client/guild_msg.go index c954d26f..2ddab4c6 100644 --- a/client/guild_msg.go +++ b/client/guild_msg.go @@ -42,6 +42,13 @@ func init() { func (s *GuildService) SendGuildChannelMessage(guildId, channelId uint64, m *message.SendingMessage) (*message.GuildChannelMessage, error) { mr := rand.Uint32() // 客户端似乎是生成的 u32 虽然类型是u64 + at := m.FirstOrNil(func(e message.IMessageElement) bool { + _, ok := e.(*message.AtElement) + return ok + }) + if at != nil { + at.(*message.AtElement).Guild = true + } req := &channel.DF62ReqBody{Msg: &channel.ChannelMsgContent{ Head: &channel.ChannelMsgHead{ RoutingHead: &channel.ChannelRoutingHead{ diff --git a/message/elements.go b/message/elements.go index ec5135a9..85a04d1f 100644 --- a/message/elements.go +++ b/message/elements.go @@ -41,6 +41,7 @@ type FaceElement struct { type AtElement struct { Target int64 Display string + Guild bool } type GroupFileElement struct { diff --git a/message/message.go b/message/message.go index 223728a5..594fde7e 100644 --- a/message/message.go +++ b/message/message.go @@ -385,7 +385,9 @@ func ParseMessageElems(elems []*msg.Elem) []IMessageElement { resv := new(msg.TextResvAttr) _ = proto.Unmarshal(elem.Text.PbReserve, resv) if resv.GetAtType() == 2 { - res = append(res, NewAt(int64(resv.GetAtMemberTinyid()), elem.Text.GetStr())) + at := NewAt(int64(resv.GetAtMemberTinyid()), elem.Text.GetStr()) + at.Guild = true + res = append(res, at) break } fallthrough diff --git a/message/pack.go b/message/pack.go index f2ea0b0e..fd336dba 100644 --- a/message/pack.go +++ b/message/pack.go @@ -56,24 +56,34 @@ func (e *FaceElement) Pack() (r []*msg.Elem) { func (e *AtElement) Pack() (r []*msg.Elem) { r = []*msg.Elem{} - r = append(r, &msg.Elem{ - Text: &msg.Text{ - Str: &e.Display, - Attr6Buf: binary.NewWriterF(func(w *binary.Writer) { - w.WriteUInt16(1) - w.WriteUInt16(0) - w.WriteUInt16(uint16(len([]rune(e.Display)))) - w.WriteByte(func() byte { - if e.Target == 0 { - return 1 - } - return 0 - }()) - w.WriteUInt32(uint32(e.Target)) - w.WriteUInt16(0) - }), - }, - }) + if e.Guild { + pb, _ := proto.Marshal(&msg.TextResvAttr{AtType: proto.Uint32(2), AtMemberTinyid: proto.Uint64(uint64(e.Target))}) + r = append(r, &msg.Elem{ + Text: &msg.Text{ + Str: &e.Display, + PbReserve: pb, + }, + }) + } else { + r = append(r, &msg.Elem{ + Text: &msg.Text{ + Str: &e.Display, + Attr6Buf: binary.NewWriterF(func(w *binary.Writer) { + w.WriteUInt16(1) + w.WriteUInt16(0) + w.WriteUInt16(uint16(len([]rune(e.Display)))) + w.WriteByte(func() byte { + if e.Target == 0 { + return 1 + } + return 0 + }()) + w.WriteUInt32(uint32(e.Target)) + w.WriteUInt16(0) + }), + }, + }) + } r = append(r, &msg.Elem{Text: &msg.Text{Str: proto.String(" ")}}) return }