-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add discord /missing proper command (#59)
* feat: add discord /missing proper command * chore: fixed linting * feat: add discord /validators command * feat: add missing and validators cmds to /help
- Loading branch information
1 parent
9c30c2d
commit c1aded7
Showing
9 changed files
with
101 additions
and
36 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,3 +54,4 @@ linters: | |
- durationcheck | ||
- gocyclo | ||
- exhaustive | ||
- mnd |
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,67 @@ | ||
package discord | ||
|
||
import ( | ||
"fmt" | ||
"main/pkg/constants" | ||
snapshotPkg "main/pkg/snapshot" | ||
"main/pkg/utils" | ||
"sort" | ||
|
||
"github.com/bwmarrin/discordgo" | ||
) | ||
|
||
func (reporter *Reporter) GetValidatorsCommand() *Command { | ||
return &Command{ | ||
Info: &discordgo.ApplicationCommand{ | ||
Name: "validators", | ||
Description: "Get the list of all validators and their missing blocks", | ||
}, | ||
Handler: func(s *discordgo.Session, i *discordgo.InteractionCreate) { | ||
reporter.MetricsManager.LogReporterQuery(reporter.Config.Name, constants.TelegramReporterName, "validators") | ||
|
||
snapshot, found := reporter.SnapshotManager.GetNewerSnapshot() | ||
if !found { | ||
reporter.Logger.Info(). | ||
Msg("No older snapshot on discord validators query!") | ||
reporter.BotRespond(s, i, "Error getting validators list") | ||
return | ||
} | ||
|
||
validatorEntries := snapshot.Entries.ToSlice() | ||
activeValidatorsEntries := utils.Filter(validatorEntries, func(v snapshotPkg.Entry) bool { | ||
return v.Validator.Active() | ||
}) | ||
|
||
sort.Slice(activeValidatorsEntries, func(firstIndex, secondIndex int) bool { | ||
first := activeValidatorsEntries[firstIndex] | ||
second := activeValidatorsEntries[secondIndex] | ||
|
||
return first.SignatureInfo.GetNotSigned() < second.SignatureInfo.GetNotSigned() | ||
}) | ||
|
||
render := missingValidatorsRender{ | ||
Config: reporter.Config, | ||
Validators: utils.Map(activeValidatorsEntries, func(v snapshotPkg.Entry) missingValidatorsEntry { | ||
link := reporter.Config.ExplorerConfig.GetValidatorLink(v.Validator) | ||
group, _, _ := reporter.Config.MissedBlocksGroups.GetGroup(v.SignatureInfo.GetNotSigned()) | ||
link.Text = fmt.Sprintf("%s %s", group.EmojiEnd, v.Validator.Moniker) | ||
|
||
return missingValidatorsEntry{ | ||
Validator: v.Validator, | ||
Link: link, | ||
NotSigned: v.SignatureInfo.GetNotSigned(), | ||
BlocksWindow: reporter.Config.BlocksWindow, | ||
} | ||
}), | ||
} | ||
|
||
template, err := reporter.TemplatesManager.Render("Validators", render) | ||
if err != nil { | ||
reporter.Logger.Error().Err(err).Msg("Error rendering missing") | ||
return | ||
} | ||
|
||
reporter.BotRespond(s, i, template) | ||
}, | ||
} | ||
} |
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 not .Validators }} | ||
There are no active validators on {{ .Config.GetName }}! | ||
{{- else }} | ||
**Validators' status on {{ .Config.GetName }}:** | ||
{{- end }} | ||
{{ range .Validators -}} | ||
**{{ SerializeLink .Link }}**: {{ .NotSigned }} missed blocks ({{ .FormatMissed }}%) | ||
{{ end }} |