mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-12-17 04:34:40 +03:00
Added 3 new buttons to telegram bot (#2965)
Some checks failed
Build and Release 3X-UI / build (386) (push) Has been cancelled
Build and Release 3X-UI / build (amd64) (push) Has been cancelled
Build and Release 3X-UI / build (arm64) (push) Has been cancelled
Build and Release 3X-UI / build (armv5) (push) Has been cancelled
Build and Release 3X-UI / build (armv6) (push) Has been cancelled
Build and Release 3X-UI / build (armv7) (push) Has been cancelled
Build and Release 3X-UI / build (s390x) (push) Has been cancelled
Some checks failed
Build and Release 3X-UI / build (386) (push) Has been cancelled
Build and Release 3X-UI / build (amd64) (push) Has been cancelled
Build and Release 3X-UI / build (arm64) (push) Has been cancelled
Build and Release 3X-UI / build (armv5) (push) Has been cancelled
Build and Release 3X-UI / build (armv6) (push) Has been cancelled
Build and Release 3X-UI / build (armv7) (push) Has been cancelled
Build and Release 3X-UI / build (s390x) (push) Has been cancelled
* 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
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user