diff --git a/handler/beatleader/beatleader.go b/handler/beatleader/beatleader.go index 4db7d97..5fb9738 100644 --- a/handler/beatleader/beatleader.go +++ b/handler/beatleader/beatleader.go @@ -293,17 +293,7 @@ func getMyRecentScore(msg model.Message) (reply *model.Reply) { Text: "玩家 " + userName + " 的" + strconv.Itoa(recordCount) + "条最近记录为:\n" + scoreMsg, }, } - nodeMsg := message.NewNodeMessage() - loginAccountInfo, err := action.GetLoginAccountInfo() - if err != nil { - log.Println("GetLoginAccountInfo error:", err) - return nil - } - if loginAccountInfo == nil { - return nil - } - nodeMsg.Data.UserID = strconv.FormatInt(int64(loginAccountInfo.Data.UserID), 10) - nodeMsg.Data.Nickname = loginAccountInfo.Data.Nickname + nodeMsg := util.NewSelfNodeMessage() nodeMsg.Data.Content = []any{&textMsg} action.ActionManager.SendForward( &model.Reply{ diff --git a/handler/scoresaber/score.go b/handler/scoresaber/score.go index 4b54736..cdfd30f 100644 --- a/handler/scoresaber/score.go +++ b/handler/scoresaber/score.go @@ -306,17 +306,7 @@ func getMyRecentScore(msg model.Message) (reply *model.Reply) { Text: "玩家 " + userName + " 的" + strconv.Itoa(recordCount) + "条最近记录为:\n" + scoreMsg, }, } - nodeMsg := message.NewNodeMessage() - loginAccountInfo, err := action.GetLoginAccountInfo() - if err != nil { - log.Println("GetLoginAccountInfo error:", err) - return nil - } - if loginAccountInfo == nil { - return nil - } - nodeMsg.Data.UserID = strconv.FormatInt(int64(loginAccountInfo.Data.UserID), 10) - nodeMsg.Data.Nickname = loginAccountInfo.Data.Nickname + nodeMsg := util.NewSelfNodeMessage() nodeMsg.Data.Content = []any{&textMsg} action.ActionManager.SendForward( &model.Reply{ diff --git a/util/message.go b/util/message.go new file mode 100644 index 0000000..c6d83c8 --- /dev/null +++ b/util/message.go @@ -0,0 +1,21 @@ +package util + +import ( + "log" + "strconv" + + "git.lxtend.com/qqbot/action" + "git.lxtend.com/qqbot/message" +) + +func NewSelfNodeMessage() *message.NodeMessage { + loginAccountInfo, err := action.GetLoginAccountInfo() + if err != nil { + log.Println("GetLoginAccountInfo error:", err) + return nil + } + if loginAccountInfo == nil { + return nil + } + return &message.NodeMessage{Type: message.TypeNode, Data: message.NodeMessageData{UserID: strconv.FormatInt(int64(loginAccountInfo.Data.UserID), 10), Nickname: loginAccountInfo.Data.Nickname}} +}