fix(tgbot): Only show usage command for admins

Signed-off-by: Ahmad Thoriq Najahi <najahi@zephyrus.id>
This commit is contained in:
Ahmad Thoriq Najahi 2024-10-15 04:29:48 +07:00
parent d89d8ece72
commit 22de381e54
No known key found for this signature in database
GPG key ID: F1F4FA115DADBD90

View file

@ -282,19 +282,26 @@ func (t *Tgbot) answerCommand(message *telego.Message, chatId int64, isAdmin boo
} }
case "restart": case "restart":
onlyMessage = true onlyMessage = true
if isAdmin && len(commandArgs) > 0 && commandArgs[0] == "force" { if isAdmin && len(commandArgs) == 0 {
if t.xrayService.IsXrayRunning() { msg += t.I18nBot("tgbot.commands.unknown")
err := t.xrayService.RestartXray(true) msg += t.I18nBot("tgbot.commands.restartUsage")
msg += t.I18nBot("tgbot.commands.restartSuccess") } else if isAdmin && len(commandArgs) > 0 {
if err != nil { if strings.ToLower(commandArgs[0]) == "force" {
msg += t.I18nBot("tgbot.commands.restartFailed", "Error=="+err.Error()) if t.xrayService.IsXrayRunning() {
err := t.xrayService.RestartXray(true)
msg += t.I18nBot("tgbot.commands.restartSuccess")
if err != nil {
msg += t.I18nBot("tgbot.commands.restartFailed", "Error=="+err.Error())
}
} else {
msg += t.I18nBot("tgbot.commands.xrayNotRunning")
} }
} else { } else {
msg += t.I18nBot("tgbot.commands.xrayNotRunning") msg += t.I18nBot("tgbot.commands.unknown")
msg += t.I18nBot("tgbot.commands.restartUsage")
} }
} else { } else {
msg += t.I18nBot("tgbot.commands.unknown") msg += t.I18nBot("tgbot.commands.unknown")
msg += t.I18nBot("tgbot.commands.restartUsage")
} }
default: default:
msg += t.I18nBot("tgbot.commands.unknown") msg += t.I18nBot("tgbot.commands.unknown")
@ -888,6 +895,7 @@ func (t *Tgbot) SendAnswer(chatId int64, msg string, isAdmin bool) {
tu.InlineKeyboardButton(t.I18nBot("tgbot.buttons.onlines")).WithCallbackData(t.encodeQuery("onlines")), tu.InlineKeyboardButton(t.I18nBot("tgbot.buttons.onlines")).WithCallbackData(t.encodeQuery("onlines")),
tu.InlineKeyboardButton(t.I18nBot("tgbot.buttons.allClients")).WithCallbackData(t.encodeQuery("get_inbounds")), tu.InlineKeyboardButton(t.I18nBot("tgbot.buttons.allClients")).WithCallbackData(t.encodeQuery("get_inbounds")),
), ),
// TODOOOOOOOOOOOOOO: Add restart button here.
) )
numericKeyboardClient := tu.InlineKeyboard( numericKeyboardClient := tu.InlineKeyboard(
tu.InlineKeyboardRow( tu.InlineKeyboardRow(