Fix restart service

This commit is contained in:
Masoud Hidden 2023-05-05 02:47:26 +03:30
parent 4b3bdebfa5
commit c6295085fe

View file

@ -31,6 +31,7 @@ type Tgbot struct {
inboundService InboundService inboundService InboundService
settingService SettingService settingService SettingService
serverService ServerService serverService ServerService
xrayService XrayService
lastStatus *Status lastStatus *Status
} }
@ -171,9 +172,14 @@ func (t *Tgbot) asnwerCallback(callbackQuery *tgbotapi.CallbackQuery, isAdmin bo
) )
t.editMessageCallbackTgBot(callbackQuery.From.ID, callbackQuery.Message.MessageID, inlineKeyboard) t.editMessageCallbackTgBot(callbackQuery.From.ID, callbackQuery.Message.MessageID, inlineKeyboard)
case "reset_traffic_confirm": case "reset_traffic_confirm":
t.inboundService.ResetClientTrafficByEmail(email) resetError := t.inboundService.ResetClientTrafficByEmail(email)
if resetError == nil {
t.xrayService.SetToNeedRestart()
t.sendCallbackAnswerTgBot(callbackQuery.ID, fmt.Sprintf("✅ %s : Traffic reset successfully.", email)) t.sendCallbackAnswerTgBot(callbackQuery.ID, fmt.Sprintf("✅ %s : Traffic reset successfully.", email))
t.searchClient(callbackQuery.From.ID, email, callbackQuery.Message.MessageID) t.searchClient(callbackQuery.From.ID, email, callbackQuery.Message.MessageID)
} else {
t.sendCallbackAnswerTgBot(callbackQuery.ID, "❗ Error in Operation.")
}
case "reset_expire_days": case "reset_expire_days":
var inlineKeyboard = tgbotapi.NewInlineKeyboardMarkup( var inlineKeyboard = tgbotapi.NewInlineKeyboardMarkup(
tgbotapi.NewInlineKeyboardRow( tgbotapi.NewInlineKeyboardRow(
@ -184,15 +190,15 @@ func (t *Tgbot) asnwerCallback(callbackQuery *tgbotapi.CallbackQuery, isAdmin bo
), ),
tgbotapi.NewInlineKeyboardRow( tgbotapi.NewInlineKeyboardRow(
tgbotapi.NewInlineKeyboardButtonData("1 Month", "reset_expire_days_confirm "+email+" 30"), 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.NewInlineKeyboardRow(
tgbotapi.NewInlineKeyboardButtonData("3 Month", "reset_expire_days_confirm "+email+" 90"), tgbotapi.NewInlineKeyboardButtonData("3 Months", "reset_expire_days_confirm "+email+" 90"),
tgbotapi.NewInlineKeyboardButtonData("6 Month", "reset_expire_days_confirm "+email+" 180"), tgbotapi.NewInlineKeyboardButtonData("6 Months", "reset_expire_days_confirm "+email+" 180"),
), ),
tgbotapi.NewInlineKeyboardRow( tgbotapi.NewInlineKeyboardRow(
tgbotapi.NewInlineKeyboardButtonData("9 Month", "reset_expire_days_confirm "+email+" 270"), tgbotapi.NewInlineKeyboardButtonData("9 Months", "reset_expire_days_confirm "+email+" 270"),
tgbotapi.NewInlineKeyboardButtonData("12 Month", "reset_expire_days_confirm "+email+" 360"), tgbotapi.NewInlineKeyboardButtonData("12 Months", "reset_expire_days_confirm "+email+" 360"),
), ),
tgbotapi.NewInlineKeyboardRow( tgbotapi.NewInlineKeyboardRow(
tgbotapi.NewInlineKeyboardButtonData("10 Days", "reset_expire_days_confirm "+email+" 10"), 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": case "reset_expire_days_confirm":
err := len(dataArray) < 3 err := len(dataArray) < 3
if !err { if !err {
days, error := strconv.Atoi(dataArray[2]) days, err2 := strconv.Atoi(dataArray[2])
if error == nil { if err2 == nil {
var date int64 = 0 var date int64 = 0
if days > 0 { if days > 0 {
date = int64(-(days * 24 * 60 * 60000)) date = int64(-(days * 24 * 60 * 60000))
} }
t.inboundService.ResetClientExpiryTimeByEmail(email, date) 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.sendCallbackAnswerTgBot(callbackQuery.ID, fmt.Sprintf("✅ %s : Expire days reset successfully.", email))
t.searchClient(callbackQuery.From.ID, email, callbackQuery.Message.MessageID) t.searchClient(callbackQuery.From.ID, email, callbackQuery.Message.MessageID)
}
} else { } else {
err = true err = true
} }