Files
miti99bot/internal/modules/loldlequote/render.go
T
tiennm99 53ce1113eb feat(modules): port loldle-quote
Phase 6b of the go-port-cloud-run plan. Same shape as loldle-emoji but
with quote-pool data and default 6 guesses (vs emoji's 5).

- internal/modules/loldlequote: champions.go (embed quotes.json),
  state.go (game/stats/config persistence), render.go (italic clue +
  guess list, HTML-escaped), handlers.go (handleQuote / handleGiveup /
  handleStats / handleSetMax), loldlequote.go (Module Factory).
- Reuses internal/modules/util/chathelper and internal/champname so
  the new module adds no helper duplication.
- 4 commands wired in cmd/server/main.go: loldle_quote (public),
  loldle_quote_giveup (public), loldle_quote_stats (public),
  loldle_quote_setmax (private).
- 17 tests: lookup (embed + redaction-marker check), render
  (escapes), state (round-trip + JS-wire-format decode + streak
  sequence), handlers (no-arg / win / unknown / duplicate / giveup /
  stats / setmax owner+nonowner).

go test -race -count=1 ./... clean across all 16 packages;
golangci-lint clean.
2026-05-09 16:45:51 +07:00

32 lines
1005 B
Go

package loldlequote
import (
"fmt"
"html"
"strings"
)
// renderBoard formats the quote clue + the wrong-guess list. JS-faithful:
//
// 🎭 <i>the Darkin Blade — Once honored defenders of Shurima against the Void, ___ ...</i>
//
// Guesses (2/6):
// • Aatrox ❌
// • Ahri ❌
//
// Empty board returns the placeholder hint. The quote is HTML-escaped before
// wrapping in <i> so apostrophes / ampersands / stray angle brackets in the
// data source can't break Telegram's HTML parse mode.
func renderBoard(quote string, guesses []string, maxGuesses int) string {
clue := "🎭 <i>" + html.EscapeString(quote) + "</i>"
if len(guesses) == 0 {
return clue + "\n\nNo guesses yet. Reply with <code>/loldle_quote &lt;champion&gt;</code>."
}
lines := make([]string, len(guesses))
for i, name := range guesses {
lines[i] = " • " + html.EscapeString(name) + " ❌"
}
return fmt.Sprintf("%s\n\nGuesses (%d/%d):\n%s",
clue, len(guesses), maxGuesses, strings.Join(lines, "\n"))
}