stats_notify_job.go 824 B

123456789101112131415161718192021222324252627282930313233
  1. package job
  2. import (
  3. "github.com/mhsanaei/3x-ui/v3/internal/web/service"
  4. "github.com/mhsanaei/3x-ui/v3/internal/web/service/tgbot"
  5. )
  6. // LoginStatus represents the status of a login attempt.
  7. type LoginStatus byte
  8. const (
  9. LoginSuccess LoginStatus = 1 // Successful login
  10. LoginFail LoginStatus = 0 // Failed login attempt
  11. )
  12. // StatsNotifyJob sends periodic statistics reports via Telegram bot.
  13. type StatsNotifyJob struct {
  14. xrayService service.XrayService
  15. tgbotService tgbot.Tgbot
  16. }
  17. // NewStatsNotifyJob creates a new statistics notification job instance.
  18. func NewStatsNotifyJob() *StatsNotifyJob {
  19. return new(StatsNotifyJob)
  20. }
  21. // Run sends a statistics report via Telegram bot if Xray is running.
  22. func (j *StatsNotifyJob) Run() {
  23. if !j.xrayService.IsXrayRunning() {
  24. return
  25. }
  26. j.tgbotService.SendReport()
  27. }