removed redundant notifiers :(
This commit is contained in:
parent
98c2c3741f
commit
9d8c9b5590
5 changed files with 0 additions and 322 deletions
67
README.md
67
README.md
|
|
@ -434,73 +434,6 @@ database:
|
||||||
prune: "@every 1h"
|
prune: "@every 1h"
|
||||||
```
|
```
|
||||||
|
|
||||||
## Telegram
|
|
||||||
|
|
||||||
Get a bot token from the [@BotFather](https://core.telegram.org/bots/tutorial) and get the [chatID](https://www.alphr.com/find-chat-id-telegram/) of the chat want to send the notifications to.
|
|
||||||
An example config for sending notifications through Telegram:
|
|
||||||
```
|
|
||||||
notifiers:
|
|
||||||
Telegram:
|
|
||||||
token: "<token>"
|
|
||||||
chat: "<chatID>"
|
|
||||||
debug: false
|
|
||||||
database:
|
|
||||||
dsn: "watch.db"
|
|
||||||
prune: "@every 1h"
|
|
||||||
```
|
|
||||||
|
|
||||||
## Discord
|
|
||||||
|
|
||||||
To get a token, userID and/or serverID you first have to enable [Developer Mode and create a new application](https://www.ionos.com/digitalguide/server/know-how/creating-discord-bot/).
|
|
||||||
Then you can right click on your username in any chat to copy your user ID or right click on a server/channel to get the server/channel ID.
|
|
||||||
An example config for sending DM notifications through Discord:
|
|
||||||
```
|
|
||||||
notifiers:
|
|
||||||
Discord:
|
|
||||||
type: "discord"
|
|
||||||
token: "<token>"
|
|
||||||
userID: "<userID>"
|
|
||||||
debug: false
|
|
||||||
database:
|
|
||||||
dsn: "watch.db"
|
|
||||||
prune: "@every 1h"
|
|
||||||
```
|
|
||||||
|
|
||||||
An example config for sending channel notifications:
|
|
||||||
```
|
|
||||||
notifiers:
|
|
||||||
Discord:
|
|
||||||
type: "discord"
|
|
||||||
token: "<token>"
|
|
||||||
server:
|
|
||||||
ID: "<serverID>"
|
|
||||||
channel: "<channelID>"
|
|
||||||
debug: false
|
|
||||||
database:
|
|
||||||
dsn: "watch.db"
|
|
||||||
prune: "@every 1h"
|
|
||||||
```
|
|
||||||
|
|
||||||
Both a userID and serverID/channelID is also possible.
|
|
||||||
|
|
||||||
## Email
|
|
||||||
|
|
||||||
An example config for sending email notifications through a SMTP relay server:
|
|
||||||
```
|
|
||||||
notifiers:
|
|
||||||
Email-to-at-email-com:
|
|
||||||
type: "email"
|
|
||||||
server: "smtp.relay.com"
|
|
||||||
port: "465"
|
|
||||||
from: "from@email.com"
|
|
||||||
user: "apikey"
|
|
||||||
password: "-"
|
|
||||||
to: "to@email.com"
|
|
||||||
database:
|
|
||||||
dsn: "watch.db"
|
|
||||||
prune: "@every 1h"
|
|
||||||
```
|
|
||||||
|
|
||||||
# Dev
|
# Dev
|
||||||
## type script compilation
|
## type script compilation
|
||||||
|
|
||||||
|
|
|
||||||
18
main.go
18
main.go
|
|
@ -207,24 +207,6 @@ func (web *Web) initNotifiers() {
|
||||||
success := false
|
success := false
|
||||||
var notifier notifiers.Notifier
|
var notifier notifiers.Notifier
|
||||||
switch notifierType {
|
switch notifierType {
|
||||||
case "telegram":
|
|
||||||
{
|
|
||||||
notifier = ¬ifiers.TelegramNotifier{}
|
|
||||||
success = notifier.Open(notifierPath)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
case "discord":
|
|
||||||
{
|
|
||||||
notifier = ¬ifiers.DiscordNotifier{}
|
|
||||||
success = notifier.Open(notifierPath)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
case "email":
|
|
||||||
{
|
|
||||||
notifier = ¬ifiers.EmailNotifier{}
|
|
||||||
success = notifier.Open(notifierPath)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
case "shoutrrr":
|
case "shoutrrr":
|
||||||
{
|
{
|
||||||
notifier = ¬ifiers.ShoutrrrNotifier{}
|
notifier = ¬ifiers.ShoutrrrNotifier{}
|
||||||
|
|
|
||||||
|
|
@ -1,93 +0,0 @@
|
||||||
package notifiers
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
|
|
||||||
"github.com/bwmarrin/discordgo"
|
|
||||||
"github.com/spf13/viper"
|
|
||||||
)
|
|
||||||
|
|
||||||
type DiscordNotifier struct {
|
|
||||||
Bot *discordgo.Session
|
|
||||||
Token string
|
|
||||||
UserID string
|
|
||||||
UserChannel *discordgo.Channel
|
|
||||||
ServerID string
|
|
||||||
ChannelID string
|
|
||||||
ServerChannel *discordgo.Channel
|
|
||||||
Debug bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func (discord *DiscordNotifier) Open(configPath string) bool {
|
|
||||||
userIDPath := fmt.Sprintf("%s.userID", configPath)
|
|
||||||
serverPath := fmt.Sprintf("%s.server", configPath)
|
|
||||||
if !viper.IsSet(userIDPath) && !viper.IsSet(serverPath) {
|
|
||||||
log.Println("Net either 'serverID' or 'userID' for Discord")
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
bot, err := discordgo.New("Bot " + viper.GetString("notifiers.discord.token"))
|
|
||||||
if err != nil {
|
|
||||||
log.Println("Could not start Discord notifier:\n", err)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if viper.IsSet(userIDPath) {
|
|
||||||
discord.UserID = viper.GetString(userIDPath)
|
|
||||||
channel, err := bot.UserChannelCreate(discord.UserID)
|
|
||||||
if err != nil {
|
|
||||||
log.Println("Could not connect to user channel:", discord.UserID, err)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
discord.UserChannel = channel
|
|
||||||
log.Println("Authorized discord bot for:", channel.Recipients)
|
|
||||||
}
|
|
||||||
if viper.IsSet(serverPath) {
|
|
||||||
serverIDPath := fmt.Sprintf("%s.server.ID", configPath)
|
|
||||||
serverChannelPath := fmt.Sprintf("%s.server.channel", configPath)
|
|
||||||
discord.ServerID = viper.GetString(serverIDPath)
|
|
||||||
discord.ChannelID = viper.GetString(serverChannelPath)
|
|
||||||
channels, err := bot.GuildChannels(discord.ServerID)
|
|
||||||
if err != nil {
|
|
||||||
log.Println("Could not connect to server channel:", discord.ServerID, err)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
foundChannel := false
|
|
||||||
for i := range channels {
|
|
||||||
channel := channels[i]
|
|
||||||
if channel.ID == discord.ChannelID {
|
|
||||||
foundChannel = true
|
|
||||||
discord.ServerChannel = channel
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !foundChannel {
|
|
||||||
log.Println("Did not find channel with '"+discord.ChannelID+"' in server:", discord.ServerID)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
log.Println("Authorized discord bot for:", discord.ServerChannel.Name)
|
|
||||||
}
|
|
||||||
debugPath := fmt.Sprintf("%s.debug", configPath)
|
|
||||||
discord.Debug = viper.GetBool(debugPath)
|
|
||||||
if discord.Debug {
|
|
||||||
bot.LogLevel = discordgo.LogDebug
|
|
||||||
} else {
|
|
||||||
bot.LogLevel = discordgo.LogInformational
|
|
||||||
}
|
|
||||||
discord.Bot = bot
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func (discord *DiscordNotifier) Message(message string) bool {
|
|
||||||
if discord.UserChannel != nil {
|
|
||||||
discord.Bot.ChannelMessageSend(discord.UserChannel.ID, message)
|
|
||||||
}
|
|
||||||
if discord.ServerChannel != nil {
|
|
||||||
discord.Bot.ChannelMessageSend(discord.ServerChannel.ID, message)
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func (discord *DiscordNotifier) Close() bool {
|
|
||||||
discord.Bot.Close()
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
@ -1,89 +0,0 @@
|
||||||
package notifiers
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
|
|
||||||
"github.com/spf13/viper"
|
|
||||||
"gopkg.in/gomail.v2"
|
|
||||||
)
|
|
||||||
|
|
||||||
type EmailNotifier struct {
|
|
||||||
Server string
|
|
||||||
Port int
|
|
||||||
From string
|
|
||||||
User string
|
|
||||||
To string
|
|
||||||
Password string
|
|
||||||
Debug bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func (email *EmailNotifier) Open(configPath string) bool {
|
|
||||||
serverPath := fmt.Sprintf("%s.server", configPath)
|
|
||||||
if viper.IsSet(serverPath) {
|
|
||||||
email.Server = viper.GetString(serverPath)
|
|
||||||
} else {
|
|
||||||
log.Println("Need 'server' var for email notifier")
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
portPath := fmt.Sprintf("%s.port", configPath)
|
|
||||||
if viper.IsSet(portPath) {
|
|
||||||
email.Port = viper.GetInt(portPath)
|
|
||||||
} else {
|
|
||||||
log.Println("Need 'port' var for email notifier")
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
userPath := fmt.Sprintf("%s.user", configPath)
|
|
||||||
if viper.IsSet(userPath) {
|
|
||||||
email.User = viper.GetString(userPath)
|
|
||||||
} else {
|
|
||||||
log.Println("Need 'user' var for email notifier")
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
fromPath := fmt.Sprintf("%s.from", configPath)
|
|
||||||
if viper.IsSet(fromPath) {
|
|
||||||
email.From = viper.GetString(fromPath)
|
|
||||||
} else {
|
|
||||||
log.Println("Need 'from' var for email notifier")
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
toPath := fmt.Sprintf("%s.to", configPath)
|
|
||||||
if viper.IsSet(toPath) {
|
|
||||||
email.To = viper.GetString(toPath)
|
|
||||||
} else {
|
|
||||||
log.Println("Need 'to' var for email notifier")
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
passwordPath := fmt.Sprintf("%s.password", configPath)
|
|
||||||
if viper.IsSet(passwordPath) {
|
|
||||||
email.Password = viper.GetString(passwordPath)
|
|
||||||
} else {
|
|
||||||
log.Println("Need 'password' var for email notifier")
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
log.Printf("Configured email: %s, %s", email.From, email.To)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func (email *EmailNotifier) Message(message string) bool {
|
|
||||||
m := gomail.NewMessage()
|
|
||||||
m.SetHeaders(map[string][]string{
|
|
||||||
"From": {email.From},
|
|
||||||
"To": {email.To},
|
|
||||||
"Subject": {"GoWatch"},
|
|
||||||
})
|
|
||||||
m.SetBody("text/html", message)
|
|
||||||
|
|
||||||
d := gomail.NewDialer(email.Server, email.Port, email.User, email.Password)
|
|
||||||
|
|
||||||
err := d.DialAndSend(m)
|
|
||||||
if err != nil {
|
|
||||||
log.Println("Could not send email:", err)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func (email *EmailNotifier) Close() bool {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
@ -1,55 +0,0 @@
|
||||||
package notifiers
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
|
|
||||||
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
|
|
||||||
"github.com/spf13/viper"
|
|
||||||
)
|
|
||||||
|
|
||||||
type TelegramNotifier struct {
|
|
||||||
Bot *tgbotapi.BotAPI
|
|
||||||
Token string
|
|
||||||
ChatID int64
|
|
||||||
Debug bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func (telegram *TelegramNotifier) Open(configPath string) bool {
|
|
||||||
tokenPath := fmt.Sprintf("%s.token", configPath)
|
|
||||||
if !viper.IsSet(tokenPath) {
|
|
||||||
log.Println("Telegram needs 'token' value set")
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
telegram.Token = viper.GetString(tokenPath)
|
|
||||||
bot, err := tgbotapi.NewBotAPI(telegram.Token)
|
|
||||||
if err != nil {
|
|
||||||
log.Println("Could not start Telegram notifier:\n", err)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
chatIDPath := fmt.Sprintf("%s.chat", configPath)
|
|
||||||
if !viper.IsSet(chatIDPath) {
|
|
||||||
log.Panicln("Telegram needs 'chat' ID value")
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
telegram.ChatID = viper.GetInt64(chatIDPath)
|
|
||||||
telegram.Bot = bot
|
|
||||||
bot.Debug = viper.GetBool("notifiers.telegram.debug")
|
|
||||||
log.Printf("Authorized telegram bot: %s", bot.Self.UserName)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func (telegram *TelegramNotifier) Message(message string) bool {
|
|
||||||
msg := tgbotapi.NewMessage(telegram.ChatID, message)
|
|
||||||
_, err := telegram.Bot.Send(msg)
|
|
||||||
if err != nil {
|
|
||||||
log.Println("Could not send Telegram message:\n", err)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func (telegram *TelegramNotifier) Close() bool {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
Loading…
Add table
Reference in a new issue