From 714961d68f3dcd6956771d7b8bdea70d96ad65fd Mon Sep 17 00:00:00 2001 From: wdvxdr Date: Sun, 20 Mar 2022 13:48:02 +0800 Subject: [PATCH] client: use `%x` placeholder --- client/builders.go | 4 ++-- client/decoders.go | 3 +-- client/group_file.go | 2 +- client/guild_msg.go | 6 +++--- client/image.go | 8 ++++---- client/ptt.go | 5 +++-- message/pack.go | 3 +-- 7 files changed, 15 insertions(+), 16 deletions(-) diff --git a/client/builders.go b/client/builders.go index 0154ae6a..ca9e85c4 100644 --- a/client/builders.go +++ b/client/builders.go @@ -2,7 +2,7 @@ package client import ( "crypto/md5" - "encoding/hex" + "fmt" "math/rand" "time" @@ -903,7 +903,7 @@ func (c *QQClient) buildOffPicUpPacket(target int64, md5 []byte, size int32) (ui DstUin: proto.Uint64(uint64(target)), FileMd5: md5, FileSize: proto.Uint64(uint64(size)), - FileName: []byte(hex.EncodeToString(md5) + ".jpg"), + FileName: []byte(fmt.Sprintf("%x.jpg", md5)), SrcTerm: proto.Uint32(5), PlatformType: proto.Uint32(9), BuType: proto.Uint32(1), diff --git a/client/decoders.go b/client/decoders.go index fa20b0ff..f8452d4b 100644 --- a/client/decoders.go +++ b/client/decoders.go @@ -2,7 +2,6 @@ package client import ( "crypto/md5" - "encoding/hex" "net" "strconv" "strings" @@ -173,7 +172,7 @@ func decodeLoginResponse(c *QQClient, _ *network.IncomingPacketInfo, payload []b } c.debug("unknown login response: %v", t) for k, v := range m { - c.debug("Type: %v Value: %v", strconv.FormatInt(int64(k), 16), hex.EncodeToString(v)) + c.debug("Type: %d Value: %x", k, v) } return nil, errors.Errorf("unknown login response: %v", t) // ? } diff --git a/client/group_file.go b/client/group_file.go index 1e050cd7..bb3c428a 100644 --- a/client/group_file.go +++ b/client/group_file.go @@ -104,7 +104,7 @@ func (c *QQClient) GetGroupFileUrl(groupCode int64, fileId string, busId int32) return "" } url := i.(string) - url += "?fname=" + hex.EncodeToString([]byte(fileId)) + url += fmt.Sprintf("?fname=%x", fileId) return url } diff --git a/client/guild_msg.go b/client/guild_msg.go index 6f514101..378a8125 100644 --- a/client/guild_msg.go +++ b/client/guild_msg.go @@ -1,7 +1,7 @@ package client import ( - "encoding/hex" + "fmt" "io" "math/rand" "strconv" @@ -88,7 +88,7 @@ func (s *GuildService) QueryImage(guildId, channelId uint64, hash []byte, size u if body.IsExists { return &message.GuildImageElement{ FileId: body.FileId, - FilePath: hex.EncodeToString(hash) + ".jpg", + FilePath: fmt.Sprintf("%x.jpg", hash), Size: int32(size), DownloadIndex: body.DownloadIndex, Width: body.Width, @@ -177,7 +177,7 @@ func (c *QQClient) buildGuildImageStorePacket(guildId, channelId uint64, hash [] FileId: proto.Uint64(0), FileMd5: hash, FileSize: &size, - FileName: []byte(hex.EncodeToString(hash) + ".jpg"), + FileName: []byte(fmt.Sprintf("%x.jpg", hash)), SrcTerm: proto.Uint32(5), PlatformType: proto.Uint32(9), BuType: proto.Uint32(211), diff --git a/client/image.go b/client/image.go index a4e2a3eb..84b8e810 100644 --- a/client/image.go +++ b/client/image.go @@ -1,7 +1,7 @@ package client import ( - "encoding/hex" + "fmt" "io" "math/rand" "strings" @@ -154,7 +154,7 @@ ok: } return &message.GuildImageElement{ FileId: rsp.FileId, - FilePath: hex.EncodeToString(fh) + ".jpg", + FilePath: fmt.Sprintf("%x.jpg", fh), Size: int32(length), DownloadIndex: rsp.DownloadIndex, Width: width, @@ -214,7 +214,7 @@ func (c *QQClient) ImageOcr(img any) (*OcrResponse, error) { } _ = b.Close() } - rsp, err := c.sendAndWait(c.buildImageOcrRequestPacket(url, strings.ToUpper(hex.EncodeToString(e.Md5)), e.Size, e.Width, e.Height)) + rsp, err := c.sendAndWait(c.buildImageOcrRequestPacket(url, fmt.Sprintf("%X", e.Md5), e.Size, e.Width, e.Height)) if err != nil { return nil, err } @@ -399,7 +399,7 @@ func decodeGroupImageDownloadResponse(_ *QQClient, _ *network.IncomingPacketInfo if len(pkt.GetimgUrlRsp[0].FailMsg) != 0 { return nil, errors.New(utils.B2S(pkt.GetimgUrlRsp[0].FailMsg)) } - return "https://" + utils.B2S(pkt.GetimgUrlRsp[0].DownDomain) + utils.B2S(pkt.GetimgUrlRsp[0].BigDownPara), nil + return fmt.Sprintf("https://%s%s", pkt.GetimgUrlRsp[0].DownDomain, pkt.GetimgUrlRsp[0].BigDownPara), nil } // OidbSvc.0xe07_0 diff --git a/client/ptt.go b/client/ptt.go index 7ed1ea93..024d3097 100644 --- a/client/ptt.go +++ b/client/ptt.go @@ -3,6 +3,7 @@ package client import ( "crypto/md5" "encoding/hex" + "fmt" "io" "github.com/pkg/errors" @@ -90,7 +91,7 @@ func (c *QQClient) UploadVoice(target message.Source, voice io.ReadSeeker) (*mes FileType: proto.Int32(4), SrcUin: &c.Uin, FileMd5: fh, - FileName: proto.String(hex.EncodeToString(fh) + ".amr"), + FileName: proto.String(fmt.Sprintf("%x.amr", fh)), FileSize: proto.Int32(int32(length)), BoolValid: proto.Bool(true), } @@ -259,7 +260,7 @@ func (c *QQClient) buildPttShortVideoProto(target message.Source, videoHash, thu ChatType: chatType, ClientType: 2, Info: &pttcenter.ShortVideoFileInfo{ - FileName: hex.EncodeToString(videoHash) + ".mp4", + FileName: fmt.Sprintf("%x.mp4", videoHash), FileMd5: videoHash, ThumbFileMd5: thumbHash, FileSize: videoSize, diff --git a/message/pack.go b/message/pack.go index 37af9a7c..bb56ad70 100644 --- a/message/pack.go +++ b/message/pack.go @@ -1,7 +1,6 @@ package message import ( - "encoding/hex" "fmt" "github.com/Mrs4s/MiraiGo/binary" @@ -126,7 +125,7 @@ func (e *ShortVideoElement) Pack() (r []*msg.Elem) { video := &msg.VideoFile{ FileUuid: e.Uuid, FileMd5: e.Md5, - FileName: []byte(hex.EncodeToString(e.Md5) + ".mp4"), + FileName: []byte(fmt.Sprintf("%x.mp4", e.Md5)), FileFormat: proto.Int32(3), FileTime: proto.Int32(10), FileSize: proto.Int32(e.Size),