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()},
|
Rejections: []string{err.Error()},
|
||||||
Timestamp: time.Now(),
|
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(),
|
Timestamp: time.Now(),
|
||||||
}
|
}
|
||||||
|
|
||||||
if rejections != nil {
|
notificationEvent := &domain.EventsReleasePushed{
|
||||||
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{
|
|
||||||
ReleaseName: release.TorrentName,
|
ReleaseName: release.TorrentName,
|
||||||
Filter: release.Filter.Name,
|
Filter: release.Filter.Name,
|
||||||
Indexer: release.Indexer,
|
Indexer: release.Indexer,
|
||||||
|
@ -188,7 +194,21 @@ func (s *service) runAction(action domain.Action, release domain.Release) error
|
||||||
Protocol: domain.ReleaseProtocolTorrent,
|
Protocol: domain.ReleaseProtocolTorrent,
|
||||||
Implementation: domain.ReleaseImplementationIRC,
|
Implementation: domain.ReleaseImplementationIRC,
|
||||||
Timestamp: time.Now(),
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,13 +40,19 @@ func discordNotification(event domain.EventsReleasePushed, webhookURL string) {
|
||||||
|
|
||||||
client := http.Client{Transport: t, Timeout: 15 * time.Second}
|
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{
|
m := DiscordMessage{
|
||||||
Content: nil,
|
Content: nil,
|
||||||
Embeds: []DiscordEmbeds{
|
Embeds: []DiscordEmbeds{
|
||||||
{
|
{
|
||||||
Title: event.ReleaseName,
|
Title: event.ReleaseName,
|
||||||
Description: "New release!",
|
Description: "New release!",
|
||||||
Color: 5814783,
|
Color: color[event.Status],
|
||||||
Fields: []DiscordEmbedsFields{
|
Fields: []DiscordEmbedsFields{
|
||||||
{
|
{
|
||||||
Name: "Status",
|
Name: "Status",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue