From fcc99efe7ef4f5e892eb6cf4552cee2626b5f023 Mon Sep 17 00:00:00 2001 From: lixiangwuxian Date: Sat, 8 Mar 2025 18:14:57 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E6=9C=80=E8=BF=91?= =?UTF-8?q?=E6=88=90=E7=BB=A9=E8=8E=B7=E5=8F=96=EF=BC=8C=E5=B9=B6=E5=8F=91?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E6=AD=8C=E6=9B=B2=E5=B0=81=E9=9D=A2=E5=B9=B6?= =?UTF-8?q?=E5=9C=A8=E6=B6=88=E6=81=AF=E4=B8=AD=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- handler/scoresaber/score.go | 39 +++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/handler/scoresaber/score.go b/handler/scoresaber/score.go index 0173e05..ad15a76 100644 --- a/handler/scoresaber/score.go +++ b/handler/scoresaber/score.go @@ -2,13 +2,17 @@ package scoresaber import ( "log" + "os" "strconv" "strings" + "sync" "git.lxtend.com/qqbot/constants" "git.lxtend.com/qqbot/handler" + "git.lxtend.com/qqbot/message" "git.lxtend.com/qqbot/model" "git.lxtend.com/qqbot/service/scoresaber" + "git.lxtend.com/qqbot/util" ) func init() { @@ -153,13 +157,40 @@ func getMyRecentScore(msg model.Message) (reply model.Reply) { FromMsg: msg, } } - for _, v := range records { - scoreMsg += v.ToString() + "\n\n" - userName = v.Name + coverImageMap := make(map[string]string) + wg := sync.WaitGroup{} + for _, record := range records { + coverImageMap[record.SongHash] = record.CoverImage + wg.Add(1) + go func(songHash string) { + defer wg.Done() + //文件存在则跳过 + if _, err := os.Stat(util.GetResizedIamgePathByOrgPath(util.GenTempFilePath(songHash + ".jpeg"))); err == nil { + return + } + util.DownloadFile(coverImageMap[songHash], util.GenTempFilePath(songHash+".jpeg")) + newPath, err := util.ResizeImageByMaxHeight(util.GenTempFilePath(songHash+".jpeg"), 20) + os.Remove(util.GenTempFilePath(songHash + ".jpeg")) + if err != nil { + log.Printf("缩放图片失败: %v", err) + } + coverImageMap[songHash] = newPath + }(record.SongHash) + } + wg.Wait() + for _, record := range records { + imageMsg := message.ImageMessage{ + Type: "image", + Data: message.ImageMessageData{ + File: util.GetResizedIamgePathByOrgPath(util.GenTempFilePath(record.SongHash + ".jpeg")), + }, + } + scoreMsg += imageMsg.ToCQString() + record.ToString() + "\n" + userName = record.Name recordCount++ } if len(scoreMsg) > 0 { - scoreMsg = scoreMsg[:len(scoreMsg)-len("\n\n")] //去掉最后一个换行符 + scoreMsg = scoreMsg[:len(scoreMsg)-len("\n")] //去掉最后一个换行符 } else { return model.Reply{ ReplyMsg: "无最近游戏记录",