From 294894eca0febe1eca1e36584fb695630fcc001c Mon Sep 17 00:00:00 2001 From: Alireza Ahmadi Date: Wed, 29 Mar 2023 12:12:27 +0200 Subject: [PATCH] [tgbot] adjust tgbot usage to new method --- web/service/inbound.go | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/web/service/inbound.go b/web/service/inbound.go index 605bd6e3af..e78a10902e 100644 --- a/web/service/inbound.go +++ b/web/service/inbound.go @@ -505,11 +505,27 @@ func (s *InboundService) ResetClientTraffic(id int, clientEmail string) error { } return nil } -func (s *InboundService) GetClientTrafficTgBot(tguname string) (traffic []*xray.ClientTraffic, err error) { +func (s *InboundService) GetClientTrafficTgBot(tguname string) ([]*xray.ClientTraffic, error) { db := database.GetDB() + var inbounds []*model.Inbound + err := db.Model(model.Inbound{}).Where("settings like ?", fmt.Sprintf(`%%"tgId": "%s"%%`, tguname)).Find(&inbounds).Error + if err != nil && err != gorm.ErrRecordNotFound { + return nil, err + } + var emails []string + for _, inbound := range inbounds { + clients, err := s.getClients(inbound) + if err != nil { + logger.Error("Unable to get clients from inbound") + } + for _, client := range clients { + if client.TgID == tguname { + emails = append(emails, client.Email) + } + } + } var traffics []*xray.ClientTraffic - - err = db.Model(xray.ClientTraffic{}).Where("email like ?", "%@"+tguname).Find(&traffics).Error + err = db.Model(xray.ClientTraffic{}).Where("email IN ?", emails).Find(&traffics).Error if err != nil { if err == gorm.ErrRecordNotFound { logger.Warning(err)