-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b561996
commit 40d9f45
Showing
6 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package discord | ||
|
||
import ( | ||
"main/pkg/constants" | ||
|
||
"github.com/bwmarrin/discordgo" | ||
) | ||
|
||
func (reporter *Reporter) GetJailsCountCommand() *Command { | ||
return &Command{ | ||
Info: &discordgo.ApplicationCommand{ | ||
Name: "jailscount", | ||
Description: "See jails count for each validator since the app was started", | ||
}, | ||
Handler: func(s *discordgo.Session, i *discordgo.InteractionCreate) { | ||
reporter.MetricsManager.LogReporterQuery(reporter.Config.Name, constants.DiscordReporterName, "jailscount") | ||
|
||
snapshot, found := reporter.SnapshotManager.GetNewerSnapshot() | ||
if !found { | ||
reporter.Logger.Error().Msg("Error searching for historical events!") | ||
reporter.BotRespond(s, i, "Error searching for jails count!") | ||
return | ||
} | ||
|
||
jailsCount, err := reporter.Manager.FindAllJailsCount() | ||
if err != nil { | ||
reporter.Logger.Error().Err(err).Msg("Error searching for jails count") | ||
reporter.BotRespond(s, i, "Error searching for jails count!") | ||
return | ||
} | ||
|
||
jailsCountRendered := make([]renderedJailsCount, len(jailsCount)) | ||
|
||
for index, validatorJailsCount := range jailsCount { | ||
validatorEntries := snapshot.Entries.ByValidatorAddresses([]string{validatorJailsCount.Validator}) | ||
if len(validatorEntries) == 0 { | ||
reporter.BotRespond(s, i, "Validator is not found!") | ||
return | ||
} | ||
|
||
jailsCountRendered[index] = renderedJailsCount{ | ||
ValidatorLink: reporter.Config.ExplorerConfig.GetValidatorLink(validatorEntries[0].Validator), | ||
JailsCount: validatorJailsCount.JailsCount, | ||
} | ||
} | ||
|
||
renderedTemplate, err := reporter.TemplatesManager.Render("JailsCount", jailsCountRendered) | ||
if err != nil { | ||
reporter.Logger.Error().Err(err).Msg("Error rendering template") | ||
return | ||
} | ||
|
||
reporter.BotRespond(s, i, renderedTemplate) | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{{- if . }} | ||
**Validators jails count observed by the app:** | ||
{{- range . }} | ||
- {{ SerializeLink .ValidatorLink }}: {{ .JailsCount }} | ||
{{- end }} | ||
{{- else }} | ||
Nobody has been jailed since the app launch. | ||
{{- end }} |