diff options
| author | nistootsin <104831639+nistootsin@users.noreply.github.com> | 2025-05-06 19:27:17 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-06 19:27:17 +0300 |
| commit | d39ccf4b8f77f99d4468580085e9d89e8b5f0b1c (patch) | |
| tree | 90ca065b6aed3171771f9c87ab3b6371eb91f1ea /web/service/inbound.go | |
| parent | 1aed2d8cdcd7b971d3bc055d428a7958a71c9226 (diff) | |
Added 3 new buttons to telegram bot (#2965)
* Add a new button to but : Reset All Clients
* handel translation for `Reset All Clients` button
* refactoring
* add a new button to telegram bot >> `Sorted Traffic Usage Report`
* - refactoring
* add ip limit conifg on new client adding time
Diffstat (limited to 'web/service/inbound.go')
| -rw-r--r-- | web/service/inbound.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/web/service/inbound.go b/web/service/inbound.go index fce01634..f2646dbb 100644 --- a/web/service/inbound.go +++ b/web/service/inbound.go @@ -3,6 +3,7 @@ package service import ( "encoding/json" "fmt" + "sort" "strconv" "strings" "time" @@ -2025,3 +2026,37 @@ func (s *InboundService) MigrateDB() { func (s *InboundService) GetOnlineClients() []string { return p.GetOnlineClients() } + +func (s *InboundService) FilterAndSortClientEmails(emails []string) ([]string, []string, error) { + db := database.GetDB() + + // Step 1: Get ClientTraffic records for emails in the input list + var clients []xray.ClientTraffic + err := db.Where("email IN ?", emails).Find(&clients).Error + if err != nil && err != gorm.ErrRecordNotFound { + return nil, nil, err + } + + // Step 2: Sort clients by (Up + Down) descending + sort.Slice(clients, func(i, j int) bool { + return (clients[i].Up + clients[i].Down) > (clients[j].Up + clients[j].Down) + }) + + // Step 3: Extract sorted valid emails and track found ones + validEmails := make([]string, 0, len(clients)) + found := make(map[string]bool) + for _, client := range clients { + validEmails = append(validEmails, client.Email) + found[client.Email] = true + } + + // Step 4: Identify emails that were not found in the database + extraEmails := make([]string, 0) + for _, email := range emails { + if !found[email] { + extraEmails = append(extraEmails, email) + } + } + + return validEmails, extraEmails, nil +} |
