-
Notifications
You must be signed in to change notification settings - Fork 25
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 reporter * chore: add tests for SplitStringIntoChunks * feat: add proposals command for discord * feat: add mute command for discord * feat: delete mute command for discord * feat: list mutes command for discord * feat: add params command for discord + updating commands * feat: add tally command
- Loading branch information
1 parent
5cb4556
commit 698f895
Showing
30 changed files
with
1,027 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
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,82 @@ | ||
package discord | ||
|
||
import ( | ||
"fmt" | ||
mutes "main/pkg/mutes" | ||
"time" | ||
|
||
"github.com/bwmarrin/discordgo" | ||
) | ||
|
||
func (reporter *Reporter) GetAddMuteCommand() *Command { | ||
return &Command{ | ||
Info: &discordgo.ApplicationCommand{ | ||
Name: "proposals_mute", | ||
Description: "Mute proposals' notifications", | ||
Options: []*discordgo.ApplicationCommandOption{ | ||
{ | ||
Type: discordgo.ApplicationCommandOptionString, | ||
Name: "duration", | ||
Description: "For how long to mute notifications", | ||
Required: true, | ||
}, | ||
{ | ||
Type: discordgo.ApplicationCommandOptionString, | ||
Name: "chain", | ||
Description: "Chain to mute notifications on", | ||
Required: false, | ||
}, | ||
{ | ||
Type: discordgo.ApplicationCommandOptionString, | ||
Name: "proposal", | ||
Description: "Proposal to mute notifications on", | ||
Required: false, | ||
}, | ||
}, | ||
}, | ||
Handler: func(s *discordgo.Session, i *discordgo.InteractionCreate) { | ||
options := i.ApplicationCommandData().Options | ||
|
||
durationString, _ := options[0].Value.(string) | ||
var chain string | ||
var proposal string | ||
|
||
_, opts := options[0], options[1:] | ||
|
||
for _, opt := range opts { | ||
if opt.Name == "chain" { | ||
chain, _ = opt.Value.(string) | ||
} | ||
if opt.Name == "proposal" { | ||
proposal, _ = opt.Value.(string) | ||
} | ||
} | ||
|
||
duration, err := time.ParseDuration(durationString) | ||
if err != nil { | ||
reporter.BotRespond(s, i, "Invalid mute duration provided: %s") | ||
return | ||
} | ||
|
||
mute := &mutes.Mute{ | ||
Chain: chain, | ||
ProposalID: proposal, | ||
Expires: time.Now().Add(duration), | ||
Comment: fmt.Sprintf( | ||
"Muted using cosmos-proposals-checker for %s", | ||
duration, | ||
), | ||
} | ||
|
||
reporter.MutesManager.AddMute(mute) | ||
|
||
template, err := reporter.TemplatesManager.Render("mute_added", mute) | ||
if err != nil { | ||
reporter.Logger.Error().Err(err).Str("template", "mute_added").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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package discord | ||
|
||
import ( | ||
mutes "main/pkg/mutes" | ||
"time" | ||
|
||
"github.com/bwmarrin/discordgo" | ||
) | ||
|
||
func (reporter *Reporter) GetDeleteMuteCommand() *Command { | ||
return &Command{ | ||
Info: &discordgo.ApplicationCommand{ | ||
Name: "proposals_unmute", | ||
Description: "Unmute proposals' notifications", | ||
Options: []*discordgo.ApplicationCommandOption{ | ||
{ | ||
Type: discordgo.ApplicationCommandOptionString, | ||
Name: "chain", | ||
Description: "Chain to mute notifications on", | ||
Required: false, | ||
}, | ||
{ | ||
Type: discordgo.ApplicationCommandOptionString, | ||
Name: "proposal", | ||
Description: "Proposal to mute notifications on", | ||
Required: false, | ||
}, | ||
}, | ||
}, | ||
Handler: func(s *discordgo.Session, i *discordgo.InteractionCreate) { | ||
options := i.ApplicationCommandData().Options | ||
|
||
var chain string | ||
var proposal string | ||
|
||
for _, opt := range options { | ||
if opt.Name == "chain" { | ||
chain, _ = opt.Value.(string) | ||
} | ||
if opt.Name == "proposal" { | ||
proposal, _ = opt.Value.(string) | ||
} | ||
} | ||
|
||
mute := &mutes.Mute{ | ||
Chain: chain, | ||
ProposalID: proposal, | ||
Expires: time.Now(), | ||
Comment: "", | ||
} | ||
|
||
if found := reporter.MutesManager.DeleteMute(mute); !found { | ||
reporter.BotRespond(s, i, "Could not find the mute to delete!") | ||
return | ||
} | ||
|
||
template, err := reporter.TemplatesManager.Render("mute_deleted", mute) | ||
if err != nil { | ||
reporter.Logger.Error().Err(err).Str("template", "mute_deleted").Msg("Error rendering template") | ||
return | ||
} | ||
|
||
reporter.BotRespond(s, i, template) | ||
}, | ||
} | ||
} |
Oops, something went wrong.