Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

code... #137

Merged
merged 4 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions client/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ func (c *QQClient) SendGroupMessage(groupUin uint32, elements []message2.IMessag
GroupUin: groupUin,
GroupName: group.GroupName,
Sender: &message2.Sender{
Uin: c.Uin,
UID: c.GetUID(c.Uin),
Nickname: c.NickName(),
CardName: minfo.MemberCard,
AnonymousInfo: nil,
IsFriend: true,
Uin: c.Uin,
UID: c.GetUID(c.Uin),
Nickname: c.NickName(),
CardName: minfo.MemberCard,
//AnonymousInfo: nil,
IsFriend: true,
},
Time: ret.Timestamp1,
Elements: elements,
Expand Down Expand Up @@ -106,11 +106,11 @@ func (c *QQClient) SendPrivateMessage(uin uint32, elements []message2.IMessageEl
Target: uin,
Time: ret.Timestamp1,
Sender: &message2.Sender{
Uin: c.Uin,
UID: c.GetUID(c.Uin),
Nickname: c.NickName(),
AnonymousInfo: nil,
IsFriend: true,
Uin: c.Uin,
UID: c.GetUID(c.Uin),
Nickname: c.NickName(),
//AnonymousInfo: nil,
IsFriend: true,
},
Elements: elements,
}
Expand All @@ -137,11 +137,11 @@ func (c *QQClient) SendTempMessage(groupUin uint32, uin uint32, elements []messa
GroupName: group.GroupName,
Self: c.Uin,
Sender: &message2.Sender{
Uin: c.Uin,
UID: c.GetUID(c.Uin),
Nickname: c.NickName(),
AnonymousInfo: nil,
IsFriend: true,
Uin: c.Uin,
UID: c.GetUID(c.Uin),
Nickname: c.NickName(),
//AnonymousInfo: nil,
IsFriend: true,
},
Elements: elements,
}
Expand All @@ -159,7 +159,7 @@ func (c *QQClient) BuildFakeMessage(msgElems []*message2.ForwardNode) []*message
FromUin: elem.SenderID,
},
ContentHead: &message.ContentHead{
Type: uint32(utils.Ternary(elem.GroupID != 0, 82, 9)),
Type: utils.Ternary[uint32](elem.GroupID != 0, 82, 9),
MsgId: proto.Uint32(crypto.RandU32()),
Sequence: proto.Uint32(crypto.RandU32()),
TimeStamp: proto.Uint32(uint32(utils.TimeStamp())),
Expand All @@ -169,7 +169,7 @@ func (c *QQClient) BuildFakeMessage(msgElems []*message2.ForwardNode) []*message
Foward: &message.ForwardHead{
Field1: proto.Uint32(0),
Field2: proto.Uint32(0),
Field3: utils.Ternary(elem.GroupID != 0, proto.Uint32(0), proto.Uint32(2)),
Field3: proto.Uint32(utils.Ternary[uint32](elem.GroupID != 0, 0, 2)),
UnknownBase64: proto.String(avatar),
Avatar: proto.String(avatar),
},
Expand Down
2 changes: 1 addition & 1 deletion client/packets/message/multi_msg_upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func BuildMultiMsgUploadReq(selfUID string, groupUin uint32, msg []*message.Push
Info: &message.SendLongMsgInfo{
Type: utils.Ternary[uint32](groupUin == 0, 1, 3),
Uid: &message.LongMsgUid{
Uid: utils.Ternary(groupUin == 0, proto.String(selfUID), proto.String(strconv.Itoa(int(groupUin)))),
Uid: proto.String(utils.Ternary(groupUin == 0, selfUID, strconv.Itoa(int(groupUin)))),
},
GroupUin: proto.Uint32(groupUin),
Payload: payload,
Expand Down
3 changes: 1 addition & 2 deletions client/packets/pb/action/action.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 20 additions & 30 deletions client/packets/pb/message/element.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion client/packets/pb/message/element.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ message Elem {
optional GroupFile GroupFile = 13;
optional ExtraInfo ExtraInfo = 16;
optional VideoFile VideoFile = 19;
optional AnonymousGroupMessage AnonymousGroupMessage = 21;
//optional AnonymousGroupMessage AnonymousGroupMessage = 21;
optional QQWalletMsg QQWalletMsg = 24;
optional CustomElem CustomElem = 31;
optional GeneralFlags GeneralFlags = 37;
Expand All @@ -24,6 +24,7 @@ message Elem {
optional CommonElem CommonElem = 53;
}

/*
message AnonymousGroupMessage {
int32 Flags = 1;
bytes AnonId = 2;
Expand All @@ -33,6 +34,7 @@ message AnonymousGroupMessage {
int32 BubbleId = 6;
bytes RankColor = 7;
}
*/

message CommonElem {
int32 ServiceType = 1;
Expand Down
3 changes: 1 addition & 2 deletions client/packets/pb/message/message.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions client/packets/pb/service/highway/highway.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions message/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (e *TextElement) BuildElement() []*message.Elem {

func (e *AtElement) BuildElement() []*message.Elem {
reserveData, _ := proto.Marshal(&message.MentionExtra{
Type: proto.Some(int32(utils.Ternary(e.TargetUin == 0, 1, 2))), // atAll
Type: proto.Some(utils.Ternary[int32](e.TargetUin == 0, 1, 2)), // atAll
Uin: proto.Some(uint32(0)),
Field5: proto.Some(int32(0)),
Uid: proto.Some(e.TargetUID),
Expand Down Expand Up @@ -75,7 +75,7 @@ func (e *ImageElement) BuildElement() []*message.Elem {
CommonElem: &message.CommonElem{
ServiceType: 48,
PbElem: common,
BusinessType: utils.Ternary(e.IsGroup, uint32(20), uint32(10)),
BusinessType: utils.Ternary[uint32](e.IsGroup, 20, 10),
},
}}
if e.CompatFace != nil {
Expand Down
74 changes: 36 additions & 38 deletions message/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,29 +77,31 @@ type (
}

Sender struct {
Uin uint32
UID string
Nickname string
CardName string
AnonymousInfo *AnonymousInfo
IsFriend bool
Uin uint32
UID string
Nickname string
CardName string
//AnonymousInfo *AnonymousInfo
IsFriend bool
}

AnonymousInfo struct {
AnonymousID string
AnonymousNick string
}

/*
AnonymousInfo struct {
AnonymousID string
AnonymousNick string
}
*/
IMessageElement interface {
Type() ElementType
}

ElementType int
)

/*
func (s *Sender) IsAnonymous() bool {
return s.Uin == 80000000
}
*/

func ParsePrivateMessage(msg *message.PushMsgBody) *PrivateMessage {
prvMsg := &PrivateMessage{
Expand Down Expand Up @@ -161,14 +163,13 @@ func ParseMessageElements(msg []*message.Elem) []IMessageElement {
continue
}
if elem.SrcMsg != nil && len(elem.SrcMsg.OrigSeqs) != 0 {
r := &ReplyElement{
res = append(res, &ReplyElement{
ReplySeq: elem.SrcMsg.OrigSeqs[0],
Time: uint32(elem.SrcMsg.Time.Unwrap()),
SenderUin: uint32(elem.SrcMsg.SenderUin),
GroupUin: uint32(elem.SrcMsg.ToUin.Unwrap()),
Elements: ParseMessageElements(elem.SrcMsg.Elems),
}
res = append(res, r)
})
}

if elem.Text != nil {
Expand All @@ -191,24 +192,25 @@ func ParseMessageElements(msg []*message.Elem) []IMessageElement {
}

if elem.Face != nil {
switch {
case len(elem.Face.Old) > 0:
if len(elem.Face.Old) > 0 {
faceID := elem.Face.Index
if faceID.IsSome() {
res = append(res, &FaceElement{FaceID: uint32(faceID.Unwrap())})
}
case elem.CommonElem != nil && elem.CommonElem.ServiceType == 37 && elem.CommonElem.PbElem != nil:
qFace := message.QFaceExtra{}
if err := proto.Unmarshal(elem.CommonElem.PbElem, &qFace); err == nil {
if qFace.Qsid.IsSome() {
res = append(res, &FaceElement{FaceID: uint32(qFace.Qsid.Unwrap()), isLargeFace: true})
} else if elem.CommonElem != nil && elem.CommonElem.PbElem != nil {
if elem.CommonElem.ServiceType == 37 {
qFace := message.QFaceExtra{}
if err := proto.Unmarshal(elem.CommonElem.PbElem, &qFace); err == nil {
if qFace.Qsid.IsSome() {
res = append(res, &FaceElement{FaceID: uint32(qFace.Qsid.Unwrap()), isLargeFace: true})
}
}
} else if elem.CommonElem.ServiceType == 33 {
qFace := message.QSmallFaceExtra{}
err := proto.Unmarshal(elem.CommonElem.PbElem, &qFace)
if err == nil {
res = append(res, &FaceElement{FaceID: qFace.FaceId, isLargeFace: false})
}
}
case elem.CommonElem != nil && elem.CommonElem.ServiceType == 33 && elem.CommonElem.PbElem != nil:
qFace := message.QSmallFaceExtra{}
err := proto.Unmarshal(elem.CommonElem.PbElem, &qFace)
if err == nil {
res = append(res, &FaceElement{FaceID: qFace.FaceId, isLargeFace: false})
}
}
}
Expand Down Expand Up @@ -328,7 +330,7 @@ func ParseMessageElements(msg []*message.Elem) []IMessageElement {
})
case 11, 21: // video
var thumb = new(VideoThumb)
if !(len(extra.MsgInfoBody) < 2) {
if len(extra.MsgInfoBody) > 1 {
info := extra.MsgInfoBody[1].Index
thumb.Size = info.Info.FileSize
thumb.Width = info.Info.Width
Expand Down Expand Up @@ -408,7 +410,7 @@ func ParseMessageElements(msg []*message.Elem) []IMessageElement {
} else {
res = append(res, &XMLElement{
ServiceID: 35,
Content: utils.B2S(binary.ZlibUncompress(elem.RichMsg.Template1[1:])),
Content: utils.B2S(xmlData),
})
}
}
Expand Down Expand Up @@ -654,11 +656,9 @@ func PackElementsToBody(msgElems []IMessageElement) (msgBody *message.MessageBod
RichText: &message.RichText{Elems: PackElements(msgElems)},
}
for _, elem := range msgElems {
bd, ok := elem.(MsgContentBuilder)
if !ok {
continue
if bd, ok := elem.(MsgContentBuilder); ok {
msgBody.MsgContent = bd.BuildContent()
}
msgBody.MsgContent = bd.BuildContent()
}
return
}
Expand All @@ -669,11 +669,9 @@ func PackElements(msgElems []IMessageElement) []*message.Elem {
}
elems := make([]*message.Elem, 0, len(msgElems))
for _, elem := range msgElems {
bd, ok := elem.(ElementBuilder)
if !ok {
continue
if bd, ok := elem.(ElementBuilder); ok {
elems = append(elems, bd.BuildElement()...)
}
elems = append(elems, bd.BuildElement()...)
}
return elems
}
Loading