Skip to content

Commit

Permalink
feat: discord notifications (#126)
Browse files Browse the repository at this point in the history
* feat: basic notification support with shoutrrr

* feat(notifications): change notifications to use discord

* chore(notifications): remove leftover services

* chore(notifications): apply suggested changes
  • Loading branch information
nuxencs authored Aug 21, 2024
1 parent 52e1de6 commit 6f9b6fd
Show file tree
Hide file tree
Showing 11 changed files with 439 additions and 96 deletions.
6 changes: 5 additions & 1 deletion cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"seasonpackarr/internal/config"
"seasonpackarr/internal/http"
"seasonpackarr/internal/logger"
"seasonpackarr/internal/notification"
"seasonpackarr/pkg/errors"

"github.com/spf13/cobra"
Expand All @@ -36,7 +37,10 @@ var startCmd = &cobra.Command{
// init dynamic config
cfg.DynamicReload(log)

srv := http.NewServer(log, cfg)
// init notification sender
noti := notification.NewDiscordSender(log, cfg)

srv := http.NewServer(log, cfg, noti)

log.Info().Msgf("Starting seasonpackarr")
log.Info().Msgf("Version: %s", buildinfo.Version)
Expand Down
13 changes: 12 additions & 1 deletion config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,15 @@ fuzzyMatching:
#
# Optional
#
# apiToken: ""
# apiToken: ""

# Notifications
# You can decide which notifications you want to receive
#
notifications:
# Discord
# Uses the given Discord webhook to send notifications for various events
#
# Optional
#
discord: ""
22 changes: 21 additions & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,17 @@ fuzzyMatching:
# Optional
#
# apiToken: ""
# Notifications
# You can decide which notifications you want to receive
#
notifications:
# Discord
# Uses the given Discord webhook to send notifications for various events
#
# Optional
#
discord: ""
`

func (c *AppConfig) writeConfig(configPath string, configFile string) error {
Expand Down Expand Up @@ -302,6 +313,11 @@ func (c *AppConfig) defaults() {
SimplifyHdrCompare: false,
},
APIToken: "",
Notifications: domain.Notifications{
Discord: "",
// Notifiarr: "",
// Shoutrrr: "",
},
}
}

Expand Down Expand Up @@ -482,7 +498,11 @@ func (c *AppConfig) processLines(lines []string) []string {
foundLineSimplifyHdrCompare = true
}
if !foundLineApiToken && strings.Contains(line, "apiToken:") {
lines[i] = fmt.Sprintf("apiToken: \"%s\"", c.Config.APIToken)
if c.Config.APIToken == "" {
lines[i] = "# apiToken: \"\""
} else {
lines[i] = fmt.Sprintf("apiToken: \"%s\"", c.Config.APIToken)
}
foundLineApiToken = true
}
}
Expand Down
7 changes: 7 additions & 0 deletions internal/domain/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ type FuzzyMatching struct {
SimplifyHdrCompare bool `yaml:"simplifyHdrCompare"`
}

type Notifications struct {
Discord string `yaml:"discord"`
// Notifiarr string `yaml:"notifiarr"`
// Shoutrrr string `yaml:"shoutrrr"`
}

type Config struct {
Version string
ConfigPath string
Expand All @@ -32,4 +38,5 @@ type Config struct {
ParseTorrentFile bool `yaml:"parseTorrentFile"`
FuzzyMatching FuzzyMatching `yaml:"fuzzyMatching"`
APIToken string `yaml:"apiToken"`
Notifications Notifications `yaml:"notifications"`
}
32 changes: 32 additions & 0 deletions internal/domain/http.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (c) 2023 - 2024, nuxen and the seasonpackarr contributors.
// SPDX-License-Identifier: GPL-2.0-or-later

package domain

const (
StatusNoMatches = 200
StatusResolutionMismatch = 201
StatusSourceMismatch = 202
StatusRlsGrpMismatch = 203
StatusCutMismatch = 204
StatusEditionMismatch = 205
StatusRepackStatusMismatch = 206
StatusHdrMismatch = 207
StatusStreamingServiceMismatch = 208
StatusAlreadyInClient = 210
StatusNotASeasonPack = 211
StatusBelowThreshold = 230
StatusSuccessfulMatch = 250
StatusSuccessfulHardlink = 250
StatusFailedHardlink = 440
StatusClientNotFound = 472
StatusGetClientError = 471
StatusDecodingError = 470
StatusAnnounceNameError = 469
StatusGetTorrentsError = 468
StatusTorrentBytesError = 467
StatusDecodeTorrentBytesError = 466
StatusParseTorrentInfoError = 465
StatusGetEpisodesError = 464
StatusEpisodeCountError = 450
)
18 changes: 18 additions & 0 deletions internal/domain/notification.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) 2021 - 2024, Ludvig Lundgren and the autobrr contributors.
// Code is heavily modified for use with seasonpackarr
// SPDX-License-Identifier: GPL-2.0-or-later

package domain

type Sender interface {
Send(statusCode int, payload NotificationPayload) error
}

type NotificationPayload struct {
Subject string
Message string
ReleaseName string
Client string
Action string
Error error
}
Loading

0 comments on commit 6f9b6fd

Please sign in to comment.