From 5ef8a5a37ec7e6b7df710fa61b0324ab5a6617ab Mon Sep 17 00:00:00 2001 From: MHSanaei <33454419+MHSanaei@users.noreply.github.com> Date: Thu, 23 Mar 2023 23:22:50 +0330 Subject: old design --- web/web.go | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) (limited to 'web/web.go') diff --git a/web/web.go b/web/web.go index 1c692598..d57fc084 100644 --- a/web/web.go +++ b/web/web.go @@ -21,11 +21,11 @@ import ( "x-ui/web/network" "x-ui/web/service" + "github.com/pelletier/go-toml/v2" "github.com/gin-contrib/sessions" "github.com/gin-contrib/sessions/cookie" "github.com/gin-gonic/gin" "github.com/nicksnyder/go-i18n/v2/i18n" - "github.com/pelletier/go-toml/v2" "github.com/robfig/cron/v3" "golang.org/x/text/language" ) @@ -88,7 +88,7 @@ type Server struct { xrayService service.XrayService settingService service.SettingService - tgbotService service.Tgbot + inboundService service.InboundService cron *cron.Cron @@ -309,7 +309,7 @@ func (s *Server) startTask() { // Check the inbound traffic every 30 seconds that the traffic exceeds and expires s.cron.AddJob("@every 30s", job.NewCheckInboundJob()) - + // check client ips from log file every 10 sec s.cron.AddJob("@every 10s", job.NewCheckClientIpJob()) @@ -328,13 +328,8 @@ func (s *Server) startTask() { logger.Warning("Add NewStatsNotifyJob error", err) return } - - // Check CPU load and alarm to TgBot if threshold passes - cpuThreshold, err := s.settingService.GetTgCpu() - if (err == nil) && (cpuThreshold > 0) { - s.cron.AddJob("@every 10s", job.NewCheckCpuJob()) - } - + // listen for TG bot income messages + go job.NewStatsNotifyJob().OnReceive() } else { s.cron.Remove(entry) } @@ -411,12 +406,6 @@ func (s *Server) Start() (err error) { s.httpServer.Serve(listener) }() - isTgbotenabled, err := s.settingService.GetTgbotenabled() - if (err == nil) && (isTgbotenabled) { - tgBot := s.tgbotService.NewTgbot() - tgBot.Start() - } - return nil } @@ -426,9 +415,6 @@ func (s *Server) Stop() error { if s.cron != nil { s.cron.Stop() } - if s.tgbotService.IsRunnging() { - s.tgbotService.Stop() - } var err1 error var err2 error if s.httpServer != nil { -- cgit v1.2.3