fix: Create a new XP entry for new users

master
Luther Wen Xu 2020-09-15 00:10:40 +07:00
parent 877cf55380
commit f59ccc00e0
Signed by: chanbakjsd
GPG Key ID: B7D77E3E9D102B70
1 changed files with 8 additions and 1 deletions

@ -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 {