Remove Telegram
parent
22355825ed
commit
05e6f383c2
22
config.go
22
config.go
|
@ -16,7 +16,6 @@ var (
|
||||||
SyndicationTargets []SyndicationTarget
|
SyndicationTargets []SyndicationTarget
|
||||||
SelectedStorage Storage
|
SelectedStorage Storage
|
||||||
SelectedMediaStorage MediaStorage
|
SelectedMediaStorage MediaStorage
|
||||||
SelectedNotificationServices NotificationServices
|
|
||||||
SelectedImageCompression ImageCompression
|
SelectedImageCompression ImageCompression
|
||||||
DefaultLanguage string
|
DefaultLanguage string
|
||||||
Languages map[string]Language
|
Languages map[string]Language
|
||||||
|
@ -35,7 +34,6 @@ type YamlConfig struct {
|
||||||
Languages map[string]Language `yaml:"languages"`
|
Languages map[string]Language `yaml:"languages"`
|
||||||
Git GitConfig `yaml:"git"`
|
Git GitConfig `yaml:"git"`
|
||||||
BunnyCdn BunnyCdnConfig `yaml:"bunnyCdn"`
|
BunnyCdn BunnyCdnConfig `yaml:"bunnyCdn"`
|
||||||
Telegram TelegramConfig `yaml:"telegram"`
|
|
||||||
Tinify TinifyConfig `yaml:"tinify"`
|
Tinify TinifyConfig `yaml:"tinify"`
|
||||||
SyndicationTargets []string `yaml:"syndication"`
|
SyndicationTargets []string `yaml:"syndication"`
|
||||||
}
|
}
|
||||||
|
@ -45,11 +43,6 @@ type BunnyCdnConfig struct {
|
||||||
StorageName string `yaml:"storageName"`
|
StorageName string `yaml:"storageName"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type TelegramConfig struct {
|
|
||||||
UserId int `yaml:"userId"`
|
|
||||||
BotToken string `yaml:"botToken"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type TinifyConfig struct {
|
type TinifyConfig struct {
|
||||||
Key string `yaml:"key"`
|
Key string `yaml:"key"`
|
||||||
}
|
}
|
||||||
|
@ -172,21 +165,6 @@ func initConfig() (err error) {
|
||||||
if SelectedMediaStorage == nil {
|
if SelectedMediaStorage == nil {
|
||||||
log.Println("no media storage configured")
|
log.Println("no media storage configured")
|
||||||
}
|
}
|
||||||
// Find configured notification services (optional)
|
|
||||||
SelectedNotificationServices = func() NotificationServices {
|
|
||||||
var notificationServices []NotificationService = nil
|
|
||||||
// Telegram
|
|
||||||
if cfg.Telegram.UserId > 0 && len(cfg.Telegram.BotToken) > 0 {
|
|
||||||
notificationServices = append(notificationServices, &Telegram{
|
|
||||||
userId: cfg.Telegram.UserId,
|
|
||||||
botToken: cfg.Telegram.BotToken,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return notificationServices
|
|
||||||
}()
|
|
||||||
if SelectedNotificationServices == nil {
|
|
||||||
log.Println("No notification services configured")
|
|
||||||
}
|
|
||||||
// Find configured image compression service (optional)
|
// Find configured image compression service (optional)
|
||||||
SelectedImageCompression = func() ImageCompression {
|
SelectedImageCompression = func() ImageCompression {
|
||||||
// Tinify
|
// Tinify
|
||||||
|
|
|
@ -1,47 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"net/http"
|
|
||||||
"net/url"
|
|
||||||
"strconv"
|
|
||||||
)
|
|
||||||
|
|
||||||
type NotificationService interface {
|
|
||||||
Post(message string)
|
|
||||||
}
|
|
||||||
|
|
||||||
type NotificationServices []NotificationService
|
|
||||||
|
|
||||||
// Post to all Notification Services
|
|
||||||
func (notificationServices *NotificationServices) Post(message string) {
|
|
||||||
for _, notificationService := range *notificationServices {
|
|
||||||
notificationService.Post(message)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Telegram
|
|
||||||
type Telegram struct {
|
|
||||||
userId int
|
|
||||||
botToken string
|
|
||||||
}
|
|
||||||
|
|
||||||
var telegramBaseUrl = "https://api.telegram.org/bot"
|
|
||||||
|
|
||||||
func (t *Telegram) Post(message string) {
|
|
||||||
params := url.Values{}
|
|
||||||
params.Add("chat_id", strconv.Itoa(t.userId))
|
|
||||||
params.Add("text", message)
|
|
||||||
tgUrl, err := url.Parse(telegramBaseUrl + t.botToken + "/sendMessage")
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("Failed to create Telegram request")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
tgUrl.RawQuery = params.Encode()
|
|
||||||
req, _ := http.NewRequest(http.MethodPost, tgUrl.String(), nil)
|
|
||||||
resp, err := http.DefaultClient.Do(req)
|
|
||||||
if err != nil || resp.StatusCode != 200 {
|
|
||||||
fmt.Println("Failed to send Telegram message")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue