Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/MHSanaei/3x-ui.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMHSanaei <ho3ein.sanaei@gmail.com>2026-04-22 11:47:30 +0300
committerMHSanaei <ho3ein.sanaei@gmail.com>2026-04-22 11:47:30 +0300
commit8f30d14716072d4eb26ec84313799d4a6d1786a0 (patch)
tree85774f504513efe4fc2bd398ad0b1cc9a2e597d7
parent9611c9def67ca8daa81f4b220ae7b9cec729ed21 (diff)
Extract bot command setup into trySetBotCommands
-rw-r--r--web/service/tgbot.go33
1 files changed, 21 insertions, 12 deletions
diff --git a/web/service/tgbot.go b/web/service/tgbot.go
index 1649f2ed..7c2a7d9e 100644
--- a/web/service/tgbot.go
+++ b/web/service/tgbot.go
@@ -249,18 +249,7 @@ func (t *Tgbot) Start(i18nFS embed.FS) error {
return err
}
- // After bot initialization, set up bot commands with localized descriptions
- err = bot.SetMyCommands(context.Background(), &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)
- }
+ t.trySetBotCommands(bot)
// Start receiving Telegram bot messages
tgBotMutex.Lock()
@@ -274,6 +263,26 @@ func (t *Tgbot) Start(i18nFS embed.FS) error {
return nil
}
+func (t *Tgbot) trySetBotCommands(bot *telego.Bot) {
+ defer func() {
+ if r := recover(); r != nil {
+ logger.Warning("Failed to register bot commands (Telegram may be rate-limiting); bot will continue without them:", r)
+ }
+ }()
+
+ err := bot.SetMyCommands(context.Background(), &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)
+ }
+}
+
// createRobustFastHTTPClient creates a fasthttp.Client with proper connection handling
func (t *Tgbot) createRobustFastHTTPClient(proxyUrl string) *fasthttp.Client {
client := &fasthttp.Client{