mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 08:49:13 +00:00
feat(notifications): add LunaSea support (#1284)
* feat(notifications): add lunasea * fix(web): truncate overflow in PasswordFieldWide * refactor(notifications): centralize msg building Left the building logic in discord.go and notifiarr.go as is because of their unique structure. * refactor: moved components and swapped to outline - Refactored the iconComponentMap to use a single iconStyle variable. * upped size from 4 to 5 * rename NotificationBuilder function
This commit is contained in:
parent
da365da17c
commit
a89a1a55d9
13 changed files with 266 additions and 203 deletions
56
internal/notification/message_builder.go
Normal file
56
internal/notification/message_builder.go
Normal file
|
@ -0,0 +1,56 @@
|
|||
package notification
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/autobrr/autobrr/internal/domain"
|
||||
"github.com/dustin/go-humanize"
|
||||
)
|
||||
|
||||
type NotificationBuilderPlainText struct{}
|
||||
|
||||
// BuildBody constructs the body of the notification message.
|
||||
func (b *NotificationBuilderPlainText) BuildBody(payload domain.NotificationPayload) string {
|
||||
var parts []string
|
||||
|
||||
buildPart := func(condition bool, format string, a ...interface{}) {
|
||||
if condition {
|
||||
parts = append(parts, fmt.Sprintf(format, a...))
|
||||
}
|
||||
}
|
||||
|
||||
buildPart(payload.Subject != "" && payload.Message != "", "%v\n%v", payload.Subject, payload.Message)
|
||||
buildPart(payload.ReleaseName != "", "\nNew release: %v", payload.ReleaseName)
|
||||
buildPart(payload.Size > 0, "\nSize: %v", humanize.Bytes(payload.Size))
|
||||
buildPart(payload.Status != "", "\nStatus: %v", payload.Status.String())
|
||||
buildPart(payload.Indexer != "", "\nIndexer: %v", payload.Indexer)
|
||||
buildPart(payload.Filter != "", "\nFilter: %v", payload.Filter)
|
||||
buildPart(payload.Action != "", "\nAction: %v Type: %v", payload.Action, payload.ActionType)
|
||||
buildPart(len(payload.Rejections) > 0, "\nRejections: %v", strings.Join(payload.Rejections, ", "))
|
||||
|
||||
if payload.Action != "" && payload.ActionClient != "" {
|
||||
parts = append(parts, fmt.Sprintf(" Client: %v", payload.ActionClient))
|
||||
}
|
||||
|
||||
return strings.Join(parts, "\n")
|
||||
}
|
||||
|
||||
// BuildTitle constructs the title of the notification message.
|
||||
func (b *NotificationBuilderPlainText) BuildTitle(event domain.NotificationEvent) string {
|
||||
titles := map[domain.NotificationEvent]string{
|
||||
domain.NotificationEventAppUpdateAvailable: "Autobrr update available",
|
||||
domain.NotificationEventPushApproved: "Push Approved",
|
||||
domain.NotificationEventPushRejected: "Push Rejected",
|
||||
domain.NotificationEventPushError: "Error",
|
||||
domain.NotificationEventIRCDisconnected: "IRC Disconnected",
|
||||
domain.NotificationEventIRCReconnected: "IRC Reconnected",
|
||||
domain.NotificationEventTest: "Test",
|
||||
}
|
||||
|
||||
if title, ok := titles[event]; ok {
|
||||
return title
|
||||
}
|
||||
|
||||
return "New Event"
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue