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,7 +282,11 @@ func (t *Tgbot) answerCommand(message *telego.Message, chatId int64, isAdmin boo
}
case "restart":
onlyMessage = true
if isAdmin && len(commandArgs) > 0 && commandArgs[0] == "force" {
if isAdmin && len(commandArgs) == 0 {
msg += t.I18nBot("tgbot.commands.unknown")
msg += t.I18nBot("tgbot.commands.restartUsage")
} else if isAdmin && len(commandArgs) > 0 {
if strings.ToLower(commandArgs[0]) == "force" {
if t.xrayService.IsXrayRunning() {
err := t.xrayService.RestartXray(true)
msg += t.I18nBot("tgbot.commands.restartSuccess")
@ -296,6 +300,9 @@ func (t *Tgbot) answerCommand(message *telego.Message, chatId int64, isAdmin boo
msg += t.I18nBot("tgbot.commands.unknown")
msg += t.I18nBot("tgbot.commands.restartUsage")
}
} else {
msg += t.I18nBot("tgbot.commands.unknown")
}
default:
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.allClients")).WithCallbackData(t.encodeQuery("get_inbounds")),
),
// TODOOOOOOOOOOOOOO: Add restart button here.
)
numericKeyboardClient := tu.InlineKeyboard(
tu.InlineKeyboardRow(