From aaa722a41470d40df0d37b5ec306a635c6db55a5 Mon Sep 17 00:00:00 2001 From: Kay Date: Tue, 9 Jan 2024 16:38:40 +0000 Subject: [PATCH] fix: get time after gRPC request --- discord/discord.go | 119 ++++++++++++++++++++++----------------------- 1 file changed, 58 insertions(+), 61 deletions(-) diff --git a/discord/discord.go b/discord/discord.go index b9291151..9e053052 100644 --- a/discord/discord.go +++ b/discord/discord.go @@ -1,11 +1,8 @@ package discord import ( - "encoding/json" "fmt" "log" - "math/big" - "os" "strings" "time" @@ -262,64 +259,64 @@ func (b *Bot) messageHandler(s *discordgo.Session, m *discordgo.MessageCreate) { return } - if m.Content == "pip19-report" { - t := time.Now() - - total := big.NewFloat(0) - scoresSum := big.NewFloat(0) - - results := make([]Result, 2000) - - info, err := b.cm.GetNetworkInfo() - if err != nil { - msg := "error getting network info" - _, _ = s.ChannelMessageSendReply(m.ChannelID, msg, m.Reference()) - return - } - - fmt.Printf("total peers: %v\n", info.ConnectedPeersCount) - - for i, p := range info.ConnectedPeers { - fmt.Printf("new peer %v\n", i) - r := Result{} - r.Agent = p.Agent - r.RemoteAddress = p.Address - r.IsActive = true - if p.Height < 673_000 { - r.IsActive = false - } - for iv, v := range p.ConsensusKeys { - fmt.Printf("new validator %v\n", iv) - val, err := b.cm.GetValidatorInfo(v) - if err != nil { - continue - } - r.PIP19Score = val.Validator.AvailabilityScore - r.ValidatorAddress = v - - results = append(results, r) - total = total.Abs(big.NewFloat(1)) - scoresSum = scoresSum.Abs(big.NewFloat(val.Validator.AvailabilityScore)) - } - } - - data, err := json.Marshal(results) - if err != nil { - msg := "error saving report" - _, _ = s.ChannelMessageSendReply(m.ChannelID, msg, m.Reference()) - return - } - - if err = os.WriteFile("pip19Report.json", data, 0o600); err != nil { - msg := "error saving report" - _, _ = s.ChannelMessageSendReply(m.ChannelID, msg, m.Reference()) - return - } - - msg := fmt.Sprintf("time:%v\n avg:%v", t.Format("15:04:05"), new(big.Float).Quo(scoresSum, total)) - _, _ = s.ChannelMessageSendReply(m.ChannelID, msg, m.Reference()) - return - } + // if m.Content == "pip19-report" { + // t := time.Now() + + // total := big.NewFloat(0) + // scoresSum := big.NewFloat(0) + + // results := make([]Result, 2000) + + // info, err := b.cm.GetNetworkInfo() + // if err != nil { + // msg := "error getting network info" + // _, _ = s.ChannelMessageSendReply(m.ChannelID, msg, m.Reference()) + // return + // } + + // fmt.Printf("total peers: %v\n", info.ConnectedPeersCount) + + // for i, p := range info.ConnectedPeers { + // fmt.Printf("new peer %v\n", i) + // r := Result{} + // r.Agent = p.Agent + // r.RemoteAddress = p.Address + // r.IsActive = true + // if p.Height < 673_000 { + // r.IsActive = false + // } + // for iv, v := range p.ConsensusKeys { + // fmt.Printf("new validator %v\n", iv) + // val, err := b.cm.GetValidatorInfo(v) + // if err != nil { + // continue + // } + // r.PIP19Score = val.Validator.AvailabilityScore + // r.ValidatorAddress = v + + // results = append(results, r) + // total = total.Abs(big.NewFloat(1)) + // scoresSum = scoresSum.Abs(big.NewFloat(val.Validator.AvailabilityScore)) + // } + // } + + // data, err := json.Marshal(results) + // if err != nil { + // msg := "error saving report" + // _, _ = s.ChannelMessageSendReply(m.ChannelID, msg, m.Reference()) + // return + // } + + // if err = os.WriteFile("pip19Report.json", data, 0o600); err != nil { + // msg := "error saving report" + // _, _ = s.ChannelMessageSendReply(m.ChannelID, msg, m.Reference()) + // return + // } + + // msg := fmt.Sprintf("time:%v\n avg:%v", t.Format("15:04:05"), new(big.Float).Quo(scoresSum, total)) + // _, _ = s.ChannelMessageSendReply(m.ChannelID, msg, m.Reference()) + // return + // } } // help sends a message detailing how to use the bot discord-client side