feat(tgbot): Allow restart core via telegram bot

Signed-off-by: Ahmad Thoriq Najahi <najahi@zephyrus.id>
This commit is contained in:
Ahmad Thoriq Najahi 2024-10-12 04:40:20 +07:00
parent f98d78c356
commit b25f7c2ae5
No known key found for this signature in database
GPG key ID: F1F4FA115DADBD90
3 changed files with 24 additions and 0 deletions

View file

@ -280,6 +280,22 @@ func (t *Tgbot) answerCommand(message *telego.Message, chatId int64, isAdmin boo
} else {
msg += t.I18nBot("tgbot.commands.unknown")
}
case "restart":
onlyMessage = true
if isAdmin && len(commandArgs) > 0 && commandArgs[0] == "force" {
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 {
msg += t.I18nBot("tgbot.commands.unknown")
msg += t.I18nBot("tgbot.commands.restartUsage")
}
default:
msg += t.I18nBot("tgbot.commands.unknown")
}

View file

@ -485,6 +485,10 @@
"getID" = "🆔 Your ID: <code>{{ .ID }}</code>"
"helpAdminCommands" = "To search for a client email:\r\n<code>/usage [Email]</code>\r\n\r\nTo search for inbounds (with client stats):\r\n<code>/inbound [Remark]</code>\r\n\r\nTelegram Chat ID:\r\n<code>/id</code>"
"helpClientCommands" = "To search for statistics, use the following command:\r\n\r\n<code>/usage [Email]</code>\r\n\r\nTelegram Chat ID:\r\n<code>/id</code>"
"restartUsage" = "\r\n\r\n<code>/restart force</code>"
"restartSuccess" = "✅ Operation successful!"
"restartFailed" = "❗ Error in operation.\r\n\r\n<code>Error: {{.Error }}</code>."
"xrayNotRunning" = "❗ Xray Core is not running."
[tgbot.messages]
"cpuThreshold" = "🔴 CPU Load {{ .Percent }}% exceeds the threshold of {{ .Threshold }}%"

View file

@ -485,6 +485,10 @@
"getID" = "🆔 ID Anda:<code>{{.ID }}</code>"
"helpAdminCommands" = "Untuk mencari email klien:\r\n<code>/usage [Email]</code>\r\n\r\nUntuk mencari inbound (dengan statistik klien):\r\n<code>/inbound [Catatan]</code>\r\n\r\nID Obrolan Telegram:\r\n<code>/id</code>"
"helpClientCommands" = "Untuk mencari statistik, gunakan perintah berikut:\r\n<code>/usage [Email]</code>\r\n\r\nID Obrolan Telegram:\r\n<code>/id</code>"
"restartUsage" = "\r\n\r\n<code>/restart force</code>"
"restartSuccess" = "✅ Operasi berhasil!"
"restartFailed" = "❗ Kesalahan dalam operasi.\r\n\r\n<code>Error: {{.Error }}</code>."
"xrayNotRunning" = "❗ Xray Core tidak berjalan."
[tgbot.messages]
"cpuThreshold" = "🔴 Beban CPU {{ .Percent }}% melebihi batas {{ .Threshold }}%"