notify

package
v0.2.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 21, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package notify provides the notifier for the notification.

Index

Constants

This section is empty.

Variables

View Source
var DefaultNotificationFormats = NotificationFormats{
	ConfigReloaded: NotificationFormat{
		Enabled:  ptr.Ref(true),
		Title:    "config reloaded",
		Message:  "",
		Priority: 10,
	},
	LoginFailed: NotificationFormat{
		Enabled:  ptr.Ref(true),
		Title:    "login failed",
		Message:  "{{ .Error }}",
		Priority: 10,
	},
	Panicked: NotificationFormat{
		Enabled:  ptr.Ref(true),
		Title:    "panicked",
		Message:  "{{ .Capture }}",
		Priority: 10,
	},
	Idle: NotificationFormat{
		Enabled: ptr.Ref(false),
		Title:   "watching {{ .ChannelID }}",
	},
	PreparingFiles: NotificationFormat{
		Enabled: ptr.Ref(false),
		Title:   "preparing files for {{ .ChannelID }}",
	},
	Downloading: NotificationFormat{
		Enabled:  ptr.Ref(true),
		Title:    "{{ .ChannelID }} is streaming",
		Message:  "{{ .MetaData.Stream.Title }}",
		Priority: 7,
	},
	PostProcessing: NotificationFormat{
		Enabled:  ptr.Ref(false),
		Title:    "post-processing {{ .ChannelID }}",
		Message:  "{{ .MetaData.Stream.Title }}",
		Priority: 7,
	},
	Finished: NotificationFormat{
		Enabled:  ptr.Ref(true),
		Title:    "{{ .ChannelID }} stream ended",
		Message:  "{{ .MetaData.Stream.Title }}",
		Priority: 7,
	},
	Error: NotificationFormat{
		Enabled:  ptr.Ref(true),
		Title:    "stream download of {{ .ChannelID }} failed",
		Message:  "{{ .Error }}",
		Priority: 10,
	},
	Canceled: NotificationFormat{
		Enabled:  ptr.Ref(true),
		Title:    "stream download of {{ .ChannelID }} canceled",
		Priority: 10,
	},
	UpdateAvailable: NotificationFormat{
		Enabled:  ptr.Ref(true),
		Title:    "update available ({{ .Version }})",
		Message:  "A new version ({{ .Version }}) of withny-dl is available. Please update.",
		Priority: 7,
	},
}

DefaultNotificationFormats is the default notification formats.

Functions

This section is empty.

Types

type BaseNotifier

type BaseNotifier interface {
	Notify(
		ctx context.Context,
		title string,
		message string,
		priority int,
	) error
}

BaseNotifier is the interface for the notifier

type DummyNotifier

type DummyNotifier struct{}

DummyNotifier is the notifier which prints in the logs.

func NewDummyNotifier

func NewDummyNotifier() *DummyNotifier

NewDummyNotifier creates a new Dummy notifier.

func (*DummyNotifier) Notify

func (*DummyNotifier) Notify(
	_ context.Context,
	title string,
	message string,
	_ int,
) error

Notify sends a notification over nothing.

type FormatedNotifier

type FormatedNotifier struct {
	BaseNotifier
	NotificationFormats
	NotificationTemplates
}

FormatedNotifier is a notifier that formats the notifications.

func NewFormatedNotifier

func NewFormatedNotifier(notifier BaseNotifier, formats NotificationFormats) *FormatedNotifier

NewFormatedNotifier creates a new FormatedNotifier.

func (*FormatedNotifier) NotifyCanceled

func (n *FormatedNotifier) NotifyCanceled(
	ctx context.Context,
	channelID string,
	labels map[string]string,
) error

NotifyCanceled sends a notification that the download was canceled.

func (*FormatedNotifier) NotifyConfigReloaded

func (n *FormatedNotifier) NotifyConfigReloaded(ctx context.Context) error

NotifyConfigReloaded sends a notification that the config was reloaded.

func (*FormatedNotifier) NotifyDownloading

func (n *FormatedNotifier) NotifyDownloading(
	ctx context.Context,
	channelID string,
	labels map[string]string,
	metadata any,
) error

NotifyDownloading sends a notification that the download is starting.

func (*FormatedNotifier) NotifyError

func (n *FormatedNotifier) NotifyError(
	ctx context.Context,
	channelID string,
	labels map[string]string,
	err error,
) error

NotifyError sends a notification that the download encountered an error.

func (*FormatedNotifier) NotifyFinished

func (n *FormatedNotifier) NotifyFinished(
	ctx context.Context,
	channelID string,
	labels map[string]string,
	metadata any,
) error

NotifyFinished sends a notification that the download is finished.

func (*FormatedNotifier) NotifyIdle

