Skip to content

Commit

Permalink
feat: list mutes command for discord
Browse files Browse the repository at this point in the history
  • Loading branch information
freak12techno committed May 19, 2024
1 parent a974c98 commit 82d06c2
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/reporters/discord/discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func (reporter *Reporter) Init() error {
"proposals": reporter.GetProposalsCommand(),
"proposals_mute": reporter.GetAddMuteCommand(),
"proposals_unmute": reporter.GetDeleteMuteCommand(),
"proposals_mutes": reporter.GetMutesCommand(),
}

go reporter.InitCommands()
Expand Down
29 changes: 29 additions & 0 deletions pkg/reporters/discord/list_mutes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package discord

import (
"github.com/bwmarrin/discordgo"
mutes "main/pkg/mutes"
"main/pkg/utils"
)

func (reporter *Reporter) GetMutesCommand() *Command {
return &Command{
Info: &discordgo.ApplicationCommand{
Name: "proposals_mutes",
Description: "List all active mutes.",
},
Handler: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
filteredMutes := utils.Filter(reporter.MutesManager.Mutes.Mutes, func(m *mutes.Mute) bool {
return !m.IsExpired()
})

template, err := reporter.TemplatesManager.Render("mutes", filteredMutes)
if err != nil {
reporter.Logger.Error().Err(err).Str("template", "mutes").Msg("Error rendering template")
return
}

reporter.BotRespond(s, i, template)
},
}
}
16 changes: 16 additions & 0 deletions templates/discord/mutes.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{- if eq (len .) 0 }}
No active mutes.
{{- end }}
{{ range . }}
{{- if .Chain }}
**Chain:** {{ .Chain }}
{{- else }}
**Chain:** all chains
{{- end }}
{{- if .ProposalID }}
**Proposal ID:** {{ .ProposalID }}
{{- else }}
**Proposal ID:** all proposals
{{- end }}
**Expires: **{{ SerializeDate .Expires }}
{{ end }}

0 comments on commit 82d06c2

Please sign in to comment.