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 all 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
33 changes: 15 additions & 18 deletions client/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,11 @@ 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,
IsFriend: true,
},
Time: ret.Timestamp1,
Elements: elements,
Expand Down Expand Up @@ -106,11 +105,10 @@ 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(),
IsFriend: true,
},
Elements: elements,
}
Expand All @@ -137,11 +135,10 @@ 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(),
IsFriend: true,
},
Elements: elements,
}
Expand All @@ -159,7 +156,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 +166,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
13 changes: 13 additions & 0 deletions client/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,19 @@ func (c *QQClient) GetGroupRecordURL(groupUin uint32, node *oidb.IndexNode) (str
return oidb2.ParseGroupRecordDownloadResp(resp)
}

func (c *QQClient) GenFileNode(name, md5, sha1, uuid string, size uint32, isnt bool) *oidb.IndexNode {
return &oidb.IndexNode{
Info: &oidb.FileInfo{
FileName: name,
FileSize: size,
FileSha1: sha1,
FileHash: md5,
},
FileUuid: uuid,
StoreId: utils.Ternary[uint32](isnt, 1, 0), // 0旧服务器 1为nt服务器
}
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以把这段加进来

// GetPrivateVideoURL 获取私聊视频下载链接
func (c *QQClient) GetPrivateVideoURL(node *oidb.IndexNode) (string, error) {
pkt, err := oidb2.BuildPrivateVideoDownloadReq(c.Sig().UID, node)
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
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
78 changes: 31 additions & 47 deletions message/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,11 @@ type (
}

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

AnonymousInfo struct {
AnonymousID string
AnonymousNick string
Uin uint32
UID string
Nickname string
CardName string
IsFriend bool
}

IMessageElement interface {
Expand All @@ -97,10 +91,6 @@ type (
ElementType int
)

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

func ParsePrivateMessage(msg *message.PushMsgBody) *PrivateMessage {
prvMsg := &PrivateMessage{
ID: msg.ContentHead.Sequence.Unwrap(),
Expand Down Expand Up @@ -161,26 +151,24 @@ 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 {
switch {
case len(elem.Text.Attr6Buf) > 0:
if len(elem.Text.Attr6Buf) > 0 {
att6 := binary.NewReader(elem.Text.Attr6Buf)
att6.SkipBytes(7)
target := att6.ReadU32()
at := NewAt(target, elem.Text.Str.Unwrap())
at.SubType = AtTypeGroupMember
res = append(res, at)
default:
} else {
res = append(res, NewText(func() string {
if strings.Contains(elem.Text.Str.Unwrap(), "\r") && !strings.Contains(elem.Text.Str.Unwrap(), "\r\n") {
return strings.ReplaceAll(elem.Text.Str.Unwrap(), "\r", "\r\n")
Expand All @@ -191,24 +179,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 +317,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 +397,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 @@ -450,8 +439,7 @@ func ParseMessageBody(body *message.MessageBody, isGroup bool) []IMessageElement
if body != nil {
if body.RichText != nil && body.RichText.Ptt != nil {
ptt := body.RichText.Ptt
switch {
case isGroup && ptt.FileId != 0:
if isGroup && ptt.FileId != 0 {
res = append(res, &VoiceElement{
Name: ptt.FileName,
UUID: ptt.FileUuid,
Expand All @@ -460,7 +448,7 @@ func ParseMessageBody(body *message.MessageBody, isGroup bool) []IMessageElement
FileUuid: ptt.GroupFileKey,
},
})
case !isGroup:
} else if !isGroup {
res = append(res, &VoiceElement{
Name: ptt.FileName,
UUID: ptt.FileUuid,
Expand Down Expand Up @@ -654,11 +642,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 +655,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