feature: add admin error notification function

This commit is contained in:
Akulij 2025-03-25 11:55:43 +08:00
parent 973a85061c
commit 584c9afe74
2 changed files with 16 additions and 0 deletions

View File

@ -35,6 +35,7 @@ func GetBotController() BotController {
cfg := config.GetConfig() cfg := config.GetConfig()
fmt.Printf("Token value: '%v'\n", cfg.BotToken) fmt.Printf("Token value: '%v'\n", cfg.BotToken)
fmt.Printf("Admin password: '%v'\n", cfg.AdminPass) fmt.Printf("Admin password: '%v'\n", cfg.AdminPass)
fmt.Printf("Admin ID: '%v'\n", cfg.AdminID)
bot, err := tgbotapi.NewBotAPI(cfg.BotToken) bot, err := tgbotapi.NewBotAPI(cfg.BotToken)
if err != nil { if err != nil {
@ -387,3 +388,17 @@ func DownloadFile(filepath string, url string) error {
_, err = io.Copy(out, resp.Body) _, err = io.Copy(out, resp.Body)
return err return err
} }
func notifyAdminAboutError(bc BotController, errorMessage string) {
// Check if AdminID is set in the config
adminID := *bc.cfg.AdminID
if adminID != 0 {
msg := tgbotapi.NewMessage(
adminID,
fmt.Sprintf("Error occurred: %s", errorMessage),
)
bc.bot.Send(msg)
} else {
log.Println("AdminID is not set in the configuration.")
}
}

View File

@ -10,6 +10,7 @@ import (
type Config struct { type Config struct {
BotToken string `env:"BOTTOKEN, required"` BotToken string `env:"BOTTOKEN, required"`
AdminPass string `env:"ADMINPASSWORD, required"` // to activate admin privileges in bot type command: /secret `AdminPass` AdminPass string `env:"ADMINPASSWORD, required"` // to activate admin privileges in bot type command: /secret `AdminPass`
AdminID *int64 `env:"ADMINID"` // optional admin ID for notifications
} }
func GetConfig() Config { func GetConfig() Config {