go: discord/backend: Gracefully handle low global active level

master
Luther Wen Xu 2019-10-18 11:48:50 +07:00
parent c934af81e2
commit 7116381000
Signed by: chanbakjsd
GPG Key ID: B7D77E3E9D102B70
1 changed files with 8 additions and 4 deletions

@ -41,15 +41,19 @@ func GetTrust(s *discordgo.Session, discordID string) (float64, error) {
}
voteResult := total / float64(len(votes))
//Calculate active level
totalLevel, err := db.GetTotalActiveLevel()
if err != nil {
return voteResult, nil
}
if totalLevel < 1000000 {
return voteResult, nil
}
activeLevel, err := db.GetActiveLevel(discordID)
if err != nil && err != db.ErrNotFound {
//ErrNotFound is allowed. It just means the player hasn't played yet.
return 0.0, err
}
totalLevel, err := db.GetTotalActiveLevel()
if err != nil {
return 0.0, err
}
activeBuff := float64(activeLevel) / float64(totalLevel)
return voteResult * (1 + activeBuff), nil