refactor: 优化 getMyRecentScore 函数中的消息构建逻辑,使用结构化消息提升代码可读性和可维护性
This commit is contained in:
parent
5b7a5a5aca
commit
6662f3ccfc
@ -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},
|
||||
|
@ -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,
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user