| 1 | package notifiarrscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/ |
| 2 | |
| 3 | import ( |
| 4 | "bytesscip-go gomod github.com/golang/go/src . bytes/" |
| 5 | "contextscip-go gomod github.com/golang/go/src . context/" |
| 6 | "encoding/jsonscip-go gomod github.com/golang/go/src . `encoding/json`/" |
| 7 | "errorsscip-go gomod github.com/golang/go/src . errors/" |
| 8 | "fmtscip-go gomod github.com/golang/go/src . fmt/" |
| 9 | "ioscip-go gomod github.com/golang/go/src . io/" |
| 10 | "net/httpscip-go gomod github.com/golang/go/src . `net/http`/" |
| 11 | "net/urlscip-go gomod github.com/golang/go/src . `net/url`/" |
| 12 | "regexpscip-go gomod github.com/golang/go/src . regexp/" |
| 13 | "strconvscip-go gomod github.com/golang/go/src . strconv/" |
| 14 | "stringsscip-go gomod github.com/golang/go/src . strings/" |
| 15 | "timescip-go gomod github.com/golang/go/src . time/" |
| 16 | |
| 17 | "github.com/nicholas-fedor/shoutrrr/pkg/formatscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/" |
| 18 | "github.com/nicholas-fedor/shoutrrr/pkg/services/standardscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/standard`/" |
| 19 | "github.com/nicholas-fedor/shoutrrr/pkg/typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/" |
| 20 | ) |
| 21 | |
| 22 | // Service implements a Notifiarr notification service. |
| 23 | type Servicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Service# struct { |
| 24 | standardscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/standard`/.Standardscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Service#Standard. |
| 25 | |
| 26 | Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Service#Config. *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Config# |
| 27 | pkrscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Service#pkr. formatscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/.PropKeyResolverscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/PropKeyResolver# |
| 28 | httpClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Service#httpClient. typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.HTTPClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/HTTPClient# |
| 29 | } |
| 30 | |
| 31 | // presenceFlags holds boolean flags indicating presence of Discord fields. |
| 32 | type presenceFlagsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/presenceFlags# struct { |
| 33 | channelscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/presenceFlags#channel., colorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/presenceFlags#color., thumbnailscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/presenceFlags#thumbnail., imagescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/presenceFlags#image., titlescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/presenceFlags#title., iconscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/presenceFlags#icon., contentscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/presenceFlags#content., descriptionscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/presenceFlags#description., footerscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/presenceFlags#footer., fieldsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/presenceFlags#fields., mentionsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/presenceFlags#mentions. bool |
| 34 | } |
| 35 | |
| 36 | const ( |
| 37 | // APIBaseURL is the base URL for Notifiarr API. |
| 38 | APIBaseURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/APIBaseURL. = "https://notifiarr.com/api/v1/notification/passthrough" |
| 39 | // MentionTypeNone represents no mention type. |
| 40 | MentionTypeNonescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/MentionTypeNone. = 0 |
| 41 | // MentionTypeUser represents a user mention type. |
| 42 | MentionTypeUserscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/MentionTypeUser. = 1 |
| 43 | // MentionTypeRole represents a role mention type. |
| 44 | MentionTypeRolescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/MentionTypeRole. = 2 |
| 45 | // requestTimeout is the timeout duration for HTTP requests to prevent hangs. |
| 46 | requestTimeoutscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/requestTimeout. = 30 // seconds |
| 47 | ) |
| 48 | |
| 49 | // ErrSendFailed indicates a failure to send a notification to Notifiarr. |
| 50 | var ( |
| 51 | ErrSendFailedscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/ErrSendFailed. = errorsscip-go gomod github.com/golang/go/src . errors/.Newscip-go gomod github.com/golang/go/src . errors/New().("failed to send notification to Notifiarr") |
| 52 | // ErrUnexpectedStatus indicates the server returned an unexpected response status code. |
| 53 | ErrUnexpectedStatusscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/ErrUnexpectedStatus. = errorsscip-go gomod github.com/golang/go/src . errors/.Newscip-go gomod github.com/golang/go/src . errors/New().("server returned unexpected response status code") |
| 54 | // ErrInvalidAPIKey indicates an invalid API key was provided. |
| 55 | ErrInvalidAPIKeyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/ErrInvalidAPIKey. = errorsscip-go gomod github.com/golang/go/src . errors/.Newscip-go gomod github.com/golang/go/src . errors/New().("invalid API key") |
| 56 | // ErrAuthenticationFailed indicates authentication failure (e.g., 401 response). |
| 57 | ErrAuthenticationFailedscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/ErrAuthenticationFailed. = errorsscip-go gomod github.com/golang/go/src . errors/.Newscip-go gomod github.com/golang/go/src . errors/New().("authentication failed") |
| 58 | // ErrEmptyMessage indicates the message is empty. |
| 59 | ErrEmptyMessagescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/ErrEmptyMessage. = errorsscip-go gomod github.com/golang/go/src . errors/.Newscip-go gomod github.com/golang/go/src . errors/New().("message is empty") |
| 60 | // ErrInvalidURL indicates an invalid URL format. |
| 61 | ErrInvalidURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/ErrInvalidURL. = errorsscip-go gomod github.com/golang/go/src . errors/.Newscip-go gomod github.com/golang/go/src . errors/New().("invalid URL format") |
| 62 | // ErrInvalidChannelID indicates an invalid channel ID. |
| 63 | ErrInvalidChannelIDscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/ErrInvalidChannelID. = errorsscip-go gomod github.com/golang/go/src . errors/.Newscip-go gomod github.com/golang/go/src . errors/New().("invalid channel ID") |
| 64 | // ErrNoDiscordFields indicates no Discord fields present. |
| 65 | ErrNoDiscordFieldsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/ErrNoDiscordFields. = errorsscip-go gomod github.com/golang/go/src . errors/.Newscip-go gomod github.com/golang/go/src . errors/New().("no Discord fields present") |
| 66 | ) |
| 67 | |
| 68 | // mentionRegex is a compiled regular expression for parsing Discord user/role mentions. |
| 69 | var mentionRegexscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/mentionRegex. = regexpscip-go gomod github.com/golang/go/src . regexp/.MustCompilescip-go gomod github.com/golang/go/src . regexp/MustCompile().(`<@!?(\d+)>|<@&(\d+)>`) |
| 70 | |
| 71 | // HasAny returns true if any of the boolean fields are true, false otherwise. |
| 72 | func (pf presenceFlagsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/presenceFlags#) HasAnyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/presenceFlags#HasAny().() bool { |
| 73 | return pf.channelscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/presenceFlags#channel. || pf.colorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/presenceFlags#color. || pf.thumbnailscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/presenceFlags#thumbnail. || pf.imagescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/presenceFlags#image. || pf.titlescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/presenceFlags#title. || pf.iconscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/presenceFlags#icon. || |
| 74 | pf.contentscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/presenceFlags#content. || |
| 75 | pf.descriptionscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/presenceFlags#description. || |
| 76 | pf.footerscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/presenceFlags#footer. || |
| 77 | pf.fieldsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/presenceFlags#fields. || |
| 78 | pf.mentionsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/presenceFlags#mentions. |
| 79 | } |
| 80 | |
| 81 | // ExtractPingIDs extracts user and role IDs from mention strings. |
| 82 | func (s *Servicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Service#) ExtractPingIDsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Service#ExtractPingIDs().(mentions []string) ([]int, []int) { |
| 83 | var pingUsers, pingRoles []int |
| 84 | |
| 85 | for _, mention := range mentions { |
| 86 | mentionType, id := ParseMentionscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/ParseMention().(mention) |
| 87 | switch mentionType { |
| 88 | case MentionTypeUserscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/MentionTypeUser.: |
| 89 | pingUsers = append(pingUsers, id) |
| 90 | case MentionTypeRolescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/MentionTypeRole.: |
| 91 | pingRoles = append(pingRoles, id) |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | return pingUsers, pingRoles |
| 96 | } |
| 97 | |
| 98 | // GetID returns the identifier for this service. |
| 99 | func (s *Servicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Service#) GetIDscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Service#GetID().() string { |
| 100 | return Schemescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Scheme. |
| 101 | } |
| 102 | |
| 103 | // GetServiceURLFromCustom converts a custom webhook URL into a standard service URL. |
| 104 | func (*Servicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Service#) GetServiceURLFromCustomscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Service#GetServiceURLFromCustom().(serviceURL *urlscip-go gomod github.com/golang/go/src . `net/url`/.URLscip-go gomod github.com/golang/go/src . `net/url`/URL#) (*urlscip-go gomod github.com/golang/go/src . `net/url`/.URLscip-go gomod github.com/golang/go/src . `net/url`/URL#, error) { |
| 105 | // Copy the URL to modify |
| 106 | webhookURL := *serviceURL |
| 107 | if stringsscip-go gomod github.com/golang/go/src . strings/.HasPrefixscip-go gomod github.com/golang/go/src . strings/HasPrefix().(webhookURL.Schemescip-go gomod github.com/golang/go/src . `net/url`/URL#Scheme., Schemescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Scheme.) && len(webhookURL.Schemescip-go gomod github.com/golang/go/src . `net/url`/URL#Scheme.) > len(Schemescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Scheme.) && |
| 108 | webhookURL.Schemescip-go gomod github.com/golang/go/src . `net/url`/URL#Scheme.[len(Schemescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Scheme.)] == '+' { |
| 109 | // Remove the scheme prefix if present |
| 110 | webhookURL.Schemescip-go gomod github.com/golang/go/src . `net/url`/URL#Scheme. = webhookURL.Schemescip-go gomod github.com/golang/go/src . `net/url`/URL#Scheme.[len(Schemescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Scheme.)+1:] |
| 111 | } |
| 112 | |
| 113 | // Parse config from webhook URL |
| 114 | config, pkr, err := ConfigFromWebhookURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/ConfigFromWebhookURL().(&webhookURL) |
| 115 | if err != nil { |
| 116 | return nil, err |
| 117 | } |
| 118 | |
| 119 | // Generate and return the service URL |
| 120 | return config.getURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Config#getURL().(&pkr), nil |
| 121 | } |
| 122 | |
| 123 | // Initialize configures the service with a URL and logger. |
| 124 | func (s *Servicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Service#) Initializescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Service#Initialize().(serviceURL *urlscip-go gomod github.com/golang/go/src . `net/url`/.URLscip-go gomod github.com/golang/go/src . `net/url`/URL#, logger typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.StdLoggerscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/StdLogger#) error { |
| 125 | // Set the logger for the service |
| 126 | s.SetLoggerscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/standard`/Logger#SetLogger().(logger) |
| 127 | // Initialize service config |
| 128 | s.Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Service#Config. = &Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Config#{} |
| 129 | // Initialize property key resolver |
| 130 | s.pkrscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Service#pkr. = formatscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/.NewPropKeyResolverscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/NewPropKeyResolver().(s.Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Service#Config.) |
| 131 | |
| 132 | // Set default properties |
| 133 | if err := s.pkrscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Service#pkr..SetDefaultPropsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/PropKeyResolver#SetDefaultProps().(s.Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Service#Config.); err != nil { |
| 134 | return fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("setting default properties: %w", err) |
| 135 | } |
| 136 | |
| 137 | // Set URL and return any error |
| 138 | if err := s.Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Service#Config..SetURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Config#SetURL().(serviceURL); err != nil { |
| 139 | return fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("setting config URL: %w", err) |
| 140 | } |
| 141 | |
| 142 | return nil |
| 143 | } |
| 144 | |
| 145 | // ParseChannelID parses the channel string to an integer. |
| 146 | func (s *Servicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Service#) ParseChannelIDscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Service#ParseChannelID().(channelStr string) (int, error) { |
| 147 | var channelID int |
| 148 | |
| 149 | _, err := fmtscip-go gomod github.com/golang/go/src . fmt/.Sscanfscip-go gomod github.com/golang/go/src . fmt/Sscanf().(channelStr, "%d", &channelID) |
| 150 | if err != nil { |
| 151 | return 0, fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("invalid channel ID format '%s': %w", channelStr, ErrInvalidChannelIDscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/ErrInvalidChannelID.) |
| 152 | } |
| 153 | |
| 154 | return channelID, nil |
| 155 | } |
| 156 | |
| 157 | // ParseFields parses a JSON string into a slice of Field structs. |
| 158 | func (s *Servicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Service#) ParseFieldsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Service#ParseFields().(fieldsStr string) ([]Fieldscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Field#, error) { |
| 159 | var fields []Fieldscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Field# |
| 160 | if err := jsonscip-go gomod github.com/golang/go/src . `encoding/json`/.Unmarshalscip-go gomod github.com/golang/go/src . `encoding/json`/Unmarshal().([]byte(fieldsStr), &fields); err != nil { |
| 161 | return nil, fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("unmarshaling fields JSON: %w", err) |
| 162 | } |
| 163 | |
| 164 | return fields, nil |
| 165 | } |
| 166 | |
| 167 | // ParseMentions extracts Discord user and role mentions from the message content. |
| 168 | func (s *Servicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Service#) ParseMentionsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Service#ParseMentions().(message string) []string { |
| 169 | var mentions []string |
| 170 | |
| 171 | matches := mentionRegexscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/mentionRegex..FindAllStringSubmatchscip-go gomod github.com/golang/go/src . regexp/Regexp#FindAllStringSubmatch().(message, -1) |
| 172 | for _, match := range matches { |
| 173 | if match[1] != "" { |
| 174 | mentions = append(mentions, fmtscip-go gomod github.com/golang/go/src . fmt/.Sprintfscip-go gomod github.com/golang/go/src . fmt/Sprintf().("<@%s>", match[1])) |
| 175 | } else if match[2] != "" { |
| 176 | mentions = append(mentions, fmtscip-go gomod github.com/golang/go/src . fmt/.Sprintfscip-go gomod github.com/golang/go/src . fmt/Sprintf().("<@&%s>", match[2])) |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | return mentions |
| 181 | } |
| 182 | |
| 183 | // Send delivers a notification message to Notifiarr. |
| 184 | func (s *Servicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Service#) Sendscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Service#Send().(message string, paramsPtr *typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.Paramsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/Params#) error { |
| 185 | // Check for empty message |
| 186 | if message == "" { |
| 187 | return ErrEmptyMessagescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/ErrEmptyMessage. |
| 188 | } |
| 189 | |
| 190 | // Create a copy of the config to avoid modifying the original |
| 191 | config := *s.Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Service#Config. |
| 192 | |
| 193 | var params typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.Paramsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/Params# |
| 194 | // Handle nil params by creating empty map |
| 195 | if paramsPtr == nil { |
| 196 | params = typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.Paramsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/Params#{} |
| 197 | } else { |
| 198 | params = *paramsPtr |
| 199 | } |
| 200 | |
| 201 | // Filter params to only include valid config keys for config updates |
| 202 | validConfigKeys := map[string]bool{ |
| 203 | "name": true, |
| 204 | "channel": true, |
| 205 | "color": true, |
| 206 | "thumbnail": true, |
| 207 | "image": true, |
| 208 | } |
| 209 | filteredParams := typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.Paramsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/Params#{} |
| 210 | |
| 211 | for k, v := range params { |
| 212 | if validConfigKeys[k] { |
| 213 | filteredParams[k] = v |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | // Update config with filtered parameters |
| 218 | if err := s.pkrscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Service#pkr..UpdateConfigFromParamsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/PropKeyResolver#UpdateConfigFromParams().(&config, &filteredParams); err != nil { |
| 219 | s.Logfscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/standard`/Logger#Logf().("Failed to update params: %v", err) |
| 220 | } |
| 221 | |
| 222 | // Create the payload |
| 223 | payload, err := s.createPayloadscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Service#createPayload().(message, params, &config) |
| 224 | if err != nil { |
| 225 | return fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("creating payload: %w", err) |
| 226 | } |
| 227 | |
| 228 | // Send the notification |
| 229 | if err := s.doSendscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Service#doSend().(payload); err != nil { |
| 230 | return fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("%w: %s", ErrSendFailedscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/ErrSendFailed., err.Error()) |
| 231 | } |
| 232 | |
| 233 | return nil |
| 234 | } |
| 235 | |
| 236 | // SetHTTPClient sets a custom HTTP client for the service. |
| 237 | func (s *Servicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Service#) SetHTTPClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Service#SetHTTPClient().(client typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.HTTPClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/HTTPClient#) { |
| 238 | if client == nil { |
| 239 | s.httpClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Service#httpClient. = nil |
| 240 | |
| 241 | return |
| 242 | } |
| 243 | |
| 244 | if c, ok := client.(*httpscip-go gomod github.com/golang/go/src . `net/http`/.Clientscip-go gomod github.com/golang/go/src . `net/http`/Client#); ok && c == nil { |
| 245 | s.httpClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Service#httpClient. = nil |
| 246 | |
| 247 | return |
| 248 | } |
| 249 | |
| 250 | s.httpClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Service#httpClient. = client |
| 251 | } |
| 252 | |
| 253 | // buildDiscordPayload constructs the Discord payload if any fields are present. |
| 254 | func (s *Servicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Service#) buildDiscordPayloadscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Service#buildDiscordPayload().( |
| 255 | flags presenceFlagsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/presenceFlags#, |
| 256 | message string, |
| 257 | params typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.Paramsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/Params#, |
| 258 | config *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Config#, |
| 259 | ) (*DiscordPayloadscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/DiscordPayload#, error) { |
| 260 | if !flags.HasAnyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/presenceFlags#HasAny().() { |
| 261 | return nil, ErrNoDiscordFieldsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/ErrNoDiscordFields. |
| 262 | } |
| 263 | |
| 264 | discord := &DiscordPayloadscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/DiscordPayload#{} |
| 265 | |
| 266 | if flags.channelscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/presenceFlags#channel. { |
| 267 | // Parse channel ID from config string to integer |
| 268 | channelID, err := s.ParseChannelIDscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Service#ParseChannelID().(config.Channelscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Config#Channel.) |
| 269 | if err != nil { |
| 270 | return nil, fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("parsing channel ID: %w", err) |
| 271 | } |
| 272 | |
| 273 | discord.IDsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/DiscordPayload#IDs. = &IDPayloadscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/IDPayload#{Channelscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/IDPayload#Channel.: channelID} |
| 274 | } |
| 275 | |
| 276 | if flags.colorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/presenceFlags#color. { |
| 277 | // Assign color from config |
| 278 | discord.Colorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/DiscordPayload#Color. = config.Colorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Config#Color. |
| 279 | } |
| 280 | |
| 281 | if flags.thumbnailscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/presenceFlags#thumbnail. || flags.imagescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/presenceFlags#image. { |
| 282 | // Set thumbnail and image URLs from config |
| 283 | discord.Imagesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/DiscordPayload#Images. = &ImagePayloadscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/ImagePayload#{ |
| 284 | Thumbnailscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/ImagePayload#Thumbnail.: config.Thumbnailscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Config#Thumbnail., |
| 285 | Imagescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/ImagePayload#Image.: config.Imagescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Config#Image., |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | // Construct text payload with title, icon, content, description, and footer from params |
| 290 | textPayload := &TextPayloadscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/TextPayload#{ |
| 291 | Titlescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/TextPayload#Title.: params[typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.TitleKeyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/TitleKey.], |
| 292 | Iconscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/TextPayload#Icon.: params["icon"], |
| 293 | Contentscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/TextPayload#Content.: params["content"], |
| 294 | Descriptionscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/TextPayload#Description.: message, |
| 295 | Footerscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/TextPayload#Footer.: params["footer"], |
| 296 | } |
| 297 | |
| 298 | if flags.fieldsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/presenceFlags#fields. { |
| 299 | // Parse JSON fields string into Field structs |
| 300 | fields, err := s.ParseFieldsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Service#ParseFields().(params["fields"]) |
| 301 | if err != nil { |
| 302 | return nil, fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("parsing fields: %w", err) |
| 303 | } |
| 304 | |
| 305 | textPayload.Fieldsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/TextPayload#Fields. = fields |
| 306 | } |
| 307 | |
| 308 | discord.Textscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/DiscordPayload#Text. = textPayload |
| 309 | |
| 310 | if flags.mentionsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/presenceFlags#mentions. { |
| 311 | // Extract Discord mentions from message content |
| 312 | mentions := s.ParseMentionsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Service#ParseMentions().(message) |
| 313 | |
| 314 | // Extract user and role IDs for ping setup (collects all mentions) |
| 315 | pingUsers, pingRoles := s.ExtractPingIDsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Service#ExtractPingIDs().(mentions) |
| 316 | if len(pingUsers) > 0 || len(pingRoles) > 0 { |
| 317 | pingPayload := &PingPayloadscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/PingPayload#{} |
| 318 | if len(pingUsers) > 0 { |
| 319 | pingPayload.PingUserscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/PingPayload#PingUser. = &pingUsers[0] // Use first user mention |
| 320 | } |
| 321 | |
| 322 | if len(pingRoles) > 0 { |
| 323 | pingPayload.PingRolescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/PingPayload#PingRole. = &pingRoles[0] // Use first role mention |
| 324 | } |
| 325 | |
| 326 | discord.Pingscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/DiscordPayload#Ping. = pingPayload |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | return discord, nil |
| 331 | } |
| 332 | |
| 333 | // createPayload creates the JSON payload for Notifiarr API. |
| 334 | func (s *Servicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Service#) createPayloadscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Service#createPayload().( |
| 335 | message string, |
| 336 | params typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.Paramsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/Params#, |
| 337 | config *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Config#, |
| 338 | ) ([]byte, error) { |
| 339 | // Parse the update parameter from params |
| 340 | updatePtr := ParseUpdateFlagscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/ParseUpdateFlag().(params) |
| 341 | // Build the notification data structure |
| 342 | notificationData := buildNotificationDatascip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/buildNotificationData().(updatePtr, config, params) |
| 343 | // Check presence flags for Discord fields |
| 344 | flags := checkPresenceFlagsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/checkPresenceFlags().(message, params, config, s) |
| 345 | |
| 346 | // Build the Discord payload if fields are present |
| 347 | discord, err := s.buildDiscordPayloadscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Service#buildDiscordPayload().(flags, message, params, config) |
| 348 | if err != nil { |
| 349 | return nil, err |
| 350 | } |
| 351 | |
| 352 | notification := NotificationPayloadscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/NotificationPayload#{ |
| 353 | Notificationscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/NotificationPayload#Notification.: notificationData, |
| 354 | Discordscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/NotificationPayload#Discord.: discord, |
| 355 | } |
| 356 | |
| 357 | // Marshal the notification to JSON |
| 358 | payloadBytes, err := jsonscip-go gomod github.com/golang/go/src . `encoding/json`/.Marshalscip-go gomod github.com/golang/go/src . `encoding/json`/Marshal().(notification) |
| 359 | if err != nil { |
| 360 | return nil, fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("marshaling payload to JSON: %w", err) |
| 361 | } |
| 362 | |
| 363 | return payloadBytes, nil |
| 364 | } |
| 365 | |
| 366 | // doSend executes the HTTP request to send a notification to Notifiarr. |
| 367 | // It includes a timeout to prevent hangs and differentiates between authentication failures and other errors. |
| 368 | func (s *Servicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Service#) doSendscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Service#doSend().(payload []byte) error { |
| 369 | // Build the API URL with API key |
| 370 | apiURL := fmtscip-go gomod github.com/golang/go/src . fmt/.Sprintfscip-go gomod github.com/golang/go/src . fmt/Sprintf().("%s/%s", APIBaseURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/APIBaseURL., s.Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Service#Config..APIKeyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Config#APIKey.) |
| 371 | |
| 372 | // Create context with timeout to prevent request hangs |
| 373 | ctx, cancel := contextscip-go gomod github.com/golang/go/src . context/.WithTimeoutscip-go gomod github.com/golang/go/src . context/WithTimeout().( |
| 374 | contextscip-go gomod github.com/golang/go/src . context/.Backgroundscip-go gomod github.com/golang/go/src . context/Background().(), |
| 375 | timescip-go gomod github.com/golang/go/src . time/.Durationscip-go gomod github.com/golang/go/src . time/Duration#(requestTimeoutscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/requestTimeout.)*timescip-go gomod github.com/golang/go/src . time/.Secondscip-go gomod github.com/golang/go/src . time/Second., |
| 376 | ) |
| 377 | defer cancel() |
| 378 | |
| 379 | // Create HTTP request with context and timeout |
| 380 | req, err := httpscip-go gomod github.com/golang/go/src . `net/http`/.NewRequestWithContextscip-go gomod github.com/golang/go/src . `net/http`/NewRequestWithContext().(ctx, httpscip-go gomod github.com/golang/go/src . `net/http`/.MethodPostscip-go gomod github.com/golang/go/src . `net/http`/MethodPost., apiURL, bytesscip-go gomod github.com/golang/go/src . bytes/.NewBufferscip-go gomod github.com/golang/go/src . bytes/NewBuffer().(payload)) |
| 381 | if err != nil { |
| 382 | return fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("creating HTTP request: %w", err) |
| 383 | } |
| 384 | |
| 385 | // Set headers |
| 386 | req.Headerscip-go gomod github.com/golang/go/src . `net/http`/Request#Header..Setscip-go gomod github.com/golang/go/src . `net/http`/Header#Set().("Content-Type", "application/json") |
| 387 | req.Headerscip-go gomod github.com/golang/go/src . `net/http`/Request#Header..Setscip-go gomod github.com/golang/go/src . `net/http`/Header#Set().("Accept", "application/json") |
| 388 | |
| 389 | client := s.httpClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Service#httpClient. |
| 390 | if client == nil { |
| 391 | client = &httpscip-go gomod github.com/golang/go/src . `net/http`/.Clientscip-go gomod github.com/golang/go/src . `net/http`/Client#{} |
| 392 | } |
| 393 | |
| 394 | res, err := client.Doscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/HTTPClient#Do.(req) |
| 395 | if err != nil { |
| 396 | return fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("sending HTTP request: %w", err) |
| 397 | } |
| 398 | |
| 399 | if res != nil && res.Bodyscip-go gomod github.com/golang/go/src . `net/http`/Response#Body. != nil { |
| 400 | defer func() { |
| 401 | _ = res.Bodyscip-go gomod github.com/golang/go/src . `net/http`/Response#Body..Closescip-go gomod github.com/golang/go/src . io/Closer#Close().() |
| 402 | }() |
| 403 | |
| 404 | if body, err := ioscip-go gomod github.com/golang/go/src . io/.ReadAllscip-go gomod github.com/golang/go/src . io/ReadAll().(res.Bodyscip-go gomod github.com/golang/go/src . `net/http`/Response#Body.); err == nil { |
| 405 | s.Logscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/standard`/Logger#Log().("Server response: ", string(body)) |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | // Check for authentication failure (401 Unauthorized) |
| 410 | if res.StatusCodescip-go gomod github.com/golang/go/src . `net/http`/Response#StatusCode. == httpscip-go gomod github.com/golang/go/src . `net/http`/.StatusUnauthorizedscip-go gomod github.com/golang/go/src . `net/http`/StatusUnauthorized. { |
| 411 | return ErrAuthenticationFailedscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/ErrAuthenticationFailed. |
| 412 | } |
| 413 | |
| 414 | // Check for other unexpected status codes |
| 415 | if res.StatusCodescip-go gomod github.com/golang/go/src . `net/http`/Response#StatusCode. < 200 || res.StatusCodescip-go gomod github.com/golang/go/src . `net/http`/Response#StatusCode. >= 300 { |
| 416 | return fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("%w: %s", ErrUnexpectedStatusscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/ErrUnexpectedStatus., res.Statusscip-go gomod github.com/golang/go/src . `net/http`/Response#Status.) |
| 417 | } |
| 418 | |
| 419 | return nil |
| 420 | } |
| 421 | |
| 422 | // ParseMention parses a single mention string and returns the type (0=none, 1=user, 2=role) and ID if valid. |
| 423 | func ParseMentionscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/ParseMention().(mention string) (int, int) { |
| 424 | if !stringsscip-go gomod github.com/golang/go/src . strings/.HasPrefixscip-go gomod github.com/golang/go/src . strings/HasPrefix().(mention, "<@") || !stringsscip-go gomod github.com/golang/go/src . strings/.HasSuffixscip-go gomod github.com/golang/go/src . strings/HasSuffix().(mention, ">") { |
| 425 | return MentionTypeNonescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/MentionTypeNone., 0 |
| 426 | } |
| 427 | |
| 428 | idStr := mention[2 : len(mention)-1] |
| 429 | if stringsscip-go gomod github.com/golang/go/src . strings/.HasPrefixscip-go gomod github.com/golang/go/src . strings/HasPrefix().(idStr, "&") { |
| 430 | roleIDStr := idStr[1:] |
| 431 | if roleID, err := strconvscip-go gomod github.com/golang/go/src . strconv/.Atoiscip-go gomod github.com/golang/go/src . strconv/Atoi().(roleIDStr); err == nil { |
| 432 | return MentionTypeRolescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/MentionTypeRole., roleID |
| 433 | } |
| 434 | } else { |
| 435 | // Handle user mentions, which may have a "!" prefix for nicknames |
| 436 | userIDStr := stringsscip-go gomod github.com/golang/go/src . strings/.TrimPrefixscip-go gomod github.com/golang/go/src . strings/TrimPrefix().(idStr, "!") |
| 437 | |
| 438 | if userID, err := strconvscip-go gomod github.com/golang/go/src . strconv/.Atoiscip-go gomod github.com/golang/go/src . strconv/Atoi().(userIDStr); err == nil { |
| 439 | return MentionTypeUserscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/MentionTypeUser., userID |
| 440 | } |
| 441 | } |
| 442 | |
| 443 | return MentionTypeNonescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/MentionTypeNone., 0 |
| 444 | } |
| 445 | |
| 446 | // ParseUpdateFlag parses the update parameter from params. |
| 447 | func ParseUpdateFlagscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/ParseUpdateFlag().(params typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.Paramsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/Params#) *bool { |
| 448 | if updateStr, exists := params["update"]; exists && updateStr != "" { |
| 449 | switch updateStr { |
| 450 | case "true": |
| 451 | return &[]bool{true}[0] |
| 452 | case "false": |
| 453 | return &[]bool{false}[0] |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | return nil |
| 458 | } |
| 459 | |
| 460 | // buildNotificationData creates the notification data structure. |
| 461 | func buildNotificationDatascip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/buildNotificationData().(updatePtr *bool, config *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Config#, params typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.Paramsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/Params#) NotificationDatascip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/NotificationData# { |
| 462 | return NotificationDatascip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/NotificationData#{ |
| 463 | Updatescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/NotificationData#Update.: updatePtr, |
| 464 | Namescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/NotificationData#Name.: config.Namescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Config#Name., |
| 465 | Eventscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/NotificationData#Event.: params["id"], |
| 466 | } |
| 467 | } |
| 468 | |
| 469 | // checkPresenceFlags determines which Discord fields are present. |
| 470 | func checkPresenceFlagsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/checkPresenceFlags().( |
| 471 | message string, |
| 472 | params typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.Paramsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/Params#, |
| 473 | config *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Config#, |
| 474 | service *Servicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Service#, |
| 475 | ) presenceFlagsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/presenceFlags# { |
| 476 | return presenceFlagsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/presenceFlags#{ |
| 477 | channelscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/presenceFlags#channel.: config.Channelscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Config#Channel. != "", |
| 478 | colorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/presenceFlags#color.: config.Colorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Config#Color. != "", |
| 479 | thumbnailscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/presenceFlags#thumbnail.: config.Thumbnailscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Config#Thumbnail. != "", |
| 480 | imagescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/presenceFlags#image.: config.Imagescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Config#Image. != "", |
| 481 | titlescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/presenceFlags#title.: params[typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.TitleKeyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/TitleKey.] != "", |
| 482 | iconscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/presenceFlags#icon.: params["icon"] != "", |
| 483 | contentscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/presenceFlags#content.: params["content"] != "", |
| 484 | descriptionscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/presenceFlags#description.: message != "", |
| 485 | footerscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/presenceFlags#footer.: params["footer"] != "", |
| 486 | fieldsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/presenceFlags#fields.: params["fields"] != "", |
| 487 | mentionsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/presenceFlags#mentions.: len(service.ParseMentionsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/specialized/notifiarr`/Service#ParseMentions().(message)) > 0, |
| 488 | } |
| 489 | } |