diff --git a/service/binance.go b/service/binance.go index 5e9c51e..9e56d94 100644 --- a/service/binance.go +++ b/service/binance.go @@ -28,6 +28,9 @@ func init() { chatID = mustParseInt64(os.Getenv("CHAT_ID")) symbols = strings.Split(os.Getenv("SYMBOLS"), ",") + // 初始化 singaporeTZ + singaporeTZ = time.FixedZone("Asia/Singapore", 8*60*60) // UTC+8 + bot, err = tgbotapi.NewBotAPI(botToken) if err != nil { log.Fatal(err) @@ -95,7 +98,13 @@ func formatChange(changePercent float64) string { } func sendPriceUpdate() { - now := time.Now().In(singaporeTZ) + var now time.Time + if singaporeTZ != nil { + now = time.Now().In(singaporeTZ) + } else { + now = time.Now().UTC() + log.Println("Warning: singaporeTZ is nil, using UTC") + } message := fmt.Sprintf("市场更新 - %s (SGT)\n\n", now.Format("2006-01-02 15:04:05")) for _, symbol := range symbols { @@ -132,16 +141,12 @@ func sendPriceUpdate() { } func RunBinance() { - log.Println("Sending initial price update...") - sendPriceUpdate() - - ticker := time.NewTicker(1 * time.Hour) - defer ticker.Stop() - + log.Println("Starting Binance service...") for { - select { - case <-ticker.C: - sendPriceUpdate() - } + log.Println("Sending price update...") + sendPriceUpdate() + + log.Println("Waiting for next update...") + time.Sleep(1 * time.Hour) } } diff --git a/service/guard.go b/service/guard.go index 99f769b..a1dffc0 100644 --- a/service/guard.go +++ b/service/guard.go @@ -145,7 +145,7 @@ func StartBot() error { log.Printf("Authorized on account %s", bot.Self.UserName) - err = core.RegisterCommands(bot, adminID) + err = core.RegisterCommands(bot, 0) if err != nil { return fmt.Errorf("error registering commands: %w", err) }