func (n *FormatedNotifier) NotifyIdle(
	ctx context.Context,
	channelID string,
	labels map[string]string,
) error

NotifyIdle sends a notification that the download is idle.

func (*FormatedNotifier) NotifyLoginFailed

func (n *FormatedNotifier) NotifyLoginFailed(ctx context.Context, capture error) error

NotifyLoginFailed sends a notification that the login failed.

func (*FormatedNotifier) NotifyPanicked

func (n *FormatedNotifier) NotifyPanicked(ctx context.Context, capture any) error

NotifyPanicked sends a notification that the download panicked.

func (*FormatedNotifier) NotifyPostProcessing

func (n *FormatedNotifier) NotifyPostProcessing(
	ctx context.Context,
	channelID string,
	labels map[string]string,
	metadata any,
) error

NotifyPostProcessing sends a notification that the download is post-processing.

func (*FormatedNotifier) NotifyPreparingFiles

func (n *FormatedNotifier) NotifyPreparingFiles(
	ctx context.Context,
	channelID string,
	labels map[string]string,
	metadata any,
) error

NotifyPreparingFiles sends a notification that the download is preparing files.

func (*FormatedNotifier) NotifyUpdateAvailable

func (n *FormatedNotifier) NotifyUpdateAvailable(
	ctx context.Context,
	version string,
) error

NotifyUpdateAvailable sends a notification that an update is available.

type NotificationFormat

type NotificationFormat struct {
	Enabled  *bool  `yaml:"enabled,omitempty"`
	Title    string `yaml:"title,omitempty"`
	Message  string `yaml:"message,omitempty"`
	Priority int    `yaml:"priority,omitempty"`
}

NotificationFormat is a format for a notification.

type NotificationFormats

type NotificationFormats struct {
	ConfigReloaded  NotificationFormat `yaml:"configReloaded,omitempty"`
	LoginFailed     NotificationFormat `yaml:"loginFailed,omitempty"`
	Panicked        NotificationFormat `yaml:"panicked,omitempty"`
	Idle            NotificationFormat `yaml:"idle,omitempty"`
	PreparingFiles  NotificationFormat `yaml:"preparingFiles,omitempty"`
	Downloading     NotificationFormat `yaml:"downloading,omitempty"`
	PostProcessing  NotificationFormat `yaml:"postProcessing,omitempty"`
	Finished        NotificationFormat `yaml:"finished,omitempty"`
	Error           NotificationFormat `yaml:"error,omitempty"`
	Canceled        NotificationFormat `yaml:"canceled,omitempty"`
	UpdateAvailable NotificationFormat `yaml:"updateAvailable,omitempty"`
}

NotificationFormats is a collection of formats for notifications.

type NotificationTemplate

type NotificationTemplate struct {
	TitleTemplate   *template.Template
	MessageTemplate *template.Template
}

NotificationTemplate is a template for a notification.

type NotificationTemplates

type NotificationTemplates struct {
	ConfigReloaded  NotificationTemplate
	LoginFailed     NotificationTemplate
	Panicked        NotificationTemplate
	Idle            NotificationTemplate
	PreparingFiles  NotificationTemplate
	Downloading     NotificationTemplate
	PostProcessing  NotificationTemplate
	Finished        NotificationTemplate
	Error           NotificationTemplate
	Canceled        NotificationTemplate
	UpdateAvailable NotificationTemplate
}

NotificationTemplates is a collection of templates for notifications.

type Shoutrrr

type Shoutrrr struct {
	*router.ServiceRouter
	// contains filtered or unexported fields
}

Shoutrrr is the notifier for shoutrrr.

func NewShoutrrr

func NewShoutrrr(urls []string, opts ...ShoutrrrOption) *Shoutrrr

NewShoutrrr creates a new Shoutrrr notifier.

func (*Shoutrrr) Notify

func (n *Shoutrrr) Notify(
	ctx context.Context,
	title string,
	message string,
	priority int,
) error

Notify sends a notification with Shoutrrr.

type ShoutrrrOption

type ShoutrrrOption func(*ShoutrrrOptions)

ShoutrrrOption is the option for the Shoutrrr notifier

func IncludeTitleInMessage

func IncludeTitleInMessage(value ...bool) ShoutrrrOption

IncludeTitleInMessage is an option to include the title in the message

func NoPriority

func NoPriority(value ...bool) ShoutrrrOption

NoPriority is an option to not include the priority

type ShoutrrrOptions

type ShoutrrrOptions struct {
	// contains filtered or unexported fields
}

ShoutrrrOptions is the options for the Shoutrrr notifier

Directories

Path Synopsis
Package notifier provides functions to notify the user about the status of the download.
Package notifier provides functions to notify the user about the status of the download.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL