refactor: 提取用户信息获取逻辑到 util.NewSelfNodeMessage 函数,简化消息处理逻辑
This commit is contained in:
parent
ebadac56c4
commit
b55d1f24b8
@ -293,17 +293,7 @@ func getMyRecentScore(msg model.Message) (reply *model.Reply) {
|
|||||||
Text: "玩家 " + userName + " 的" + strconv.Itoa(recordCount) + "条最近记录为:\n" + scoreMsg,
|
Text: "玩家 " + userName + " 的" + strconv.Itoa(recordCount) + "条最近记录为:\n" + scoreMsg,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
nodeMsg := message.NewNodeMessage()
|
nodeMsg := util.NewSelfNodeMessage()
|
||||||
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.Data.Content = []any{&textMsg}
|
nodeMsg.Data.Content = []any{&textMsg}
|
||||||
action.ActionManager.SendForward(
|
action.ActionManager.SendForward(
|
||||||
&model.Reply{
|
&model.Reply{
|
||||||
|
@ -306,17 +306,7 @@ func getMyRecentScore(msg model.Message) (reply *model.Reply) {
|
|||||||
Text: "玩家 " + userName + " 的" + strconv.Itoa(recordCount) + "条最近记录为:\n" + scoreMsg,
|
Text: "玩家 " + userName + " 的" + strconv.Itoa(recordCount) + "条最近记录为:\n" + scoreMsg,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
nodeMsg := message.NewNodeMessage()
|
nodeMsg := util.NewSelfNodeMessage()
|
||||||
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.Data.Content = []any{&textMsg}
|
nodeMsg.Data.Content = []any{&textMsg}
|
||||||
action.ActionManager.SendForward(
|
action.ActionManager.SendForward(
|
||||||
&model.Reply{
|
&model.Reply{
|
||||||
|
21
util/message.go
Normal file
21
util/message.go
Normal file
@ -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}}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user