mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 08:49:13 +00:00
fix(notifications): send error and reject events (#217)
* fix: send notifications with correct events * feat: set err color red
This commit is contained in:
parent
431742fd94
commit
2f358473f3
2 changed files with 38 additions and 12 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue