Files
miti99bot/internal/modules/wordle/lookup.go
T
tiennm99 ec77a24db7 chore: drop CF→AWS migration tooling and stale JS-port references
The CF→AWS data migration (closed 2026-05-16) is long done and the
tooling isn't wired into any production path. Remove the one-shot binary,
its support package, and the migration runbook.

In live code, replace 'JS-parity' / 'same shape as JS' / 'cross-runtime
KV migration' comments with the real, stable reason for each behavior
(wire-format invariant, null-vs-zero distinction, CloudWatch alarm field
name, etc.). 24 files touched across lolschedule, loldle, wordle, twentyq,
trading, misc, util, server, metrics, ai, keylock.

- delete cmd/migrate_cf_data/
- delete internal/migration/
- delete docs/cf-to-aws-migration-runbook.md
2026-05-25 09:39:17 +07:00

54 lines
1.5 KiB
Go

package wordle
import "strings"
// normalizeWord lowercases input and strips anything outside a-z.
func normalizeWord(input string) string {
lower := strings.ToLower(input)
out := make([]byte, 0, len(lower))
for i := 0; i < len(lower); i++ {
c := lower[i]
if c >= 'a' && c <= 'z' {
out = append(out, c)
}
}
return string(out)
}
// rejectReason classifies why validateGuess returned not-ok. The user-facing
// reply mapping in handlers branches on these values, so renaming a constant
// here requires updating that mapping.
type rejectReason string
const (
reasonEmpty rejectReason = "empty"
reasonLength rejectReason = "length"
reasonUnknown rejectReason = "unknown"
)
// guessResult is the validateGuess outcome. Word is always populated with the
// normalized form, even on failure, so callers can include it in error
// messages without re-normalizing.
type guessResult struct {
OK bool
Word string
Reason rejectReason
}
// validateGuess normalizes input then checks length + dictionary membership.
//
// Reasons in priority order: empty (post-normalize blank) > length > unknown.
func validateGuess(dict map[string]struct{}, input string) guessResult {
w := normalizeWord(input)
if w == "" {
return guessResult{OK: false, Word: w, Reason: reasonEmpty}
}
if len(w) != WordLength {
return guessResult{OK: false, Word: w, Reason: reasonLength}
}
if _, ok := dict[w]; !ok {
return guessResult{OK: false, Word: w, Reason: reasonUnknown}
}
return guessResult{OK: true, Word: w}
}