From 6662f3ccfc28c2653b2a856b0a826b2f112185da Mon Sep 17 00:00:00 2001 From: lixiangwuxian Date: Mon, 5 May 2025 02:40:53 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=BC=98=E5=8C=96=20getMyRecentSco?= =?UTF-8?q?re=20=E5=87=BD=E6=95=B0=E4=B8=AD=E7=9A=84=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E6=9E=84=E5=BB=BA=E9=80=BB=E8=BE=91=EF=BC=8C=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E7=BB=93=E6=9E=84=E5=8C=96=E6=B6=88=E6=81=AF=E6=8F=90=E5=8D=87?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E5=8F=AF=E8=AF=BB=E6=80=A7=E5=92=8C=E5=8F=AF?= =?UTF-8?q?=E7=BB=B4=E6=8A=A4=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- handler/beatleader/beatleader.go | 7 +++++- handler/scoresaber/score.go | 40 +++++++++++++++++++++++++------- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/handler/beatleader/beatleader.go b/handler/beatleader/beatleader.go index 74a963d..efc86de 100644 --- a/handler/beatleader/beatleader.go +++ b/handler/beatleader/beatleader.go @@ -287,7 +287,12 @@ func getMyRecentScore(msg model.Message) (reply *model.Reply) { } //如果消息行数太多,使用合并转发 if len(records) > 5 { - nodeMsg := util.NewSelfNodeMessage("玩家 " + userName + " 的" + strconv.Itoa(recordCount) + "条最近记录为:\n" + scoreMsg) + nodeMsg := util.NewSelfNodeMessage(&message.TextMessage{ + Type: "text", + Data: message.TextMessageData{ + Text: "玩家 " + userName + " 的" + strconv.Itoa(recordCount) + "条最近记录为:\n" + scoreMsg, + }, + }) action.ActionManager.SendForward( &model.Reply{ ReplyMsg: []any{&nodeMsg}, diff --git a/handler/scoresaber/score.go b/handler/scoresaber/score.go index 5215c02..adda534 100644 --- a/handler/scoresaber/score.go +++ b/handler/scoresaber/score.go @@ -232,7 +232,7 @@ func unbindSS(msg model.Message) (reply *model.Reply) { func getMyRecentScore(msg model.Message) (reply *model.Reply) { count := 1 - scoreMsg := "" + scoreMsg := []any{} if len(msg.RawMsg) > len("最新ss ") { var err error count, err = strconv.Atoi(msg.RawMsg[len("最新ss "):]) @@ -285,13 +285,17 @@ func getMyRecentScore(msg model.Message) (reply *model.Reply) { File: coverImageMap[record.SongHash], }, } - scoreMsg += imageMsg.ToCQString() + record.ToString() + "\n" + textMsg := message.TextMessage{ + Type: "text", + Data: message.TextMessageData{ + Text: record.ToString(), + }, + } + scoreMsg = append(scoreMsg, imageMsg, textMsg) userName = record.Name recordCount++ } - if len(scoreMsg) > 0 { - scoreMsg = scoreMsg[:len(scoreMsg)-len("\n")] //去掉最后一个换行符 - } else { + if len(scoreMsg) <= 0 { return &model.Reply{ ReplyMsg: "无最近游戏记录", ReferOriginMsg: true, @@ -300,10 +304,20 @@ func getMyRecentScore(msg model.Message) (reply *model.Reply) { } //如果消息行数太多,使用合并转发 if len(records) > 5 { - nodeMsg := util.NewSelfNodeMessage("玩家 " + userName + " 的" + strconv.Itoa(recordCount) + "条最近记录为:\n" + scoreMsg) + var nodeMsgs []message.NodeMessage + nodeMsg := util.NewSelfNodeMessage(&message.TextMessage{ + Type: "text", + Data: message.TextMessageData{ + Text: "玩家 " + userName + " 的" + strconv.Itoa(recordCount) + "条最近记录为:\n", + }, + }) + nodeMsgs = append(nodeMsgs, *nodeMsg) + for _, msg := range scoreMsg { + nodeMsgs = append(nodeMsgs, *util.NewSelfNodeMessage(msg)) + } action.ActionManager.SendForward( &model.Reply{ - ReplyMsg: []any{&nodeMsg}, + ReplyMsg: nodeMsgs, ReferOriginMsg: false, FromMsg: msg, }, @@ -311,7 +325,17 @@ func getMyRecentScore(msg model.Message) (reply *model.Reply) { return nil } return &model.Reply{ - ReplyMsg: "玩家 " + userName + " 的" + strconv.Itoa(recordCount) + "条最近记录为:\n" + scoreMsg, + ReplyMsg: append( + []any{ + &message.TextMessage{ + Type: "text", + Data: message.TextMessageData{ + Text: "玩家 " + userName + " 的" + strconv.Itoa(recordCount) + "条最近记录为:", + }, + }, + }, + scoreMsg..., + ), ReferOriginMsg: true, FromMsg: msg, }