diff --git a/db/level.go b/db/level.go index d0ca916..2ae91de 100644 --- a/db/level.go +++ b/db/level.go @@ -27,10 +27,17 @@ func GetXP(userID string) int64 { } func IncrementXP(userID string, value int64, newTime time.Time) { - db.Model(&PlayerLevel{}). + result := db.Model(&PlayerLevel{}). Where(&PlayerLevel{UserID: userID}). UpdateColumn("xp", gorm.Expr("xp + ?", value)). UpdateColumn("last_active", newTime) + if result.RowsAffected == 0 { + db.Create(&PlayerLevel{ + UserID: userID, + XP: value, + LastActive: newTime, + }) + } } func GetLastActive(userID string) time.Time {