fix: 在 MsgInHandler 中添加对 StructuredMsg 长度的检查,避免潜在的数组越界错误;更新 PlayerDataLite 结构体,添加 Gorm 标签以支持数据库映射

This commit is contained in:
lixiangwuxian 2025-07-05 20:51:59 +08:00
parent c50ca47911
commit 5ce7f7bba4
2 changed files with 16 additions and 16 deletions

View File

@ -119,7 +119,7 @@ func MsgInHandler(msg model.Message) (reply *model.Reply) {
return reply return reply
} }
} }
if msg.StructuredMsg[0].GetMessageType() == qq_message.TypeAt { if len(msg.StructuredMsg) > 0 && msg.StructuredMsg[0].GetMessageType() == qq_message.TypeAt {
if atMsg, ok := msg.StructuredMsg[0].(*qq_message.AtMessage); ok { if atMsg, ok := msg.StructuredMsg[0].(*qq_message.AtMessage); ok {
atUserID := atMsg.Data.QQ atUserID := atMsg.Data.QQ
loginAccountInfo, err := action.GetLoginAccountInfo() loginAccountInfo, err := action.GetLoginAccountInfo()

View File

@ -203,21 +203,21 @@ type PlayerData struct {
} }
type PlayerDataLite struct { type PlayerDataLite struct {
ID string `json:"id" db:"id"` ID string `json:"id" db:"id" gorm:"column:id"`
Name string `json:"name" db:"name"` Name string `json:"name" db:"name" gorm:"column:name"`
ProfilePicture string `json:"profilePicture" db:"profile_picture"` ProfilePicture string `json:"profilePicture" db:"profile_picture" gorm:"column:profile_picture"`
Country string `json:"country" db:"country"` Country string `json:"country" db:"country" gorm:"column:country"`
Device string `json:"device" db:"device"` Device string `json:"device" db:"device" gorm:"column:device"`
PP float64 `json:"pp" db:"pp"` PP float64 `json:"pp" db:"pp" gorm:"column:pp"`
Rank int `json:"rank" db:"rank"` Rank int `json:"rank" db:"rank" gorm:"column:rank"`
CountryRank int `json:"countryRank" db:"country_rank"` CountryRank int `json:"countryRank" db:"country_rank" gorm:"column:country_rank"`
TotalScore int `json:"totalScore" db:"total_score"` TotalScore int `json:"totalScore" db:"total_score" gorm:"column:total_score"`
TotalRankedScore int `json:"totalRankedScore" db:"total_ranked_score"` TotalRankedScore int `json:"totalRankedScore" db:"total_ranked_score" gorm:"column:total_ranked_score"`
AverageRankedAccuracy float64 `json:"averageRankedAccuracy" db:"average_ranked_accuracy"` AverageRankedAccuracy float64 `json:"averageRankedAccuracy" db:"average_ranked_accuracy" gorm:"column:average_ranked_accuracy"`
TotalPlayCount int `json:"totalPlayCount" db:"total_play_count"` TotalPlayCount int `json:"totalPlayCount" db:"total_play_count" gorm:"column:total_play_count"`
RankedPlayCount int `json:"rankedPlayCount" db:"ranked_play_count"` RankedPlayCount int `json:"rankedPlayCount" db:"ranked_play_count" gorm:"column:ranked_play_count"`
ReplaysWatched int `json:"replaysWatched" db:"replays_watched"` ReplaysWatched int `json:"replaysWatched" db:"replays_watched" gorm:"column:replays_watched"`
GeneratedTime string `json:"generatedTime" db:"generated_time"` GeneratedTime string `json:"generatedTime" db:"generated_time" gorm:"column:generated_time"`
} }
func (p PlayerDataLite) IsDiffFrom(p2 PlayerDataLite) bool { func (p PlayerDataLite) IsDiffFrom(p2 PlayerDataLite) bool {