diff --git a/cmd/server/command_menu.go b/cmd/server/command_menu.go index 127130a..bbacfb0 100644 --- a/cmd/server/command_menu.go +++ b/cmd/server/command_menu.go @@ -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 } diff --git a/cmd/server/command_menu_test.go b/cmd/server/command_menu_test.go index b7bacd4..a88b901 100644 --- a/cmd/server/command_menu_test.go +++ b/cmd/server/command_menu_test.go @@ -16,7 +16,7 @@ import ( "github.com/tiennm99/tiennm99bot/internal/testutil" ) -func TestBotCommandMenu_UsesLoadedPublicCommandsInModuleOrder(t *testing.T) { +func TestBotCommandMenu_ListsLoadedPublicCommandsByName(t *testing.T) { reg := &modules.Registry{ Modules: []modules.Module{ { @@ -39,8 +39,8 @@ func TestBotCommandMenu_UsesLoadedPublicCommandsInModuleOrder(t *testing.T) { got := botCommandMenu(reg) want := []models.BotCommand{ - {Command: "beta_public", Description: ". Beta public."}, {Command: "alpha_public", Description: "Alpha public."}, + {Command: "beta_public", Description: ". Beta public."}, } if len(got) != len(want) { t.Fatalf("commands = %v, want %v", got, want) diff --git a/internal/modules/weather/weather.go b/internal/modules/weather/weather.go index e1b0511..a517d5f 100644 --- a/internal/modules/weather/weather.go +++ b/internal/modules/weather/weather.go @@ -77,8 +77,8 @@ func New(deps modules.Deps) modules.Module { } return modules.Module{ Commands: append([]modules.Command{ - command("thoitiethomnay", "Thời tiết hôm nay (mặc định Tân Thuận, Q.7)", todayView), command("thoitiet", "Thời tiết từng giờ trong 6 giờ tới (mặc định Tân Thuận, Q.7)", hourlyView), + command("thoitiethomnay", "Thời tiết hôm nay (mặc định Tân Thuận, Q.7)", todayView), command("thoitietngaymai", "Thời tiết ngày mai (mặc định Tân Thuận, Q.7)", tomorrowView), command("thoitiettuannay", "Thời tiết 7 ngày tới (mặc định Tân Thuận, Q.7)", weekView), }, fl.commands()...), diff --git a/internal/modules/weather/weather_test.go b/internal/modules/weather/weather_test.go index 1bcfe8b..4d6cff9 100644 --- a/internal/modules/weather/weather_test.go +++ b/internal/modules/weather/weather_test.go @@ -105,8 +105,8 @@ func send(rb *testutil.RecordingBot, text string) string { func TestCommands_RegistrationAndParameters(t *testing.T) { mod := New(modules.Deps{Store: storage.NewMemoryProvider().Collection(CollectionName)}) want := []struct{ name, parameters string }{ - {"thoitiethomnay", "[location... | lat,long]"}, {"thoitiet", "[location... | lat,long]"}, + {"thoitiethomnay", "[location... | lat,long]"}, {"thoitietngaymai", "[location... | lat,long]"}, {"thoitiettuannay", "[location... | lat,long]"}, {"thuyvan", ""},