From c23fd132a63cc96ef00fd52ad7522cfc28404b38 Mon Sep 17 00:00:00 2001 From: tiennm99 Date: Thu, 6 Aug 2026 11:09:26 +0700 Subject: [PATCH] fix(wheelofnames): left-pad spoiler winner instead of centering --- internal/modules/misc/handlers_test.go | 2 +- internal/modules/misc/wheelofnames_command.go | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/internal/modules/misc/handlers_test.go b/internal/modules/misc/handlers_test.go index 2daf81e..3f077bd 100644 --- a/internal/modules/misc/handlers_test.go +++ b/internal/modules/misc/handlers_test.go @@ -168,7 +168,7 @@ func TestWheelOfNames_ResultCaptionTruncatesLongResult(t *testing.T) { func TestWheelOfNames_ResultCaptionPadsShortWinnerToLongestOption(t *testing.T) { options := []string{"Bob", "Alexandria"} got := wheelResultCaption(options, 0) - want := `Result: ` + strings.Repeat(wheelCaptionPad, 3) + "Bob" + strings.Repeat(wheelCaptionPad, 4) + `` + want := `Result: ` + strings.Repeat(wheelCaptionPad, 7) + "Bob" + `` if got != want { t.Fatalf("wheelResultCaption() = %q, want %q", got, want) } diff --git a/internal/modules/misc/wheelofnames_command.go b/internal/modules/misc/wheelofnames_command.go index e1f488d..62bea5a 100644 --- a/internal/modules/misc/wheelofnames_command.go +++ b/internal/modules/misc/wheelofnames_command.go @@ -75,7 +75,7 @@ func wheelResultCaption(options []string, winner int) string { // Telegram, which would shrink the spoiler and reveal the winner's length. const wheelCaptionPad = "\u00a0" -// padWheelResultCaption centers shorter winners with blank padding so every +// padWheelResultCaption prefixes shorter winners with blank padding so every // option renders a spoiler of equal length; otherwise the spoiler width // reveals the winner. The longest option is returned unpadded. func padWheelResultCaption(options []string, result string) string { @@ -85,9 +85,7 @@ func padWheelResultCaption(options []string, result string) string { longest = n } } - missing := longest - len([]rune(result)) - left := missing / 2 - return strings.Repeat(wheelCaptionPad, left) + result + strings.Repeat(wheelCaptionPad, missing-left) + return strings.Repeat(wheelCaptionPad, longest-len([]rune(result))) + result } func truncateWheelResultCaption(result string) string {