From 961636b5106b0503051e2e6e63bc613397f170e3 Mon Sep 17 00:00:00 2001 From: Masoud Hidden Date: Fri, 5 May 2023 01:16:43 +0330 Subject: [PATCH 1/5] Client reset buttons for telegram bot --- web/service/inbound.go | 30 +++++++++++ web/service/tgbot.go | 113 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 140 insertions(+), 3 deletions(-) diff --git a/web/service/inbound.go b/web/service/inbound.go index c496086a..95c3d745 100644 --- a/web/service/inbound.go +++ b/web/service/inbound.go @@ -664,6 +664,36 @@ func (s *InboundService) DelClientIPs(tx *gorm.DB, email string) error { return tx.Where("client_email = ?", email).Delete(model.InboundClientIps{}).Error } +func (s *InboundService) ResetClientExpiryTimeByEmail(clientEmail string, expiry_time int64) error { + db := database.GetDB() + + result := db.Model(xray.ClientTraffic{}). + Where("email = ?", clientEmail). + Updates(map[string]interface{}{"enable": true, "expiry_time": expiry_time}) + + err := result.Error + + if err != nil { + return err + } + return nil +} + +func (s *InboundService) ResetClientTrafficByEmail(clientEmail string) error { + db := database.GetDB() + + result := db.Model(xray.ClientTraffic{}). + Where("email = ?", clientEmail). + Updates(map[string]interface{}{"enable": true, "up": 0, "down": 0}) + + err := result.Error + + if err != nil { + return err + } + return nil +} + func (s *InboundService) ResetClientTraffic(id int, clientEmail string) error { db := database.GetDB() diff --git a/web/service/tgbot.go b/web/service/tgbot.go index 4703c0ca..bd95bc81 100644 --- a/web/service/tgbot.go +++ b/web/service/tgbot.go @@ -148,6 +148,73 @@ func (t *Tgbot) answerCommand(message *tgbotapi.Message, chatId int64, isAdmin b } func (t *Tgbot) asnwerCallback(callbackQuery *tgbotapi.CallbackQuery, isAdmin bool) { + + if isAdmin { + dataArray := strings.Split(callbackQuery.Data, " ") + if len(dataArray) >= 2 && len(dataArray[1]) > 0 { + email := dataArray[1] + switch dataArray[0] { + case "admin_cancel": + t.sendCallbackAnswerTgBot(callbackQuery.ID, fmt.Sprintf("❌ %s : Operation canceled.", email)) + t.searchClient(callbackQuery.From.ID, email, callbackQuery.Message.MessageID) + case "reset_traffic": + var inlineKeyboard = tgbotapi.NewInlineKeyboardMarkup( + tgbotapi.NewInlineKeyboardRow( + tgbotapi.NewInlineKeyboardButtonData("❌ Cancel Reset", "admin_cancel "+email), + ), + tgbotapi.NewInlineKeyboardRow( + tgbotapi.NewInlineKeyboardButtonData("✅ Confirm Reset?", "reset_traffic_confirm "+email), + ), + ) + t.editMessageCallbackTgBot(callbackQuery.From.ID, callbackQuery.Message.MessageID, inlineKeyboard) + case "reset_traffic_confirm": + t.inboundService.ResetClientTrafficByEmail(email) + t.sendCallbackAnswerTgBot(callbackQuery.ID, fmt.Sprintf("✅ %s : Traffic reset successfully.", email)) + t.searchClient(callbackQuery.From.ID, email, callbackQuery.Message.MessageID) + case "reset_expire_days": + var inlineKeyboard = tgbotapi.NewInlineKeyboardMarkup( + tgbotapi.NewInlineKeyboardRow( + tgbotapi.NewInlineKeyboardButtonData("❌ Cancel Reset", "admin_cancel "+email), + ), + tgbotapi.NewInlineKeyboardRow( + tgbotapi.NewInlineKeyboardButtonData("1 Mounth", "reset_expire_days_confirm "+email+" 30"), + tgbotapi.NewInlineKeyboardButtonData("2 Mounth", "reset_expire_days_confirm "+email+" 60"), + ), + tgbotapi.NewInlineKeyboardRow( + tgbotapi.NewInlineKeyboardButtonData("3 Mounth", "reset_expire_days_confirm "+email+" 90"), + tgbotapi.NewInlineKeyboardButtonData("6 Mounth", "reset_expire_days_confirm "+email+" 180"), + ), + tgbotapi.NewInlineKeyboardRow( + tgbotapi.NewInlineKeyboardButtonData("9 Mounth", "reset_expire_days_confirm "+email+" 270"), + tgbotapi.NewInlineKeyboardButtonData("12 Mounth", "reset_expire_days_confirm "+email+" 360"), + ), + tgbotapi.NewInlineKeyboardRow( + tgbotapi.NewInlineKeyboardButtonData("10 Days", "reset_expire_days_confirm "+email+" 10"), + tgbotapi.NewInlineKeyboardButtonData("20 Days", "reset_expire_days_confirm "+email+" 20"), + ), + ) + t.editMessageCallbackTgBot(callbackQuery.From.ID, callbackQuery.Message.MessageID, inlineKeyboard) + case "reset_expire_days_confirm": + err := len(dataArray) < 3 + if !err { + days, error := strconv.Atoi(dataArray[2]) + if error == nil { + t.inboundService.ResetClientExpiryTimeByEmail(email, int64(-(days * 24 * 60 * 60000))) + t.sendCallbackAnswerTgBot(callbackQuery.ID, fmt.Sprintf("✅ %s : Expire days reset successfully.", email)) + t.searchClient(callbackQuery.From.ID, email, callbackQuery.Message.MessageID) + } else { + err = true + } + } + if err { + t.sendCallbackAnswerTgBot(callbackQuery.ID, "❗ Error in Operation.") + t.searchClient(callbackQuery.From.ID, email, callbackQuery.Message.MessageID) + } + } + return + } + } + // Respond to the callback query, telling Telegram to show the user // a message with the data received. callback := tgbotapi.NewCallback(callbackQuery.ID, callbackQuery.Data) @@ -215,7 +282,7 @@ func (t *Tgbot) SendAnswer(chatId int64, msg string, isAdmin bool) { } } -func (t *Tgbot) SendMsgToTgbot(tgid int64, msg string) { +func (t *Tgbot) SendMsgToTgbot(tgid int64, msg string, inlineKeyboard ...tgbotapi.InlineKeyboardMarkup) { var allMessages []string limit := 2000 // paging message if it is big @@ -236,6 +303,9 @@ func (t *Tgbot) SendMsgToTgbot(tgid int64, msg string) { for _, message := range allMessages { info := tgbotapi.NewMessage(tgid, message) info.ParseMode = "HTML" + if len(inlineKeyboard) > 0 { + info.ReplyMarkup = inlineKeyboard[0] + } _, err := bot.Send(info) if err != nil { logger.Warning("Error sending telegram message :", err) @@ -403,7 +473,7 @@ func (t *Tgbot) getClientUsage(chatId int64, tgUserName string) { t.SendAnswer(chatId, "Please choose:", false) } -func (t *Tgbot) searchClient(chatId int64, email string) { +func (t *Tgbot) searchClient(chatId int64, email string, messageID ...int) { traffic, err := t.inboundService.GetClientTrafficByEmail(email) if err != nil { logger.Warning(err) @@ -433,7 +503,19 @@ func (t *Tgbot) searchClient(chatId int64, email string) { output := fmt.Sprintf("💡 Active: %t\r\n📧 Email: %s\r\n🔼 Upload↑: %s\r\n🔽 Download↓: %s\r\n🔄 Total: %s / %s\r\n📅 Expire in: %s\r\n", traffic.Enable, traffic.Email, common.FormatTraffic(traffic.Up), common.FormatTraffic(traffic.Down), common.FormatTraffic((traffic.Up + traffic.Down)), total, expiryTime) - t.SendMsgToTgbot(chatId, output) + var inlineKeyboard = tgbotapi.NewInlineKeyboardMarkup( + tgbotapi.NewInlineKeyboardRow( + tgbotapi.NewInlineKeyboardButtonData("🔄 Reset Traffic", "reset_traffic "+email), + ), + tgbotapi.NewInlineKeyboardRow( + tgbotapi.NewInlineKeyboardButtonData("📅 Reset Expire Days", "reset_expire_days "+email), + ), + ) + if len(messageID) > 0 { + t.editMessageTgBot(chatId, messageID[0], output, inlineKeyboard) + } else { + t.SendMsgToTgbot(chatId, output, inlineKeyboard) + } } func (t *Tgbot) searchInbound(chatId int64, remark string) { @@ -608,3 +690,28 @@ func (t *Tgbot) sendBackup(chatId int64) { logger.Warning("Error in uploading config.json: ", err) } } + +func (t *Tgbot) sendCallbackAnswerTgBot(id string, message string) { + callback := tgbotapi.NewCallback(id, message) + if _, err := bot.Request(callback); err != nil { + logger.Warning(err) + } +} + +func (t *Tgbot) editMessageCallbackTgBot(chatId int64, messageID int, inlineKeyboard tgbotapi.InlineKeyboardMarkup) { + edit := tgbotapi.NewEditMessageReplyMarkup(chatId, messageID, inlineKeyboard) + if _, err := bot.Request(edit); err != nil { + logger.Warning(err) + } +} + +func (t *Tgbot) editMessageTgBot(chatId int64, messageID int, text string, inlineKeyboard ...tgbotapi.InlineKeyboardMarkup) { + edit := tgbotapi.NewEditMessageText(chatId, messageID, text) + edit.ParseMode = "HTML" + if len(inlineKeyboard) > 0 { + edit.ReplyMarkup = &inlineKeyboard[0] + } + if _, err := bot.Request(edit); err != nil { + logger.Warning(err) + } +} From ff33539fbadacea44ecb600e8da87c67e4dee877 Mon Sep 17 00:00:00 2001 From: Masoud Hidden Date: Fri, 5 May 2023 01:48:37 +0330 Subject: [PATCH 2/5] Refresh button for client report in telegram bot Added unlimited button for expire days. --- web/service/tgbot.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/web/service/tgbot.go b/web/service/tgbot.go index bd95bc81..73da6d9b 100644 --- a/web/service/tgbot.go +++ b/web/service/tgbot.go @@ -154,6 +154,9 @@ func (t *Tgbot) asnwerCallback(callbackQuery *tgbotapi.CallbackQuery, isAdmin bo if len(dataArray) >= 2 && len(dataArray[1]) > 0 { email := dataArray[1] switch dataArray[0] { + case "refresh_client": + t.sendCallbackAnswerTgBot(callbackQuery.ID, fmt.Sprintf("✅ %s : Refreshed successfully.", email)) + t.searchClient(callbackQuery.From.ID, email, callbackQuery.Message.MessageID) case "admin_cancel": t.sendCallbackAnswerTgBot(callbackQuery.ID, fmt.Sprintf("❌ %s : Operation canceled.", email)) t.searchClient(callbackQuery.From.ID, email, callbackQuery.Message.MessageID) @@ -176,6 +179,9 @@ func (t *Tgbot) asnwerCallback(callbackQuery *tgbotapi.CallbackQuery, isAdmin bo tgbotapi.NewInlineKeyboardRow( tgbotapi.NewInlineKeyboardButtonData("❌ Cancel Reset", "admin_cancel "+email), ), + tgbotapi.NewInlineKeyboardRow( + tgbotapi.NewInlineKeyboardButtonData("♾ Unlimited", "reset_expire_days_confirm "+email+" 0"), + ), tgbotapi.NewInlineKeyboardRow( tgbotapi.NewInlineKeyboardButtonData("1 Mounth", "reset_expire_days_confirm "+email+" 30"), tgbotapi.NewInlineKeyboardButtonData("2 Mounth", "reset_expire_days_confirm "+email+" 60"), @@ -199,7 +205,11 @@ func (t *Tgbot) asnwerCallback(callbackQuery *tgbotapi.CallbackQuery, isAdmin bo if !err { days, error := strconv.Atoi(dataArray[2]) if error == nil { - t.inboundService.ResetClientExpiryTimeByEmail(email, int64(-(days * 24 * 60 * 60000))) + var date int64 = 0 + if days > 0 { + date = int64(-(days * 24 * 60 * 60000)) + } + t.inboundService.ResetClientExpiryTimeByEmail(email, date) t.sendCallbackAnswerTgBot(callbackQuery.ID, fmt.Sprintf("✅ %s : Expire days reset successfully.", email)) t.searchClient(callbackQuery.From.ID, email, callbackQuery.Message.MessageID) } else { @@ -505,7 +515,10 @@ func (t *Tgbot) searchClient(chatId int64, email string, messageID ...int) { total, expiryTime) var inlineKeyboard = tgbotapi.NewInlineKeyboardMarkup( tgbotapi.NewInlineKeyboardRow( - tgbotapi.NewInlineKeyboardButtonData("🔄 Reset Traffic", "reset_traffic "+email), + tgbotapi.NewInlineKeyboardButtonData("🔄 Refresh", "refresh_client "+email), + ), + tgbotapi.NewInlineKeyboardRow( + tgbotapi.NewInlineKeyboardButtonData("📈 Reset Traffic", "reset_traffic "+email), ), tgbotapi.NewInlineKeyboardRow( tgbotapi.NewInlineKeyboardButtonData("📅 Reset Expire Days", "reset_expire_days "+email), From 4b3bdebfa50098b435e98fdf801e79b0b55128fc Mon Sep 17 00:00:00 2001 From: Masoud Hidden Date: Fri, 5 May 2023 02:14:56 +0330 Subject: [PATCH 3/5] Fix typo --- web/service/tgbot.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/web/service/tgbot.go b/web/service/tgbot.go index 73da6d9b..fe9b1d35 100644 --- a/web/service/tgbot.go +++ b/web/service/tgbot.go @@ -166,7 +166,7 @@ func (t *Tgbot) asnwerCallback(callbackQuery *tgbotapi.CallbackQuery, isAdmin bo tgbotapi.NewInlineKeyboardButtonData("❌ Cancel Reset", "admin_cancel "+email), ), tgbotapi.NewInlineKeyboardRow( - tgbotapi.NewInlineKeyboardButtonData("✅ Confirm Reset?", "reset_traffic_confirm "+email), + tgbotapi.NewInlineKeyboardButtonData("✅ Confirm Reset Traffic?", "reset_traffic_confirm "+email), ), ) t.editMessageCallbackTgBot(callbackQuery.From.ID, callbackQuery.Message.MessageID, inlineKeyboard) @@ -183,16 +183,16 @@ func (t *Tgbot) asnwerCallback(callbackQuery *tgbotapi.CallbackQuery, isAdmin bo tgbotapi.NewInlineKeyboardButtonData("♾ Unlimited", "reset_expire_days_confirm "+email+" 0"), ), tgbotapi.NewInlineKeyboardRow( - tgbotapi.NewInlineKeyboardButtonData("1 Mounth", "reset_expire_days_confirm "+email+" 30"), - tgbotapi.NewInlineKeyboardButtonData("2 Mounth", "reset_expire_days_confirm "+email+" 60"), + tgbotapi.NewInlineKeyboardButtonData("1 Month", "reset_expire_days_confirm "+email+" 30"), + tgbotapi.NewInlineKeyboardButtonData("2 Month", "reset_expire_days_confirm "+email+" 60"), ), tgbotapi.NewInlineKeyboardRow( - tgbotapi.NewInlineKeyboardButtonData("3 Mounth", "reset_expire_days_confirm "+email+" 90"), - tgbotapi.NewInlineKeyboardButtonData("6 Mounth", "reset_expire_days_confirm "+email+" 180"), + tgbotapi.NewInlineKeyboardButtonData("3 Month", "reset_expire_days_confirm "+email+" 90"), + tgbotapi.NewInlineKeyboardButtonData("6 Month", "reset_expire_days_confirm "+email+" 180"), ), tgbotapi.NewInlineKeyboardRow( - tgbotapi.NewInlineKeyboardButtonData("9 Mounth", "reset_expire_days_confirm "+email+" 270"), - tgbotapi.NewInlineKeyboardButtonData("12 Mounth", "reset_expire_days_confirm "+email+" 360"), + tgbotapi.NewInlineKeyboardButtonData("9 Month", "reset_expire_days_confirm "+email+" 270"), + tgbotapi.NewInlineKeyboardButtonData("12 Month", "reset_expire_days_confirm "+email+" 360"), ), tgbotapi.NewInlineKeyboardRow( tgbotapi.NewInlineKeyboardButtonData("10 Days", "reset_expire_days_confirm "+email+" 10"), From c6295085fe73fa1b2a168e02083ffadbdb4dedf6 Mon Sep 17 00:00:00 2001 From: Masoud Hidden Date: Fri, 5 May 2023 02:47:26 +0330 Subject: [PATCH 4/5] Fix restart service --- web/service/tgbot.go | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/web/service/tgbot.go b/web/service/tgbot.go index fe9b1d35..ef5d2abd 100644 --- a/web/service/tgbot.go +++ b/web/service/tgbot.go @@ -31,6 +31,7 @@ type Tgbot struct { inboundService InboundService settingService SettingService serverService ServerService + xrayService XrayService lastStatus *Status } @@ -171,9 +172,14 @@ func (t *Tgbot) asnwerCallback(callbackQuery *tgbotapi.CallbackQuery, isAdmin bo ) t.editMessageCallbackTgBot(callbackQuery.From.ID, callbackQuery.Message.MessageID, inlineKeyboard) case "reset_traffic_confirm": - t.inboundService.ResetClientTrafficByEmail(email) - t.sendCallbackAnswerTgBot(callbackQuery.ID, fmt.Sprintf("✅ %s : Traffic reset successfully.", email)) - t.searchClient(callbackQuery.From.ID, email, callbackQuery.Message.MessageID) + resetError := t.inboundService.ResetClientTrafficByEmail(email) + if resetError == nil { + t.xrayService.SetToNeedRestart() + t.sendCallbackAnswerTgBot(callbackQuery.ID, fmt.Sprintf("✅ %s : Traffic reset successfully.", email)) + t.searchClient(callbackQuery.From.ID, email, callbackQuery.Message.MessageID) + } else { + t.sendCallbackAnswerTgBot(callbackQuery.ID, "❗ Error in Operation.") + } case "reset_expire_days": var inlineKeyboard = tgbotapi.NewInlineKeyboardMarkup( tgbotapi.NewInlineKeyboardRow( @@ -184,15 +190,15 @@ func (t *Tgbot) asnwerCallback(callbackQuery *tgbotapi.CallbackQuery, isAdmin bo ), tgbotapi.NewInlineKeyboardRow( tgbotapi.NewInlineKeyboardButtonData("1 Month", "reset_expire_days_confirm "+email+" 30"), - tgbotapi.NewInlineKeyboardButtonData("2 Month", "reset_expire_days_confirm "+email+" 60"), + tgbotapi.NewInlineKeyboardButtonData("2 Months", "reset_expire_days_confirm "+email+" 60"), ), tgbotapi.NewInlineKeyboardRow( - tgbotapi.NewInlineKeyboardButtonData("3 Month", "reset_expire_days_confirm "+email+" 90"), - tgbotapi.NewInlineKeyboardButtonData("6 Month", "reset_expire_days_confirm "+email+" 180"), + tgbotapi.NewInlineKeyboardButtonData("3 Months", "reset_expire_days_confirm "+email+" 90"), + tgbotapi.NewInlineKeyboardButtonData("6 Months", "reset_expire_days_confirm "+email+" 180"), ), tgbotapi.NewInlineKeyboardRow( - tgbotapi.NewInlineKeyboardButtonData("9 Month", "reset_expire_days_confirm "+email+" 270"), - tgbotapi.NewInlineKeyboardButtonData("12 Month", "reset_expire_days_confirm "+email+" 360"), + tgbotapi.NewInlineKeyboardButtonData("9 Months", "reset_expire_days_confirm "+email+" 270"), + tgbotapi.NewInlineKeyboardButtonData("12 Months", "reset_expire_days_confirm "+email+" 360"), ), tgbotapi.NewInlineKeyboardRow( tgbotapi.NewInlineKeyboardButtonData("10 Days", "reset_expire_days_confirm "+email+" 10"), @@ -203,15 +209,18 @@ func (t *Tgbot) asnwerCallback(callbackQuery *tgbotapi.CallbackQuery, isAdmin bo case "reset_expire_days_confirm": err := len(dataArray) < 3 if !err { - days, error := strconv.Atoi(dataArray[2]) - if error == nil { + days, err2 := strconv.Atoi(dataArray[2]) + if err2 == nil { var date int64 = 0 if days > 0 { date = int64(-(days * 24 * 60 * 60000)) } - t.inboundService.ResetClientExpiryTimeByEmail(email, date) - t.sendCallbackAnswerTgBot(callbackQuery.ID, fmt.Sprintf("✅ %s : Expire days reset successfully.", email)) - t.searchClient(callbackQuery.From.ID, email, callbackQuery.Message.MessageID) + resetError := t.inboundService.ResetClientExpiryTimeByEmail(email, date) + if resetError == nil { + t.xrayService.SetToNeedRestart() + t.sendCallbackAnswerTgBot(callbackQuery.ID, fmt.Sprintf("✅ %s : Expire days reset successfully.", email)) + t.searchClient(callbackQuery.From.ID, email, callbackQuery.Message.MessageID) + } } else { err = true } From a53d2b927fdc4f543589750d761428f591cabaf7 Mon Sep 17 00:00:00 2001 From: Masoud Hidden Date: Fri, 5 May 2023 04:34:39 +0330 Subject: [PATCH 5/5] fix ResetClientExpiryTimeByEmail --- web/service/inbound.go | 69 +++++++++++++++++++++++++++++++++++++----- web/service/tgbot.go | 24 ++++++--------- 2 files changed, 71 insertions(+), 22 deletions(-) diff --git a/web/service/inbound.go b/web/service/inbound.go index 95c3d745..5d80c816 100644 --- a/web/service/inbound.go +++ b/web/service/inbound.go @@ -664,19 +664,72 @@ func (s *InboundService) DelClientIPs(tx *gorm.DB, email string) error { return tx.Where("client_email = ?", email).Delete(model.InboundClientIps{}).Error } -func (s *InboundService) ResetClientExpiryTimeByEmail(clientEmail string, expiry_time int64) error { +func (s *InboundService) GetClientInboundByEmail(email string) (inbound *model.Inbound, err error) { db := database.GetDB() + var traffics []*xray.ClientTraffic + err = db.Model(xray.ClientTraffic{}).Where("email = ?", email).Find(&traffics).Error + if err != nil { + logger.Warning(err) + return nil, err + } + if len(traffics) > 0 { + return s.GetInbound(traffics[0].InboundId) + } + return nil, nil +} - result := db.Model(xray.ClientTraffic{}). - Where("email = ?", clientEmail). - Updates(map[string]interface{}{"enable": true, "expiry_time": expiry_time}) - - err := result.Error - +func (s *InboundService) ResetClientExpiryTimeByEmail(clientEmail string, expiry_time int64) error { + inbound, err := s.GetClientInboundByEmail(clientEmail) if err != nil { return err } - return nil + if inbound == nil { + return common.NewError("Inbound Not Found For Email:", clientEmail) + } + + oldClients, err := s.getClients(inbound) + if err != nil { + return err + } + + clientId := "" + + for _, oldClient := range oldClients { + if oldClient.Email == clientEmail { + if inbound.Protocol == "trojan" { + clientId = oldClient.Password + } else { + clientId = oldClient.ID + } + break + } + } + + if len(clientId) == 0 { + return common.NewError("Client Not Found For Email:", clientEmail) + } + + var settings map[string]interface{} + err = json.Unmarshal([]byte(inbound.Settings), &settings) + if err != nil { + return 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["expiryTime"] = expiry_time + newClients = append(newClients, interface{}(c)) + } + } + settings["clients"] = newClients + modifiedSettings, err := json.MarshalIndent(settings, "", " ") + if err != nil { + return err + } + inbound.Settings = string(modifiedSettings) + return s.UpdateInboundClient(inbound, clientId) } func (s *InboundService) ResetClientTrafficByEmail(clientEmail string) error { diff --git a/web/service/tgbot.go b/web/service/tgbot.go index ef5d2abd..eca082b5 100644 --- a/web/service/tgbot.go +++ b/web/service/tgbot.go @@ -172,8 +172,8 @@ func (t *Tgbot) asnwerCallback(callbackQuery *tgbotapi.CallbackQuery, isAdmin bo ) t.editMessageCallbackTgBot(callbackQuery.From.ID, callbackQuery.Message.MessageID, inlineKeyboard) case "reset_traffic_confirm": - resetError := t.inboundService.ResetClientTrafficByEmail(email) - if resetError == nil { + err := t.inboundService.ResetClientTrafficByEmail(email) + if err == nil { t.xrayService.SetToNeedRestart() t.sendCallbackAnswerTgBot(callbackQuery.ID, fmt.Sprintf("✅ %s : Traffic reset successfully.", email)) t.searchClient(callbackQuery.From.ID, email, callbackQuery.Message.MessageID) @@ -207,28 +207,24 @@ func (t *Tgbot) asnwerCallback(callbackQuery *tgbotapi.CallbackQuery, isAdmin bo ) t.editMessageCallbackTgBot(callbackQuery.From.ID, callbackQuery.Message.MessageID, inlineKeyboard) case "reset_expire_days_confirm": - err := len(dataArray) < 3 - if !err { - days, err2 := strconv.Atoi(dataArray[2]) - if err2 == nil { + if len(dataArray) == 3 { + days, err := strconv.Atoi(dataArray[2]) + if err == nil { var date int64 = 0 if days > 0 { date = int64(-(days * 24 * 60 * 60000)) } - resetError := t.inboundService.ResetClientExpiryTimeByEmail(email, date) - if resetError == nil { + err := t.inboundService.ResetClientExpiryTimeByEmail(email, date) + if err == nil { t.xrayService.SetToNeedRestart() t.sendCallbackAnswerTgBot(callbackQuery.ID, fmt.Sprintf("✅ %s : Expire days reset successfully.", email)) t.searchClient(callbackQuery.From.ID, email, callbackQuery.Message.MessageID) + return } - } else { - err = true } } - if err { - t.sendCallbackAnswerTgBot(callbackQuery.ID, "❗ Error in Operation.") - t.searchClient(callbackQuery.From.ID, email, callbackQuery.Message.MessageID) - } + t.sendCallbackAnswerTgBot(callbackQuery.ID, "❗ Error in Operation.") + t.searchClient(callbackQuery.From.ID, email, callbackQuery.Message.MessageID) } return }