diff --git a/src/server/web_handlers.go b/src/server/web_handlers.go index 3241d91..6c795d9 100644 --- a/src/server/web_handlers.go +++ b/src/server/web_handlers.go @@ -133,7 +133,7 @@ func (s *Server) handleScoreSummary(c iris.Context) { return } - summary := utils.ScoreSummary(service) + _, summary := utils.ComputeScore(service) c.Text(summary) } @@ -328,7 +328,7 @@ func (s *Server) handlePostRequestServiceForm(c iris.Context) { service.KycLevel = data.KYCLevel service.Attributes = data.Attributes - service.Score = utils.ComputeScore(&service) + service.Score, _ = utils.ComputeScore(&service) // Save service to database err := database.Pb.CreateService(service) @@ -342,3 +342,38 @@ func (s *Server) handlePostRequestServiceForm(c iris.Context) { // go utils.UpdateScore(sv) c.Redirect("/request/service?message=Success!", iris.StatusSeeOther) } + +func (s *Server) handlePgp(c iris.Context) { + text := ` +-----BEGIN PGP SIGNED MESSAGE----- +Hash: SHA512 + +Here's my public PGP key: + +- -----BEGIN PGP PUBLIC KEY BLOCK----- + +mDMEZczexBYJKwYBBAHaRw8BAQdA+X+cNkOv5SmauKLLw+xcEkcDQjVubZ/4Xj3d +5DNvgru0F3BsdWphIDxhZG1pbkBreWNub3QubWU+iJMEExYKADsWIQQEPOrx9H8d +Txv0tFhweQHG2o41CgUCZczexAIbAwULCQgHAgIiAgYVCgkICwIEFgIDAQIeBwIX +gAAKCRBweQHG2o41CjwVAQDpcxgeXK+2KiVzMkmLCXiAYU0hRhQmA4xwXDkqYxn7 +dwD+KzHpcnTwnrK5ZLn3+ti9DVeURTv1lFf9TVZTKgovOAy4OARlzN7EEgorBgEE +AZdVAQUBAQdAvrCLlUmBr/RswvfC4hOGa5Som7CGQp0WzpkyETZmRh0DAQgHiHgE +GBYKACAWIQQEPOrx9H8dTxv0tFhweQHG2o41CgUCZczexAIbDAAKCRBweQHG2o41 +ClZ1AQCwZ1XrRYLuM9d5mLXzbZVRjb5INoVXFrZbx9ZkAxKgFAD/dmJI/bUxPcVZ +f6cwP2HYnxD/i2C6ltaLK0SRrxI2XAM= +=Tnvi +- -----END PGP PUBLIC KEY BLOCK----- + +Any important matters, will be signed with this key. +-----BEGIN PGP SIGNATURE----- + +iHUEARYKAB0WIQQEPOrx9H8dTxv0tFhweQHG2o41CgUCZc0qQwAKCRBweQHG2o41 +Ctx3AP9TBHliRKIXpGmfCWKL6sRHqyT/eQQMjONqaZikrcmdzAEA/ff2+nionjTr +mQXRsALQl2Fpw4nY/hIOYkdASomusAg= +=uT9S +-----END PGP SIGNATURE----- + +` + + c.Text(text) +} diff --git a/src/utils/score.go b/src/utils/score.go index 34b89b1..ae9caf5 100644 --- a/src/utils/score.go +++ b/src/utils/score.go @@ -4,33 +4,28 @@ import ( "fmt" "math" - "github.com/rs/zerolog/log" - "pluja.dev/kycnot.me/database" ) -func ComputeScore(s *database.Service) int { - const ( - baseScore = 10 - maxScore = 10 - minScore = 0 - bonusLow = 15 - bonusMedium = 20 - bonusHigh = 25 - ) +func ComputeScore(s *database.Service) (int, string) { + summary := fmt.Sprintf("SCORE BREAKDOWN - %s:\n", s.Name) - grade := float64(baseScore) + grade := float64(10) // KYC Level Adjustment switch s.KycLevel { case 0: grade = 8 + summary += fmt.Sprintf("\n%-*s--> base score for KYC Level %d", 10, fmt.Sprintf("|| %v", grade), s.KycLevel) case 1: grade = 7 + summary += fmt.Sprintf("\n%-*s--> base score for KYC Level %d", 10, fmt.Sprintf("|| %v", grade), s.KycLevel) case 2: grade = 6 + summary += fmt.Sprintf("\n%-*s--> base score for KYC Level %d", 10, fmt.Sprintf("|| %v", grade), s.KycLevel) case 3: grade = 5 + summary += fmt.Sprintf("\n%-*s--> base score for KYC Level %d", 10, fmt.Sprintf("|| %v", grade), s.KycLevel) } // Attributes @@ -38,10 +33,13 @@ func ComputeScore(s *database.Service) int { switch attr.Rating { case "good": grade += 0.1 + summary += fmt.Sprintf("\n%-*s--> good attribute.", 10, "|| +0.1") case "warn": grade -= 0.25 + summary += fmt.Sprintf("\n%-*s--> warn attribute.", 10, "|| -0.25") case "bad": - grade -= 0.5 + grade -= 0.65 + summary += fmt.Sprintf("\n%-*s--> bad attribute.", 10, "|| -0.65") } } @@ -51,22 +49,31 @@ func ComputeScore(s *database.Service) int { } trPenalty := 0.0 + wrns := 0 for _, tr := range s.TosReviews { if tr.Warning { - trPenalty -= 0.1 + trPenalty -= 0.02 + wrns++ } } if trPenalty > 3 { trPenalty = 3 } + grade += float64(trPenalty) + if trPenalty != 0 { + summary += fmt.Sprintf("\n|| %-*f--> %d terms of service warnings.", 10, trPenalty, wrns) + } + // Cash/Monero Bonus if s.Cash || s.Xmr || s.Btc { - grade += 0.5 + grade += 0.25 + summary += fmt.Sprintf("\n%-*s--> accepting Cash/BTC.", 10, "|| +0.25") if s.Xmr { grade += 0.25 + summary += fmt.Sprintf("\n%-*s--> accepting XMR.", 10, "|| +0.25") } } @@ -86,115 +93,39 @@ func ComputeScore(s *database.Service) int { // Tor URL Bonus if len(s.OnionUrls) > 0 && s.OnionUrls[0] != "" { grade += 0.5 + summary += fmt.Sprintf("\n%-*s--> has Onion links.", 10, "|| +0.5") } if s.Verified { if grade < 7.5 { grade += 0.5 + summary += fmt.Sprintf("\n%-*s--> verified bonus (only if <7.5).", 10, "|| +0.5") } } if !isP2P && grade > 9.5 { grade = 9 + summary += fmt.Sprintf("\n%-*s--> Not P2P, score can't be 10.", 10, "|| +0.5") } - if isP2P || isOpenSource && grade < 8 { + if isP2P { grade += 0.5 + summary += fmt.Sprintf("\n%-*s--> P2P bonus.", 10, "|| +0.5") + } + + if isOpenSource && grade < 7.5 { + grade += 0.25 + summary += fmt.Sprintf("\n%-*s--> Open Source bonus (if < 7.5).", 10, "|| +0.25") } // Normalize the grade to be within 0-10 bounds - grade = math.Min(maxScore, math.Max(minScore, grade)) + grade = math.Min(10, math.Max(0, grade)) - log.Debug().Msgf("Computed score for %s: %f", s.Name, math.RoundToEven(grade)) + summary += "\n||---------------------------------------" - return int(math.RoundToEven(grade)) -} + summary += fmt.Sprintf("\n|| %-*v--> Total (rounded to even)", 6, math.RoundToEven(grade)) // Call ComputeScore to get the actual score -func ScoreSummary(s *database.Service) string { - summary := fmt.Sprintf("SCORE BREAKDOWN - %s:\n", s.Name) - const leftPad = 10 // Adjust this based on your longest line - - // KYC Level Adjustment - switch s.KycLevel { - case 0: - summary += fmt.Sprintf("\n%-*s--> base score for KYC Level 0", leftPad, "|| 8") - case 1: - summary += fmt.Sprintf("\n%-*s--> base score for KYC Level 1", leftPad, "|| 7") - case 2: - summary += fmt.Sprintf("\n%-*s--> base score for KYC Level 2", leftPad, "|| 6") - case 3: - summary += fmt.Sprintf("\n%-*s--> base score for KYC Level 3", leftPad, "|| 5") - } - - // Attributes - for _, attr := range s.Expand["attributes"] { - switch attr.Rating { - case "good": - summary += fmt.Sprintf("\n%-*s--> good attribute.", leftPad, "|| +0.1") - case "warn": - summary += fmt.Sprintf("\n%-*s--> warn attribute.", leftPad, "|| -0.25") - case "bad": - summary += fmt.Sprintf("\n%-*s--> bad attribute.", leftPad, "|| -0.5") - } - } - - // Tos Highlights Penalty (Corrected to reflect actual penalty logic) - trPenalty := 0.0 - wrns := 0 - for _, tr := range s.TosReviews { - if tr.Warning { - trPenalty -= 0.1 - wrns++ - } - } - if trPenalty < -3 { - trPenalty = -3 - } - - if trPenalty != 0 { - summary += fmt.Sprintf("\n|| %-*f--> %d terms of service warnings.", leftPad, trPenalty, wrns) - } - - // Cash/Monero Bonus - if s.Cash || s.Xmr || s.Btc { - summary += fmt.Sprintf("\n%-*s--> accepting Cash/BTC.", leftPad, "|| +0.5") - if s.Xmr { - summary += fmt.Sprintf("\n%-*s--> monero bonus.", leftPad, "|| +0.25") - } - } - - // Tor URL Bonus - if len(s.OnionUrls) > 0 && s.OnionUrls[0] != "" { - summary += fmt.Sprintf("\n%-*s--> having a Tor URL.", leftPad, "|| +0.5") - } - - // Verified Bonus - if s.Verified { - summary += fmt.Sprintf("\n%-*s--> being verified (applies only if score was below 7.5 at this point).", leftPad, "|| +0.5") - } - - // P2P/OpenSource Bonus - // Note: Since the original ComputeScore doesn't show the exact bonus amount for P2P/OpenSource, - // it's assumed to follow the similar logic as in ComputeScore for simplicity. - isP2P := false - isOpenSource := false - for _, attr := range s.Attributes { - if attr == database.AttributeP2P { - isP2P = true - } - if attr == database.AttributeOpenSource { - isOpenSource = true - } - } - if isP2P || isOpenSource { - summary += fmt.Sprintf("\n%-*s--> P2P/OpenSource bonus (applies if score was below 8).", leftPad, "|| +0.5") - } - - summary += "\n||" - summary += fmt.Sprintf("\n|| Total: %v", ComputeScore(s)) // Call ComputeScore to get the actual score - summary += "\n(final score is rounded to even number)" - - return summary + return int(math.RoundToEven(grade)), summary } /*func UpdateScore(s *ent.Service) error {