mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-09-04 17:37:19 +00:00
fix(tgbot): reload bot on settings save so a new token takes effect without a panel restart
The Telegram bot was only started at panel boot, so saving a token or toggling tgBotEnable persisted to the DB but never reached the running bot until a full restart, making it look like the token did not save (issue #5539). The settings/update controller now reconciles the bot the same way panelOutbound reconciles Xray: when tgBotEnable, the token, chat ID, or API server change, it stops/(re)starts the bot and updates the event-bus subscription.
This commit is contained in:
@@ -619,6 +619,28 @@ func (s *Server) start(restartXray bool, startTgBot bool) (err error) {
|
||||
return nil
|
||||
})
|
||||
|
||||
controller.SetReloadTgbotFunc(func() {
|
||||
enabled, err := s.settingService.GetTgbotEnabled()
|
||||
if err != nil || !enabled {
|
||||
if s.tgbotService.IsRunning() {
|
||||
s.tgbotService.Stop()
|
||||
}
|
||||
if s.bus != nil {
|
||||
s.bus.Unsubscribe("tg-notifier")
|
||||
}
|
||||
return
|
||||
}
|
||||
// Start() stops any previous receiver first, so it is safe whether or not the bot is already running.
|
||||
tgBot := s.tgbotService.NewTgbot()
|
||||
if startErr := tgBot.Start(i18nFS); startErr != nil {
|
||||
logger.Warning("reload Telegram bot failed:", startErr)
|
||||
return
|
||||
}
|
||||
if s.bus != nil {
|
||||
s.bus.Subscribe("tg-notifier", s.tgbotService.HandleEvent)
|
||||
}
|
||||
})
|
||||
|
||||
s.startTask(restartXray)
|
||||
|
||||
if startTgBot {
|
||||
|
||||
Reference in New Issue
Block a user