explicit telegram enable flag
This commit is contained in:
@@ -85,7 +85,7 @@ func main() {
|
|||||||
defer stop()
|
defer stop()
|
||||||
|
|
||||||
// Telegram bot
|
// Telegram bot
|
||||||
if cfg.Telegram.Token != "" {
|
if cfg.Telegram.Enabled {
|
||||||
tgBot, err := telegram.NewBot(cfg.Telegram, memorySvc, client, cfg.Memos.URL, cfg.Memos.PublicURL, loc, logger)
|
tgBot, err := telegram.NewBot(cfg.Telegram, memorySvc, client, cfg.Memos.URL, cfg.Memos.PublicURL, loc, logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("failed to create telegram bot", "error", err)
|
logger.Error("failed to create telegram bot", "error", err)
|
||||||
|
|||||||
@@ -85,6 +85,9 @@ tier7 = 8
|
|||||||
# =============================================================================
|
# =============================================================================
|
||||||
[telegram]
|
[telegram]
|
||||||
|
|
||||||
|
# Включить Telegram-бот для ежедневной отправки воспоминаний.
|
||||||
|
enabled = false
|
||||||
|
|
||||||
# Токен бота, полученный от @BotFather.
|
# Токен бота, полученный от @BotFather.
|
||||||
token = ""
|
token = ""
|
||||||
|
|
||||||
|
|||||||
@@ -57,9 +57,10 @@ func (tw TierWeights) AsSlice() [7]int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type TelegramConfig struct {
|
type TelegramConfig struct {
|
||||||
Token string `toml:"token"`
|
Enabled bool `toml:"enabled"`
|
||||||
ChatID int64 `toml:"chat_id"`
|
Token string `toml:"token"`
|
||||||
SendAt string `toml:"send_at"`
|
ChatID int64 `toml:"chat_id"`
|
||||||
|
SendAt string `toml:"send_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type WebConfig struct {
|
type WebConfig struct {
|
||||||
@@ -137,9 +138,12 @@ func validate(cfg *Config) error {
|
|||||||
if sum := cfg.Search.TierWeights.Sum(); sum != 100 {
|
if sum := cfg.Search.TierWeights.Sum(); sum != 100 {
|
||||||
return fmt.Errorf("search.tier_weights must sum to 100, got %d", sum)
|
return fmt.Errorf("search.tier_weights must sum to 100, got %d", sum)
|
||||||
}
|
}
|
||||||
if cfg.Telegram.Token != "" {
|
if cfg.Telegram.Enabled {
|
||||||
|
if cfg.Telegram.Token == "" {
|
||||||
|
return fmt.Errorf("telegram.token is required when telegram.enabled = true")
|
||||||
|
}
|
||||||
if cfg.Telegram.ChatID == 0 {
|
if cfg.Telegram.ChatID == 0 {
|
||||||
return fmt.Errorf("telegram.chat_id is required when telegram.token is set")
|
return fmt.Errorf("telegram.chat_id is required when telegram.enabled = true")
|
||||||
}
|
}
|
||||||
if !timeFormatRe.MatchString(cfg.Telegram.SendAt) {
|
if !timeFormatRe.MatchString(cfg.Telegram.SendAt) {
|
||||||
return fmt.Errorf("telegram.send_at must be in HH:MM format, got %q", cfg.Telegram.SendAt)
|
return fmt.Errorf("telegram.send_at must be in HH:MM format, got %q", cfg.Telegram.SendAt)
|
||||||
|
|||||||
Reference in New Issue
Block a user