Skip to content

feat(ahorcado): facelift — branding, solo play, idle timeout, win/lose colors#58

Merged
Xiza73 merged 4 commits into
devfrom
feat/ahorcado-facelift
May 8, 2026
Merged

feat(ahorcado): facelift — branding, solo play, idle timeout, win/lose colors#58
Xiza73 merged 4 commits into
devfrom
feat/ahorcado-facelift

Conversation

@Xiza73

@Xiza73 Xiza73 commented May 8, 2026

Copy link
Copy Markdown
Owner

Summary

Octavo y último comando del facelift de fun. /ahorcado es el más complejo del bot (DM con StringSelectMenu para elegir palabra, collector con turnos, ascii art, GIF de derrota). Este PR aplica la convención de branding y agrega los mismos arreglos funcionales que hicimos en /ruleta.

Branding

  • Title 🎯 Ahorcado (emoji distinto a 🔫 de ruleta)
  • End title cambia a 🏆 Ahorcado — Victoria o 💀 Ahorcado — Derrota
  • Color: fun yellow durante el juego, verde (#57F287) en victoria, rojo mod (#ED4245) en derrota — signal-carrying, misma excepción a la convención que /imc y /ruleta
  • Footer Xiza Bot vX.Y.Z en todos los embeds
  • Inline embed objects → EmbedBuilder + helpers extraídos

Funcionales

Fix Cómo
player2 ahora opcional (solo play) Solo + bot_picks_word:true permitido. Solo + false rechazado (estarías adivinando tu propia palabra)
Validación duplicados new Set check, mismo patrón que /ruleta. Cubre 'player2==player3' y 'player2==self'
Collector colgado forever 🐛 Idle timeout 5 min → embed '⌛ Ahorcado abandonado'
collector.stop('end') explícito en win/lose Para que el reason 'idle' quede limpio

Mantenido intacto

  • DM flow para elegir palabra (StringSelectMenu, 20s timeout)
  • ASCII art y GIFs de Cloudinary
  • Lógica de letras/palabra completa (death-games library)
  • Word list (shared/data/words)
  • 7 vidas

Test plan

  • pnpm test → 230/230 (was 226, +4 nuevos)
  • tsc --noEmit → limpio
  • /ahorcado bot_picks_word:true (solo) → "jugando solo" en kickoff
  • /ahorcado (sin args) → rechazo "necesitas bot_picks_word:true"
  • /ahorcado player2:@bob bot_picks_word:true → flow normal
  • /ahorcado player2:@bob (sin bot_picks) → DM con menú de 25 palabras, 20s
  • DM timeout → "no eligió palabra a tiempo. Cancelado."
  • Ganar la palabra → embed verde 🏆
  • Perder todas las vidas → embed rojo 💀 con GIF
  • Empezar partida y dejarla 5 min → embed "⌛ Abandonado"
  • /ahorcado player2:@bob player3:@bob bot_picks_word:true → rechazo duplicado

Xiza73 added 4 commits May 7, 2026 19:58
…e colors

- title prefixed with 🎯 (distinct from /ruleta's 🔫); end-state title swaps
  to 🏆 on win and 💀 on loss
- color: fun yellow during play; signal-carrying green (#57F287) on victory
  and mod red (#ED4245) on defeat — same convention exception as /imc, /ruleta
- footer 'Xiza Bot vX.Y.Z' on every embed
- inline embed objects → EmbedBuilder, helpers extracted (buildKickoffEmbed,
  buildTurnEmbed, buildEndEmbed, buildAbandonedEmbed)

functional fixes:
- player2 now optional. Solo play allowed only when bot_picks_word:true
  (otherwise you'd be guessing your own word — rejected with ephemeral notice)
- duplicate player rejection (covers 'player2 == player3' and 'player2 == self'),
  matching the /ruleta validation
- collector idle timeout 5min, then '⌛ Ahorcado abandonado' embed —
  fixes the same dangling-collector issue we hit in /ruleta
- explicit collector.stop('end') on win/lose so 'idle' end reason is clean

other:
- description neutral Spanish: 'Tú eliges' → 'Eliges' (drops the explicit
  pronoun — both are neutral but Eliges flows better)
- WORD_PICK_TIMEOUT_MS named constant for the DM word-picking phase

tests: +4 (solo allowed, solo+pick=false rejected, duplicate rejection,
self-as-player2)
The DM-with-menu word-picking flow was a friction wall to start a game. Most
plays just want to roll into the round; flipping the default makes `/ahorcado`
single-tap to launch and `/ahorcado bot_picks_word:false` the explicit opt-in
for the DM-picks path.

- default: false → true
- description and examples updated (`/ahorcado` now lists '/ahorcado',
  '/ahorcado player2:@bob', '/ahorcado player2:@bob bot_picks_word:false')
- bot_picks_word option description spells out the new default
- solo+false rejection text updated ('No pongas bot_picks_word:false')
- tests: solo no-args path renamed and exercises the default; explicit
  bot_picks_word:false test exercises the rejection branch
death-games' Hangman constructor throws 'Debes proporcionar mínimo 2 ID's
en la opcion jugadores' when given a single-element array. Solo play with
the new bot_picks_word=true default crashed at runtime.

Workaround: when solo, duplicate the player's ID for the library
(libPlayerIds = [id, id]) while keeping the user-facing display as a single
player. Turn rotation alternates between two slots that resolve to the same
user, so the collector filter (msg.author.id === game.turno) keeps matching
and the player just gets every turn — which is what solo play means.

Tests passed because the death-games mock skips the validation; only real
Discord runtime hit the throw.
… semantics

Three fixes in one pass — the user reported (1) and (2), and I caught (3)
while rewriting the turn loop.

1. Repeated letter no longer consumes a life
   The death-games library decrements 'vidas' every time find() sees a letter
   that's already in letrasUsadas (covers BOTH correct and incorrect repeats —
   library code lines 56-62 and 83-87). Adding the dedup check on our side
   before calling find() means typing 'b' twice no longer eats a second life.
   The repeating player keeps their turn and gets a friendly notice instead.

2. Wrong full-word guess eliminates the player
   The library treats multi-char input as just letra[0] (line 52: 'letra =
   letra[0]'), so a wrong full-word guess silently became a single-letter
   guess of the first character. Now we intercept full-word guesses ourselves:
   correct → win path (revealing every letter); wrong → eliminate that player
   (Set<string>, ignored by collector filter, skipped in turn rotation).
   When everyone is eliminated, game ends with a dedicated all-eliminated
   embed (red, 💀).

3. Turn-tracker semantics swap (latent bug from the facelift)
   My earlier refactor pre-rotated 'turn' after the kickoff and used it as the
   current-turn index in the filter — so kickoff said 'Empieza A' but the
   filter expected B's input. Solo play hid this because libPlayerIds are
   duplicated; multi-player would have stalled on the very first guess.
   Now 'turn' = the CURRENT player whose turn it is. Kickoff uses turn=0,
   collect handler uses turn for the filter, advances after processing.

Helpers added:
- buildSkipEmbed   — 'X ya probó la letra Y, sigue su turno'
- buildEliminationEmbed — '☠️ Jugador eliminado' with the failed guess
- buildAllEliminatedEmbed — '💀 Todos eliminados' end embed
- peekNextTurn(from) — returns the next non-eliminated index, or loops if
  every slot is eliminated (caller checks aliveUnique.size beforehand)

Tests: +1 (filter matches the current-turn player, not pre-rotated). The
dedup/elimination paths are integration-tested; the unit-test mocks would
need a major rewrite to capture the constructed Hangman instance and
trigger the collect handler in isolation. The user validates in Discord.
@Xiza73 Xiza73 merged commit 4f96b44 into dev May 8, 2026
2 checks passed
@Xiza73 Xiza73 deleted the feat/ahorcado-facelift branch May 8, 2026 04:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant