1
0
mirror of https://github.com/Mrs4s/MiraiGo.git synced 2025-05-04 11:07:40 +08:00

feat: guild at encode

This commit is contained in:
Mrs4s 2021-11-15 01:08:54 +08:00
parent 55ba62e4b8
commit 511e8c41ed
No known key found for this signature in database
GPG Key ID: 3186E98FA19CE3A7
4 changed files with 39 additions and 19 deletions

View File

@ -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{

View File

@ -41,6 +41,7 @@ type FaceElement struct {
type AtElement struct {
Target int64
Display string
Guild bool
}
type GroupFileElement struct {

View File

@ -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

View File

@ -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
}