From b55d1f24b82ec917c6adec95ababad5728eed864 Mon Sep 17 00:00:00 2001 From: lixiangwuxian Date: Mon, 5 May 2025 01:37:48 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=8F=90=E5=8F=96=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E4=BF=A1=E6=81=AF=E8=8E=B7=E5=8F=96=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E5=88=B0=20util.NewSelfNodeMessage=20=E5=87=BD=E6=95=B0?= =?UTF-8?q?=EF=BC=8C=E7=AE=80=E5=8C=96=E6=B6=88=E6=81=AF=E5=A4=84=E7=90=86?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- handler/beatleader/beatleader.go | 12 +----------- handler/scoresaber/score.go | 12 +----------- util/message.go | 21 +++++++++++++++++++++ 3 files changed, 23 insertions(+), 22 deletions(-) create mode 100644 util/message.go 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}} +}