mirror of
https://github.com/tiennm99/tiennm99bot.git
synced 2026-10-14 04:16:43 +00:00
feat(menu): sort Telegram command suggestions by name
The command menu was in module load order, which split related commands across modules. Sorting by name keeps /thoitiet next to /thoitiethomnay. The weather module also lists /thoitiet first so /help matches.
This commit is contained in:
1 parent
9801a64e18
commit
fe552f43e4
4 files changed
+9
-6
No files matched your search
@@ -3,6 +3,8 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"slices"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/go-telegram/bot"
|
||||
@@ -14,8 +16,8 @@ import (
|
||||
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.
|
||||
// commands, sorted by name so related commands such as /thoitiet and
|
||||
// /thoitiethomnay sit together whatever their module order.
|
||||
func botCommandMenu(reg *modules.Registry) []models.BotCommand {
|
||||
if reg == nil {
|
||||
return nil
|
||||
@@ -32,6 +34,7 @@ func botCommandMenu(reg *modules.Registry) []models.BotCommand {
|
||||
})
|
||||
}
|
||||
}
|
||||
slices.SortFunc(out, func(a, b models.BotCommand) int { return strings.Compare(a.Command, b.Command) })
|
||||
return out
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user