Files
tiennm99bot/cmd/server/command_menu.go
T
tiennm99 7008a57cf5 refactor!: rebrand miti99bot to tiennm99bot
BREAKING CHANGE: the Go module path is now github.com/tiennm99/tiennm99bot,
the default sticker pack is stickers_by_<bot username>, and the health body,
deploy DM, User-Agents and image names say tiennm99bot.
2026-10-07 15:14:02 +07:00

54 lines
1.4 KiB
Go

package main
import (
"context"
"errors"
"time"
"github.com/go-telegram/bot"
"github.com/go-telegram/bot/models"
"github.com/tiennm99/tiennm99bot/internal/modules"
)
const commandMenuTimeout = 8 * time.Second
// botCommandMenu builds the Telegram command menu from the loaded public
// commands. It intentionally follows registry module order so MODULES controls
// both enabled commands and their menu grouping.
func botCommandMenu(reg *modules.Registry) []models.BotCommand {
if reg == nil {
return nil
}
var out []models.BotCommand
for _, mod := range reg.Modules {
for _, cmd := range mod.Commands {
if cmd.Visibility != modules.VisibilityPublic {
continue
}
out = append(out, models.BotCommand{
Command: cmd.Name,
Description: cmd.TelegramMenuDescription(),
})
}
}
return out
}
// registerCommandMenu publishes the menu to Telegram. It is best-effort at
// startup: callers should log failures and keep the bot running.
func registerCommandMenu(ctx context.Context, b *bot.Bot, reg *modules.Registry) (int, error) {
cmds := botCommandMenu(reg)
menuCtx, cancel := context.WithTimeout(ctx, commandMenuTimeout)
defer cancel()
ok, err := b.SetMyCommands(menuCtx, &bot.SetMyCommandsParams{Commands: cmds})
if err != nil {
return len(cmds), err
}
if !ok {
return len(cmds), errors.New("telegram setMyCommands returned false")
}
return len(cmds), nil
}