1
0
Эх сурвалжийг харах

feat: add command list in telegram bot (#3027)

spatiumstas 1 өдөр өмнө
parent
commit
29f950046a

+ 14 - 1
web/service/tgbot.go

@@ -147,6 +147,19 @@ func (t *Tgbot) Start(i18nFS embed.FS) error {
 		return err
 	}
 
+	// After bot initialization, set up bot commands with localized descriptions
+	err = bot.SetMyCommands(&telego.SetMyCommandsParams{
+		Commands: []telego.BotCommand{
+			{Command: "start", Description: t.I18nBot("tgbot.commands.startDesc")},
+			{Command: "help", Description: t.I18nBot("tgbot.commands.helpDesc")},
+			{Command: "status", Description: t.I18nBot("tgbot.commands.statusDesc")},
+			{Command: "id", Description: t.I18nBot("tgbot.commands.idDesc")},
+		},
+	})
+	if err != nil {
+		logger.Warning("Failed to set bot commands:", err)
+	}
+
 	// Start receiving Telegram bot messages
 	if !isRunning {
 		logger.Info("Telegram bot receiver started")
@@ -935,7 +948,7 @@ func (t *Tgbot) answerCallback(callbackQuery *telego.CallbackQuery, isAdmin bool
 								tu.InlineKeyboardButton(t.I18nBot("tgbot.buttons.cancel")).WithCallbackData(t.encodeQuery("add_client_default_traffic_exp")),
 							),
 							tu.InlineKeyboardRow(
-								tu.InlineKeyboardButton(t.I18nBot("tgbot.buttons.confirmNumber", "Num=="+strconv.Itoa(inputNumber))).WithCallbackData(t.encodeQuery("add_client_reset_exp_c "+strconv.Itoa(inputNumber))),
+								tu.InlineKeyboardButton(t.I18nBot("tgbot.buttons.confirmNumberAdd", "Num=="+strconv.Itoa(inputNumber))).WithCallbackData(t.encodeQuery("add_client_reset_exp_c "+strconv.Itoa(inputNumber))),
 							),
 							tu.InlineKeyboardRow(
 								tu.InlineKeyboardButton("1").WithCallbackData(t.encodeQuery("add_client_reset_exp_in "+strconv.Itoa(inputNumber)+" 1")),

+ 4 - 0
web/translation/translate.ar_EG.toml

@@ -588,6 +588,10 @@
 "restartSuccess" = "✅ العملية نجحت!"
 "restartFailed" = "❗ حصل خطأ في العملية.\r\n\r\n<code>Error: {{ .Error }}</code>."
 "xrayNotRunning" = "❗ Xray Core مش شغال."
+"startDesc" = "عرض القائمة الرئيسية"
+"helpDesc" = "مساعدة البوت"
+"statusDesc" = "التحقق من حالة البوت"
+"idDesc" = "عرض معرف Telegram الخاص بك"
 
 [tgbot.messages]
 "cpuThreshold" = "🔴 حمل المعالج {{ .Percent }}% عدى الحد المسموح ({{ .Threshold }}%)"

+ 5 - 1
web/translation/translate.en_US.toml

@@ -339,7 +339,7 @@
 "subEnable" = "Enable Subscription Service"
 "subEnableDesc" = "Enables the subscription service."
 "subTitle" = "Subscription Title"
- "subTitleDesc" = "Title shown in VPN client"
+"subTitleDesc" = "Title shown in VPN client"
 "subListen" = "Listen IP"
 "subListenDesc" = "The IP address for the subscription service. (leave blank to listen on all IPs)"
 "subPort" = "Listen Port"
@@ -587,6 +587,10 @@
 "restartSuccess" = "✅ Operation successful!"
 "restartFailed" = "❗ Error in operation.\r\n\r\n<code>Error: {{ .Error }}</code>."
 "xrayNotRunning" = "❗ Xray Core is not running."
+"startDesc" = "Show the main menu"
+"helpDesc" = "Bot help"
+"statusDesc" = "Check bot status"
+"idDesc" = "Show your Telegram ID"
 
 [tgbot.messages]
 "cpuThreshold" = "🔴 CPU Load {{ .Percent }}% exceeds the threshold of {{ .Threshold }}%"

+ 4 - 0
web/translation/translate.es_ES.toml

@@ -590,6 +590,10 @@
 "restartSuccess" = "✅ ¡Operación exitosa!"
 "restartFailed" = "❗ Error en la operación.\r\n\r\n<code>Error: {{ .Error }}</code>."
 "xrayNotRunning" = "❗ Xray Core no está en ejecución."
+"startDesc" = "Mostrar el menú principal"
+"helpDesc" = "Ayuda del bot"
+"statusDesc" = "Comprobar el estado del bot"
+"idDesc" = "Mostrar tu ID de Telegram"
 
 [tgbot.messages]
 "cpuThreshold" = "🔴 El uso de CPU {{ .Percent }}% es mayor que el umbral {{ .Threshold }}%"

+ 4 - 0
web/translation/translate.fa_IR.toml

@@ -590,6 +590,10 @@
 "restartSuccess" = "✅ عملیات با موفقیت انجام شد!"
 "restartFailed" = "❗ خطا در عملیات.\r\n\r\n<code>خطا: {{ .Error }}</code>."
 "xrayNotRunning" = "❗ Xray Core در حال اجرا نیست."
+"startDesc" = "نمایش منوی اصلی"
+"helpDesc" = "راهنمای ربات"
+"statusDesc" = "بررسی وضعیت ربات"
+"idDesc" = "نمایش شناسه تلگرام شما"
 
 [tgbot.messages]
 "cpuThreshold" = "🔴 بار ‌پردازنده {{ .Percent }}% بیشتر از آستانه است {{ .Threshold }}%"

+ 4 - 0
web/translation/translate.id_ID.toml

@@ -590,6 +590,10 @@
 "restartSuccess" = "✅ Operasi berhasil!"
 "restartFailed" = "❗ Kesalahan dalam operasi.\r\n\r\n<code>Error: {{ .Error }}</code>."
 "xrayNotRunning" = "❗ Xray Core tidak berjalan."
+"startDesc" = "Tampilkan menu utama"
+"helpDesc" = "Bantuan bot"
+"statusDesc" = "Periksa status bot"
+"idDesc" = "Tampilkan ID Telegram Anda"
 
 [tgbot.messages]
 "cpuThreshold" = "🔴 Beban CPU {{ .Percent }}% melebihi batas {{ .Threshold }}%"

+ 4 - 0
web/translation/translate.ja_JP.toml

@@ -590,6 +590,10 @@
 "restartSuccess" = "✅ 操作成功!"
 "restartFailed" = "❗ 操作エラー。\r\n\r\n<code>エラー: {{ .Error }}</code>"
 "xrayNotRunning" = "❗ Xray Core は動作していません。"
+"startDesc" = "メインメニューを表示"
+"helpDesc" = "ボットのヘルプ"
+"statusDesc" = "ボットの状態を確認"
+"idDesc" = "Telegram IDを表示"
 
 [tgbot.messages]
 "cpuThreshold" = "🔴 CPU使用率は{{ .Percent }}%、しきい値{{ .Threshold }}%を超えました"

+ 4 - 0
web/translation/translate.pt_BR.toml

@@ -590,6 +590,10 @@
 "restartSuccess" = "✅ Operação bem-sucedida!"
 "restartFailed" = "❗ Erro na operação.\r\n\r\n<code>Erro: {{ .Error }}</code>."
 "xrayNotRunning" = "❗ Xray Core não está em execução."
+"startDesc" = "Mostrar menu principal"
+"helpDesc" = "Ajuda do bot"
+"statusDesc" = "Verificar status do bot"
+"idDesc" = "Mostrar seu ID do Telegram"
 
 [tgbot.messages]
 "cpuThreshold" = "🔴 A carga da CPU {{ .Percent }}% excede o limite de {{ .Threshold }}%"

+ 8 - 4
web/translation/translate.ru_RU.toml

@@ -342,7 +342,7 @@
 "subEnable" = "Включить подписку"
 "subEnableDesc" = "Функция подписки с отдельной конфигурацией"
 "subTitle" = "Заголовок подписки"
- "subTitleDesc" = "Название подписки, которое видит клиент в VPN клиенте"
+"subTitleDesc" = "Название подписки, которое видит клиент в VPN клиенте"
 "subListen" = "Прослушивание IP"
 "subListenDesc" = "Оставьте пустым по умолчанию, чтобы отслеживать все IP-адреса"
 "subPort" = "Порт подписки"
@@ -532,9 +532,9 @@
 
 [pages.settings.security]
 "admin" = "Учетные данные администратора"
-"twoFactor" = "Двухфакторная аутентификация"  
-"twoFactorEnable" = "Включить 2FA"  
-"twoFactorEnableDesc" = "Добавляет дополнительный уровень аутентификации для повышения безопасности."  
+"twoFactor" = "Двухфакторная аутентификация"
+"twoFactorEnable" = "Включить 2FA"
+"twoFactorEnableDesc" = "Добавляет дополнительный уровень аутентификации для повышения безопасности."
 "twoFactorModalSetTitle" = "Включить двухфакторную аутентификацию"
 "twoFactorModalDeleteTitle" = "Отключить двухфакторную аутентификацию"
 "twoFactorModalSteps" = "Для настройки двухфакторной аутентификации выполните несколько шагов:"
@@ -590,6 +590,10 @@
 "restartSuccess" = "✅ Ядро Xray успешно перезапущено."
 "restartFailed" = "❗ Ошибка при перезапуске Xray-core.\r\n\r\n<code>Ошибка: {{ .Error }}</code>."
 "xrayNotRunning" = "❗ Xray Core не запущен."
+"startDesc" = "Показать главное меню"
+"helpDesc" = "Справка по боту"
+"statusDesc" = "Проверить статус бота"
+"idDesc" = "Показать ваш Telegram ID"
 
 [tgbot.messages]
 "cpuThreshold" = "🔴 Загрузка процессора составляет {{ .Percent }}%, что превышает пороговое значение {{ .Threshold }}%"

+ 4 - 0
web/translation/translate.tr_TR.toml

@@ -590,6 +590,10 @@
 "restartSuccess" = "✅ İşlem başarılı!"
 "restartFailed" = "❗ İşlem hatası.\r\n\r\n<code>Hata: {{ .Error }}</code>."
 "xrayNotRunning" = "❗ Xray Core çalışmıyor."
+"startDesc" = "Ana menüyü göster"
+"helpDesc" = "Bot yardımı"
+"statusDesc" = "Bot durumunu kontrol et"
+"idDesc" = "Telegram ID'nizi göster"
 
 [tgbot.messages]
 "cpuThreshold" = "🔴 CPU Yükü {{ .Percent }}% eşiği {{ .Threshold }}%'yi aşıyor"

+ 4 - 0
web/translation/translate.uk_UA.toml

@@ -590,6 +590,10 @@
 "restartSuccess" = "✅ Операція успішна!"
 "restartFailed" = "❗ Помилка в операції.\r\n\r\n<code>Помилка: {{ .Error }}</code>."
 "xrayNotRunning" = "❗ Xray Core не запущений."
+"startDesc" = "Показати головне меню"
+"helpDesc" = "Довідка по боту"
+"statusDesc" = "Перевірити статус бота"
+"idDesc" = "Показати ваш Telegram ID"
 
 [tgbot.messages]
 "cpuThreshold" = "🔴 Навантаження ЦП  {{ .Percent }}% перевищує порогове значення {{ .Threshold }}%"

+ 4 - 0
web/translation/translate.vi_VN.toml

@@ -590,6 +590,10 @@
 "restartSuccess" = "✅ Hoạt động thành công!"
 "restartFailed" = "❗ Lỗi trong quá trình hoạt động.\r\n\r\n<code>Lỗi: {{ .Error }}</code>."
 "xrayNotRunning" = "❗ Xray Core không chạy."
+"startDesc" = "Hiển thị menu chính"
+"helpDesc" = "Trợ giúp bot"
+"statusDesc" = "Kiểm tra trạng thái bot"
+"idDesc" = "Hiển thị ID Telegram của bạn"
 
 [tgbot.messages]
 "cpuThreshold" = "🔴 Sử dụng CPU {{ .Percent }}% vượt quá ngưỡng {{ .Threshold }}%"

+ 4 - 0
web/translation/translate.zh_CN.toml

@@ -590,6 +590,10 @@
 "restartSuccess" = "✅ 操作成功!"
 "restartFailed" = "❗ 操作错误。\r\n\r\n<code>错误: {{ .Error }}</code>."
 "xrayNotRunning" = "❗ Xray Core 未运行。"
+"startDesc" = "显示主菜单"
+"helpDesc" = "机器人帮助"
+"statusDesc" = "检查机器人状态"
+"idDesc" = "显示您的 Telegram ID"
 
 [tgbot.messages]
 "cpuThreshold" = "🔴 CPU 使用率为 {{ .Percent }}%,超过阈值 {{ .Threshold }}%"

+ 4 - 0
web/translation/translate.zh_TW.toml

@@ -592,6 +592,10 @@
 "restartSuccess" = "✅ 操作成功!"
 "restartFailed" = "❗ 操作錯誤。\r\n\r\n<code>錯誤: {{ .Error }}</code>."
 "xrayNotRunning" = "❗ Xray Core 未運行。"
+"startDesc" = "顯示主選單"
+"helpDesc" = "機器人幫助"
+"statusDesc" = "檢查機器人狀態"
+"idDesc" = "顯示您的 Telegram ID"
 
 [tgbot.messages]
 "cpuThreshold" = "🔴 CPU 使用率為 {{ .Percent }}%,超過閾值 {{ .Threshold }}%"