refactor: 修改 NewSelfNodeMessage 函数以接受内容参数,并更新消息处理逻辑以简化代码结构

This commit is contained in:
lixiangwuxian 2025-05-05 02:02:14 +08:00
parent b55d1f24b8
commit 2eb0d5de20
3 changed files with 6 additions and 10 deletions

View File

@ -287,14 +287,12 @@ func getMyRecentScore(msg model.Message) (reply *model.Reply) {
} }
//如果消息行数太多,使用合并转发 //如果消息行数太多,使用合并转发
if len(records) > 5 { if len(records) > 5 {
textMsg := message.TextMessage{ nodeMsg := util.NewSelfNodeMessage(&message.TextMessage{
Type: "text", Type: "text",
Data: message.TextMessageData{ Data: message.TextMessageData{
Text: "玩家 " + userName + " 的" + strconv.Itoa(recordCount) + "条最近记录为:\n" + scoreMsg, Text: "玩家 " + userName + " 的" + strconv.Itoa(recordCount) + "条最近记录为:\n" + scoreMsg,
}, },
} })
nodeMsg := util.NewSelfNodeMessage()
nodeMsg.Data.Content = []any{&textMsg}
action.ActionManager.SendForward( action.ActionManager.SendForward(
&model.Reply{ &model.Reply{
ReplyMsg: []any{&nodeMsg}, ReplyMsg: []any{&nodeMsg},

View File

@ -300,14 +300,12 @@ func getMyRecentScore(msg model.Message) (reply *model.Reply) {
} }
//如果消息行数太多,使用合并转发 //如果消息行数太多,使用合并转发
if len(records) > 5 { if len(records) > 5 {
textMsg := message.TextMessage{ nodeMsg := util.NewSelfNodeMessage(&message.TextMessage{
Type: "text", Type: "text",
Data: message.TextMessageData{ Data: message.TextMessageData{
Text: "玩家 " + userName + " 的" + strconv.Itoa(recordCount) + "条最近记录为:\n" + scoreMsg, Text: "玩家 " + userName + " 的" + strconv.Itoa(recordCount) + "条最近记录为:\n" + scoreMsg,
}, },
} })
nodeMsg := util.NewSelfNodeMessage()
nodeMsg.Data.Content = []any{&textMsg}
action.ActionManager.SendForward( action.ActionManager.SendForward(
&model.Reply{ &model.Reply{
ReplyMsg: []any{&nodeMsg}, ReplyMsg: []any{&nodeMsg},

View File

@ -8,7 +8,7 @@ import (
"git.lxtend.com/qqbot/message" "git.lxtend.com/qqbot/message"
) )
func NewSelfNodeMessage() *message.NodeMessage { func NewSelfNodeMessage(content ...any) *message.NodeMessage {
loginAccountInfo, err := action.GetLoginAccountInfo() loginAccountInfo, err := action.GetLoginAccountInfo()
if err != nil { if err != nil {
log.Println("GetLoginAccountInfo error:", err) log.Println("GetLoginAccountInfo error:", err)
@ -17,5 +17,5 @@ func NewSelfNodeMessage() *message.NodeMessage {
if loginAccountInfo == nil { if loginAccountInfo == nil {
return nil return nil
} }
return &message.NodeMessage{Type: message.TypeNode, Data: message.NodeMessageData{UserID: strconv.FormatInt(int64(loginAccountInfo.Data.UserID), 10), Nickname: loginAccountInfo.Data.Nickname}} return &message.NodeMessage{Type: message.TypeNode, Data: message.NodeMessageData{UserID: strconv.FormatInt(int64(loginAccountInfo.Data.UserID), 10), Nickname: loginAccountInfo.Data.Nickname, Content: content}}
} }