Skip to content

Commit

Permalink
[tgbot] adjust tgbot usage to new method
Browse files Browse the repository at this point in the history
  • Loading branch information
Alireza Ahmadi committed Mar 29, 2023
1 parent f3df93a commit 294894e
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions web/service/inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 294894e

Please sign in to comment.