Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/MHSanaei/3x-ui.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMasoud Hidden <masoud.hidden.user@gmail.com>2023-05-05 19:20:40 +0300
committerMasoud Hidden <masoud.hidden.user@gmail.com>2023-05-05 19:20:40 +0300
commitd349bffcd6ba547ed9e4cdf5b199c5100a99437f (patch)
tree858f71484685380c62a8fcfb7a5f31ae2e88b690
parent5856160c30fb3f525b584fb25a35ec78c8fb0488 (diff)
Fix bot client enable button
-rw-r--r--web/service/inbound.go34
-rw-r--r--web/service/tgbot.go8
2 files changed, 21 insertions, 21 deletions
diff --git a/web/service/inbound.go b/web/service/inbound.go
index 2cd42b8e..dd633c4b 100644
--- a/web/service/inbound.go
+++ b/web/service/inbound.go
@@ -679,21 +679,22 @@ func (s *InboundService) GetClientInboundByEmail(email string) (traffic *xray.Cl
return nil, nil, nil
}
-func (s *InboundService) ToggleClientEnableByEmail(clientEmail string) (*xray.ClientTraffic, error) {
- traffic, inbound, err := s.GetClientInboundByEmail(clientEmail)
+func (s *InboundService) ToggleClientEnableByEmail(clientEmail string) (bool, error) {
+ _, inbound, err := s.GetClientInboundByEmail(clientEmail)
if err != nil {
- return nil, err
+ return false, err
}
- if inbound == nil || traffic == nil {
- return nil, common.NewError("Inbound Not Found For Email:", clientEmail)
+ if inbound == nil {
+ return false, common.NewError("Inbound Not Found For Email:", clientEmail)
}
oldClients, err := s.getClients(inbound)
if err != nil {
- return nil, err
+ return false, err
}
clientId := ""
+ clientOldEnabled := false
for _, oldClient := range oldClients {
if oldClient.Email == clientEmail {
@@ -702,45 +703,44 @@ func (s *InboundService) ToggleClientEnableByEmail(clientEmail string) (*xray.Cl
} else {
clientId = oldClient.ID
}
+ clientOldEnabled = oldClient.Enable
break
}
}
if len(clientId) == 0 {
- return nil, common.NewError("Client Not Found For Email:", clientEmail)
+ return false, common.NewError("Client Not Found For Email:", clientEmail)
}
- traffic.Enable = !traffic.Enable
-
var settings map[string]interface{}
err = json.Unmarshal([]byte(inbound.Settings), &settings)
if err != nil {
- return nil, err
+ return false, err
}
clients := settings["clients"].([]interface{})
var newClients []interface{}
for client_index := range clients {
c := clients[client_index].(map[string]interface{})
if c["email"] == clientEmail {
- c["enable"] = traffic.Enable
+ c["enable"] = !clientOldEnabled
newClients = append(newClients, interface{}(c))
}
}
settings["clients"] = newClients
modifiedSettings, err := json.MarshalIndent(settings, "", " ")
if err != nil {
- return nil, err
+ return false, err
}
inbound.Settings = string(modifiedSettings)
- return traffic, s.UpdateInboundClient(inbound, clientId)
+ return !clientOldEnabled, s.UpdateInboundClient(inbound, clientId)
}
func (s *InboundService) ResetClientIpLimitByEmail(clientEmail string, count int) error {
- traffic, inbound, err := s.GetClientInboundByEmail(clientEmail)
+ _, inbound, err := s.GetClientInboundByEmail(clientEmail)
if err != nil {
return err
}
- if inbound == nil || traffic == nil {
+ if inbound == nil {
return common.NewError("Inbound Not Found For Email:", clientEmail)
}
@@ -790,11 +790,11 @@ func (s *InboundService) ResetClientIpLimitByEmail(clientEmail string, count int
}
func (s *InboundService) ResetClientExpiryTimeByEmail(clientEmail string, expiry_time int64) error {
- traffic, inbound, err := s.GetClientInboundByEmail(clientEmail)
+ _, inbound, err := s.GetClientInboundByEmail(clientEmail)
if err != nil {
return err
}
- if inbound == nil || traffic == nil {
+ if inbound == nil {
return common.NewError("Inbound Not Found For Email:", clientEmail)
}
diff --git a/web/service/tgbot.go b/web/service/tgbot.go
index 8ff25dc0..0e5c4abb 100644
--- a/web/service/tgbot.go
+++ b/web/service/tgbot.go
@@ -296,10 +296,10 @@ func (t *Tgbot) asnwerCallback(callbackQuery *tgbotapi.CallbackQuery, isAdmin bo
t.sendCallbackAnswerTgBot(callbackQuery.ID, "āœ… %s : Get IP Log.")
t.searchClientIps(callbackQuery.From.ID, email)
case "toggle_enable":
- trrafic, err := t.inboundService.ToggleClientEnableByEmail(email)
+ enabled, err := t.inboundService.ToggleClientEnableByEmail(email)
if err == nil {
t.xrayService.SetToNeedRestart()
- if trrafic.Enable {
+ if enabled {
t.sendCallbackAnswerTgBot(callbackQuery.ID, fmt.Sprintf("āœ… %s : Enabled successfully.", email))
} else {
t.sendCallbackAnswerTgBot(callbackQuery.ID, fmt.Sprintf("āœ… %s : Disabled successfully.", email))
@@ -583,7 +583,7 @@ func (t *Tgbot) searchClientIps(chatId int64, email string, messageID ...int) {
if err != nil || len(ips) == 0 {
ips = "No IP Record"
}
- output := fmt.Sprintf("šŸ“§ Email: %s\r\nšŸ”¢ IPs: \r\n%s\r\n", email, ips)
+ output := fmt.Sprintf("šŸ“§ Email: %s\r\nšŸ”¢ IPs: \r\n\r\n%s\r\n", email, ips)
var inlineKeyboard = tgbotapi.NewInlineKeyboardMarkup(
tgbotapi.NewInlineKeyboardRow(
tgbotapi.NewInlineKeyboardButtonData("šŸ”„ Refresh", "ips_refresh "+email),
@@ -644,7 +644,7 @@ func (t *Tgbot) searchClient(chatId int64, email string, messageID ...int) {
tgbotapi.NewInlineKeyboardButtonData("šŸ”¢ IP Limit", "ip_limit "+email),
),
tgbotapi.NewInlineKeyboardRow(
- tgbotapi.NewInlineKeyboardButtonData("šŸ’” Enable / Disable", "toggle_enable "+email),
+ tgbotapi.NewInlineKeyboardButtonData("šŸ”˜ Enable / Disable", "toggle_enable "+email),
),
)
if len(messageID) > 0 {