package main import ( "os" "os/signal" "syscall" "go.uber.org/zap" "git.gensokyo.cafe/kkyy/tgbot_misaka_5882f7/utils" ) var logger *zap.SugaredLogger func initLogger() { l, err := zap.NewProduction() if err != nil { panic(err) } logger = l.Sugar() } func runBot() { logger.Info("Bot initializing...") bot, err := initBot() if err != nil { logger.Fatalw("Failed to initialize bot", "err", err) } botFinCh := utils.WaitFor(bot.Start) logger.Infow("Bot started", "username", bot.Me.Username) // listen for shutdown signal sigCh := make(chan os.Signal, 1) signal.Notify(sigCh, os.Interrupt, syscall.SIGTERM) select { case sig := <-sigCh: logger.Infow("Received signal", "signal", sig) logger.Info("Bot shutdown...") bot.Stop() case <-botFinCh: logger.Warn("Bot terminated") } } func main() { initLogger() if err := LoadCfg(); err != nil { logger.Fatalw("Failed to load config", "err", err) } runBot() }