From 7116381000b80aacac0c7ffe83580500d063a3f1 Mon Sep 17 00:00:00 2001 From: Luther Wen Xu Date: Fri, 18 Oct 2019 11:48:50 +0800 Subject: [PATCH] go: discord/backend: Gracefully handle low global active level --- GoBot/discord/backend/trust.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/GoBot/discord/backend/trust.go b/GoBot/discord/backend/trust.go index fec2e7f..ab533fe 100644 --- a/GoBot/discord/backend/trust.go +++ b/GoBot/discord/backend/trust.go @@ -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