Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add discord reporter #95

Merged
merged 8 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ toolchain go1.22.1
require (
cosmossdk.io/math v1.0.1
github.com/BurntSushi/toml v1.1.0
github.com/bwmarrin/discordgo v0.28.1
github.com/creasty/defaults v1.7.0
github.com/guregu/null/v5 v5.0.0
github.com/robfig/cron/v3 v3.0.1
Expand All @@ -27,13 +28,15 @@ require (
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.26.0 // indirect
go.opentelemetry.io/otel/metric v1.26.0 // indirect
go.opentelemetry.io/proto/otlp v1.2.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/exp v0.0.0-20221205204356-47842c84f3db // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/sys v0.19.0 // indirect
Expand Down
7 changes: 7 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ cosmossdk.io/math v1.0.1 h1:Qx3ifyOPaMLNH/89WeZFH268yCvU4xEcnPLu3sJqPPg=
cosmossdk.io/math v1.0.1/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k=
github.com/BurntSushi/toml v1.1.0 h1:ksErzDEI1khOiGPgpwuI7x2ebx/uXQNw7xJpn9Eq1+I=
github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/bwmarrin/discordgo v0.28.1 h1:gXsuo2GBO7NbR6uqmrrBDplPUx2T3nzu775q/Rd1aG4=
github.com/bwmarrin/discordgo v0.28.1/go.mod h1:NJZpH+1AfhIcyQsPeuBKsUtYrRnjkyu0kIVMCHkZtRY=
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
Expand All @@ -28,6 +30,8 @@ github.com/goccy/go-yaml v1.9.5/go.mod h1:U/jl18uSupI5rdI2jmuCswEA2htH9eXfferR3K
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 h1:/c3QmbOGMGTOumP2iT/rCwB7b0QDGLKzqOmktBjT+Is=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1/go.mod h1:5SN9VR2LTsRFsrEC6FHgRbTWrTHu6tqPeKxEQv15giM=
github.com/guregu/null/v5 v5.0.0 h1:PRxjqyOekS11W+w/7Vfz6jgJE/BCwELWtgvOJzddimw=
Expand Down Expand Up @@ -86,7 +90,10 @@ go.opentelemetry.io/proto/otlp v1.2.0/go.mod h1:gGpR8txAl5M03pDhMC79G6SdqNV26naR
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
golang.org/x/crypto v0.0.0-20211215165025-cf75a172585e/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
golang.org/x/exp v0.0.0-20221205204356-47842c84f3db h1:D/cFflL63o2KSLJIwjlcIt8PR064j/xsmdEJL/YvY/o=
golang.org/x/exp v0.0.0-20221205204356-47842c84f3db/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
Expand Down
12 changes: 12 additions & 0 deletions pkg/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
mutes "main/pkg/mutes"
"main/pkg/report"
reportersPkg "main/pkg/reporters"
"main/pkg/reporters/discord"
"main/pkg/reporters/pagerduty"
"main/pkg/reporters/telegram"
"main/pkg/state"
Expand Down Expand Up @@ -73,6 +74,17 @@
timeZone,
tracer,
),
discord.NewReporter(
config,
version,
log,
stateManager,
mutesManager,
dataManager,
stateGenerator,
timeZone,
tracer,
),

Check warning on line 87 in pkg/app.go

View check run for this annotation

Codecov / codecov/patch

pkg/app.go#L77-L87

Added lines #L77 - L87 were not covered by tests
}

