-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add proposals command for discord
- Loading branch information
1 parent
e8a9d61
commit 1a3bcd0
Showing
5 changed files
with
60 additions
and
2 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
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,29 @@ | ||
package discord | ||
|
||
import ( | ||
"context" | ||
statePkg "main/pkg/state" | ||
|
||
"github.com/bwmarrin/discordgo" | ||
) | ||
|
||
func (reporter *Reporter) GetProposalsCommand() *Command { | ||
return &Command{ | ||
Info: &discordgo.ApplicationCommand{ | ||
Name: "proposals", | ||
Description: "Get list of active proposals and your wallet's votes on them.", | ||
}, | ||
Handler: func(s *discordgo.Session, i *discordgo.InteractionCreate) { | ||
state := reporter.StateGenerator.GetState(statePkg.NewState(), context.Background()) | ||
renderedState := state.ToRenderedState() | ||
|
||
template, err := reporter.TemplatesManager.Render("proposals", renderedState) | ||
if err != nil { | ||
reporter.Logger.Error().Err(err).Str("template", "proposals").Msg("Error rendering template") | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{{- if not .ChainInfos }} | ||
**No active proposals** | ||
{{- end }} | ||
{{- range .ChainInfos }} | ||
{{- $chain := .Chain -}} | ||
**{{ .Chain.GetName }}** | ||
{{- if .HasProposalsError }} | ||
❌ Error querying for proposals: {{ .ProposalsError }} | ||
{{- end }} | ||
{{- range .ProposalVotes }} | ||
{{- $proposalLink := $chain.GetProposalLink .Proposal }} | ||
Proposal #{{ .Proposal.ID }}: {{ SerializeLink $proposalLink }} (voting ends in {{ .Proposal.GetTimeLeft }}) | ||
{{- range $wallet, $vote := .Votes }} | ||
{{- $walletLink := $chain.GetWalletLink $vote.Wallet -}} | ||
{{- if $vote.IsError }} | ||
❌ Wallet {{ SerializeLink $walletLink }} - error querying: {{ $vote.Error }} | ||
{{- else if $vote.HasVoted }} | ||
✅ Wallet {{ SerializeLink $walletLink }} - voted: {{ $vote.Vote.ResolveVote }} | ||
{{- else }} | ||
🔴 Wallet {{ SerializeLink $walletLink }} - not voted | ||
{{- end }} | ||
{{- end }} | ||
{{ end }} | ||
{{ end }} |