-
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
a926a34
commit 37e3539
Showing
7 changed files
with
110 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package telegram | ||
|
||
import ( | ||
"main/pkg/constants" | ||
|
||
tele "gopkg.in/telebot.v3" | ||
) | ||
|
||
func (reporter *Reporter) HandleJailsCount(c tele.Context) error { | ||
reporter.Logger.Info(). | ||
Str("sender", c.Sender().Username). | ||
Str("text", c.Text()). | ||
Msg("Got jails count query") | ||
|
||
reporter.MetricsManager.LogReporterQuery(reporter.Config.Name, constants.TelegramReporterName, "jailscount") | ||
|
||
snapshot, found := reporter.SnapshotManager.GetNewerSnapshot() | ||
if !found { | ||
reporter.Logger.Info(). | ||
Str("sender", c.Sender().Username). | ||
Str("text", c.Text()). | ||
Msg("No older snapshot on telegram events query!") | ||
return reporter.BotReply(c, "Error getting validator events!") | ||
} | ||
|
||
jailsCount, err := reporter.Manager.FindAllJailsCount() | ||
if err != nil { | ||
return reporter.BotReply(c, "Error searching for jails count!") | ||
} | ||
|
||
jailsCountRendered := make([]renderedJailsCount, len(jailsCount)) | ||
|
||
for index, validatorJailsCount := range jailsCount { | ||
validatorEntries := snapshot.Entries.ByValidatorAddresses([]string{validatorJailsCount.Validator}) | ||
if len(validatorEntries) == 0 { | ||
return reporter.BotReply(c, "Validator is not found!") | ||
} | ||
|
||
jailsCountRendered[index] = renderedJailsCount{ | ||
ValidatorLink: reporter.Config.ExplorerConfig.GetValidatorLink(validatorEntries[0].Validator), | ||
JailsCount: validatorJailsCount.JailsCount, | ||
} | ||
} | ||
|
||
return reporter.ReplyRender(c, "JailsCount", jailsCountRendered) | ||
} |
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
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 . }} | ||
<strong>Validators jails count since the app was started:</strong> | ||
{{- range . }} | ||
{{ SerializeLink .ValidatorLink }}: {{ .JailsCount }} | ||
{{- end }} | ||
{{- else }} | ||
Nobody has been jailed since the app launch. | ||
{{- end }} |