reportDispatcher := report.NewDispatcher(log, mutesManager, reporters, tracer)
Expand Down
82 changes: 82 additions & 0 deletions pkg/reporters/discord/add_mute.go
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{

Check warning on line 16 in pkg/reporters/discord/add_mute.go

View check run for this annotation

Codecov / codecov/patch

pkg/reporters/discord/add_mute.go#L11-L16

Added lines #L11 - L16 were not covered by tests
{
Type: discordgo.ApplicationCommandOptionString,
Name: "duration",
Description: "For how long to mute notifications",
Required: true,
},

Check warning on line 22 in pkg/reporters/discord/add_mute.go

View check run for this annotation

Codecov / codecov/patch

pkg/reporters/discord/add_mute.go#L18-L22

Added lines #L18 - L22 were not covered by tests
{
Type: discordgo.ApplicationCommandOptionString,
Name: "chain",
Description: "Chain to mute notifications on",
Required: false,
},

Check warning on line 28 in pkg/reporters/discord/add_mute.go

View check run for this annotation

Codecov / codecov/patch

pkg/reporters/discord/add_mute.go#L24-L28

Added lines #L24 - L28 were not covered by tests
{
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

Check warning on line 38 in pkg/reporters/discord/add_mute.go

View check run for this annotation

Codecov / codecov/patch

pkg/reporters/discord/add_mute.go#L30-L38

Added lines #L30 - L38 were not covered by tests

durationString, _ := options[0].Value.(string)
var chain string
var proposal string

Check warning on line 42 in pkg/reporters/discord/add_mute.go

View check run for this annotation

Codecov / codecov/patch

pkg/reporters/discord/add_mute.go#L40-L42

Added lines #L40 - L42 were not covered by tests

_, opts := options[0], options[1:]

Check warning on line 44 in pkg/reporters/discord/add_mute.go

View check run for this annotation

Codecov / codecov/patch

pkg/reporters/discord/add_mute.go#L44

Added line #L44 was not covered by tests

for _, opt := range opts {
if opt.Name == "chain" {
chain, _ = opt.Value.(string)

Check warning on line 48 in pkg/reporters/discord/add_mute.go

View check run for this annotation

Codecov / codecov/patch

pkg/reporters/discord/add_mute.go#L46-L48

Added lines #L46 - L48 were not covered by tests
}
if opt.Name == "proposal" {
proposal, _ = opt.Value.(string)

Check warning on line 51 in pkg/reporters/discord/add_mute.go

View check run for this annotation

Codecov / codecov/patch

pkg/reporters/discord/add_mute.go#L50-L51

Added lines #L50 - L51 were not covered by tests
}
}

duration, err := time.ParseDuration(durationString)
if err != nil {
reporter.BotRespond(s, i, "Invalid mute duration provided: %s")
return

Check warning on line 58 in pkg/reporters/discord/add_mute.go

View check run for this annotation

Codecov / codecov/patch

pkg/reporters/discord/add_mute.go#L55-L58

Added lines #L55 - L58 were not covered by tests
}

mute := &mutes.Mute{
Chain: chain,
ProposalID: proposal,
Expires: time.Now().Add(duration),
Comment: fmt.Sprintf(
"Muted using cosmos-proposals-checker for %s",
duration,
),

Check warning on line 68 in pkg/reporters/discord/add_mute.go

View check run for this annotation

Codecov / codecov/patch

pkg/reporters/discord/add_mute.go#L61-L68

Added lines #L61 - L68 were not covered by tests
}

reporter.MutesManager.AddMute(mute)

Check warning on line 71 in pkg/reporters/discord/add_mute.go

View check run for this annotation

Codecov / codecov/patch

pkg/reporters/discord/add_mute.go#L71

Added line #L71 was not covered by tests

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

Check warning on line 76 in pkg/reporters/discord/add_mute.go

View check run for this annotation

Codecov / codecov/patch

pkg/reporters/discord/add_mute.go#L73-L76

Added lines #L73 - L76 were not covered by tests
}

reporter.BotRespond(s, i, template)

Check warning on line 79 in pkg/reporters/discord/add_mute.go

View check run for this annotation

Codecov / codecov/patch

pkg/reporters/discord/add_mute.go#L79

Added line #L79 was not covered by tests
},
}
}
66 changes: 66 additions & 0 deletions pkg/reporters/discord/delete_mute.go
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{

Check warning on line 15 in pkg/reporters/discord/delete_mute.go

View check run for this annotation

Codecov / codecov/patch

pkg/reporters/discord/delete_mute.go#L10-L15

Added lines #L10 - L15 were not covered by tests
{
Type: discordgo.ApplicationCommandOptionString,
Name: "chain",
Description: "Chain to mute notifications on",
Required: false,
},

Check warning on line 21 in pkg/reporters/discord/delete_mute.go

View check run for this annotation

Codecov / codecov/patch

pkg/reporters/discord/delete_mute.go#L17-L21

Added lines #L17 - L21 were not covered by tests
{
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

Check warning on line 31 in pkg/reporters/discord/delete_mute.go

View check run for this annotation

Codecov / codecov/patch

pkg/reporters/discord/delete_mute.go#L23-L31

Added lines #L23 - L31 were not covered by tests

var chain string
var proposal string

Check warning on line 34 in pkg/reporters/discord/delete_mute.go

View check run for this annotation

Codecov / codecov/patch

pkg/reporters/discord/delete_mute.go#L33-L34

Added lines #L33 - L34 were not covered by tests

for _, opt := range options {
if opt.Name == "chain" {
chain, _ = opt.Value.(string)

Check warning on line 38 in pkg/reporters/discord/delete_mute.go

View check run for this annotation

Codecov / codecov/patch

pkg/reporters/discord/delete_mute.go#L36-L38

Added lines #L36 - L38 were not covered by tests
}
if opt.Name == "proposal" {
proposal, _ = opt.Value.(string)

Check warning on line 41 in pkg/reporters/discord/delete_mute.go

View check run for this annotation

Codecov / codecov/patch

pkg/reporters/discord/delete_mute.go#L40-L41

Added lines #L40 - L41 were not covered by tests
}
}

mute := &mutes.Mute{
Chain: chain,
ProposalID: proposal,
Expires: time.Now(),
Comment: "",

Check warning on line 49 in pkg/reporters/discord/delete_mute.go

View check run for this annotation

Codecov / codecov/patch

pkg/reporters/discord/delete_mute.go#L45-L49

Added lines #L45 - L49 were not covered by tests
}

if found := reporter.MutesManager.DeleteMute(mute); !found {
reporter.BotRespond(s, i, "Could not find the mute to delete!")
return

Check warning on line 54 in pkg/reporters/discord/delete_mute.go

View check run for this annotation

Codecov / codecov/patch

pkg/reporters/discord/delete_mute.go#L52-L54

Added lines #L52 - L54 were not covered by tests
}

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

Check warning on line 60 in pkg/reporters/discord/delete_mute.go

View check run for this annotation

Codecov / codecov/patch

pkg/reporters/discord/delete_mute.go#L57-L60

Added lines #L57 - L60 were not covered by tests
}

reporter.BotRespond(s, i, template)

Check warning on line 63 in pkg/reporters/discord/delete_mute.go

View check run for this annotation

Codecov / codecov/patch

pkg/reporters/discord/delete_mute.go#L63

Added line #L63 was not covered by tests
},
}
}
Loading
Loading