add telegram bot
This commit is contained in:
@@ -3,10 +3,13 @@ package config
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"regexp"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
)
|
||||
|
||||
var timeFormatRe = regexp.MustCompile(`^\d{2}:\d{2}$`)
|
||||
|
||||
type Config struct {
|
||||
Memos MemosConfig `toml:"memos"`
|
||||
Database DatabaseConfig `toml:"database"`
|
||||
@@ -119,6 +122,9 @@ func setDefaults(cfg *Config) {
|
||||
if cfg.General.LogLevel == "" {
|
||||
cfg.General.LogLevel = "info"
|
||||
}
|
||||
if cfg.Telegram.SendAt == "" {
|
||||
cfg.Telegram.SendAt = "09:00"
|
||||
}
|
||||
}
|
||||
|
||||
func validate(cfg *Config) error {
|
||||
@@ -131,5 +137,13 @@ func validate(cfg *Config) error {
|
||||
if sum := cfg.Search.TierWeights.Sum(); sum != 100 {
|
||||
return fmt.Errorf("search.tier_weights must sum to 100, got %d", sum)
|
||||
}
|
||||
if cfg.Telegram.Token != "" {
|
||||
if cfg.Telegram.ChatID == 0 {
|
||||
return fmt.Errorf("telegram.chat_id is required when telegram.token is set")
|
||||
}
|
||||
if !timeFormatRe.MatchString(cfg.Telegram.SendAt) {
|
||||
return fmt.Errorf("telegram.send_at must be in HH:MM format, got %q", cfg.Telegram.SendAt)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user