Remove Telegram

master
Jan-Lukas Else 2020-07-21 20:50:27 +02:00
父節點 22355825ed
當前提交 05e6f383c2
共有 2 個檔案被更改,包括 0 行新增69 行删除

查看文件

@ -16,7 +16,6 @@ var (
SyndicationTargets []SyndicationTarget
SelectedStorage Storage
SelectedMediaStorage MediaStorage
SelectedNotificationServices NotificationServices
SelectedImageCompression ImageCompression
DefaultLanguage string
Languages map[string]Language
@ -35,7 +34,6 @@ type YamlConfig struct {
Languages map[string]Language `yaml:"languages"`
Git GitConfig `yaml:"git"`
BunnyCdn BunnyCdnConfig `yaml:"bunnyCdn"`
Telegram TelegramConfig `yaml:"telegram"`
Tinify TinifyConfig `yaml:"tinify"`
SyndicationTargets []string `yaml:"syndication"`
}
@ -45,11 +43,6 @@ type BunnyCdnConfig struct {
StorageName string `yaml:"storageName"`
}
type TelegramConfig struct {
UserId int `yaml:"userId"`
BotToken string `yaml:"botToken"`
}
type TinifyConfig struct {
Key string `yaml:"key"`
}
@ -172,21 +165,6 @@ func initConfig() (err error) {
if SelectedMediaStorage == nil {
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)
SelectedImageCompression = func() ImageCompression {
// 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
}
}