From 2f358473f330ca3e0549ff07be73ecd39d70c54a Mon Sep 17 00:00:00 2001 From: Ludvig Lundgren Date: Tue, 5 Apr 2022 19:18:00 +0200 Subject: [PATCH] fix(notifications): send error and reject events (#217) * fix: send notifications with correct events * feat: set err color red --- internal/action/run.go | 42 +++++++++++++++++++++++--------- internal/notification/discord.go | 8 +++++- 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/internal/action/run.go b/internal/action/run.go index 2b664ed..0dc17db 100644 --- a/internal/action/run.go +++ b/internal/action/run.go @@ -36,6 +36,21 @@ func (s *service) RunActions(actions []domain.Action, release domain.Release) er Rejections: []string{err.Error()}, Timestamp: time.Now(), }) + + s.bus.Publish("events:release:push", &domain.EventsReleasePushed{ + ReleaseName: release.TorrentName, + Filter: release.Filter.Name, + Indexer: release.Indexer, + InfoHash: release.TorrentHash, + Size: release.Size, + Status: domain.ReleasePushStatusErr, + Action: action.Name, + ActionType: action.Type, + Rejections: []string{err.Error()}, + Protocol: domain.ReleaseProtocolTorrent, + Implementation: domain.ReleaseImplementationIRC, + Timestamp: time.Now(), + }) } } @@ -166,16 +181,7 @@ func (s *service) runAction(action domain.Action, release domain.Release) error Timestamp: time.Now(), } - if rejections != nil { - rlsActionStatus.Status = domain.ReleasePushStatusRejected - rlsActionStatus.Rejections = rejections - } - - // send event for actions - s.bus.Publish("release:push", rlsActionStatus) - - // send separate event for notifications - s.bus.Publish("events:release:push", &domain.EventsReleasePushed{ + notificationEvent := &domain.EventsReleasePushed{ ReleaseName: release.TorrentName, Filter: release.Filter.Name, Indexer: release.Indexer, @@ -188,7 +194,21 @@ func (s *service) runAction(action domain.Action, release domain.Release) error Protocol: domain.ReleaseProtocolTorrent, Implementation: domain.ReleaseImplementationIRC, Timestamp: time.Now(), - }) + } + + if rejections != nil { + rlsActionStatus.Status = domain.ReleasePushStatusRejected + rlsActionStatus.Rejections = rejections + + notificationEvent.Status = domain.ReleasePushStatusRejected + notificationEvent.Rejections = rejections + } + + // send event for actions + s.bus.Publish("release:push", rlsActionStatus) + + // send separate event for notifications + s.bus.Publish("events:release:push", notificationEvent) return nil } diff --git a/internal/notification/discord.go b/internal/notification/discord.go index 91ca443..18cbdc4 100644 --- a/internal/notification/discord.go +++ b/internal/notification/discord.go @@ -40,13 +40,19 @@ func discordNotification(event domain.EventsReleasePushed, webhookURL string) { client := http.Client{Transport: t, Timeout: 15 * time.Second} + color := map[domain.ReleasePushStatus]int{ + domain.ReleasePushStatusApproved: 5814783, + domain.ReleasePushStatusRejected: 5814783, + domain.ReleasePushStatusErr: 14026000, + } + m := DiscordMessage{ Content: nil, Embeds: []DiscordEmbeds{ { Title: event.ReleaseName, Description: "New release!", - Color: 5814783, + Color: color[event.Status], Fields: []DiscordEmbedsFields{ { Name: "Status",