Skip to content

Commit

Permalink
Message fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
asaf-kali committed Feb 16, 2025
1 parent 4c6bd61 commit 90037f1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
22 changes: 14 additions & 8 deletions app/bot/handlers/other/event_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
)
from bot.models import (
COMMAND_TO_INDEX,
GAME_RESULT_TO_EMOJI,
BadMessageError,
BotState,
GameConfig,
Expand Down Expand Up @@ -214,16 +215,17 @@ def remove_keyboard(self, last_keyboard_message_id: int | None):
self.update_session(last_keyboard_message_id=None)

def send_game_summary(self, state: MiniGameState):
self._send_spymasters_intents(state=state)
self._send_winner_text(state=state)
self._send_spymasters_intents(state=state)

def _send_winner_text(self, state: MiniGameState):
result = state.game_result
if not result:
raise ValueError("Winner is not set, cannot send winner text.")
winning_emoji = "🎉" if result.win else "😭"
reason_emoji = GAME_RESULT_TO_EMOJI.get(result)
status = "won" if result.win else "lost"
text = f"You {status}! {winning_emoji} {result.reason}"
text = f"You {status}! {winning_emoji}\n{result.reason} {reason_emoji}"
self.send_text(text, put_log=True)

def _send_spymasters_intents(self, state: MiniGameState):
Expand All @@ -232,7 +234,7 @@ def _send_spymasters_intents(self, state: MiniGameState):
return
intent_strings = [_clue_intent_string(clue) for clue in relevant_clues]
intent_string = "\n".join(intent_strings)
text = f"Spymasters intents were:\n{intent_string}\n"
text = f"The Spymaster's intents were:\n{intent_string}\n"
self.send_markdown(text)

def _next_move(self, state: MiniGameState) -> MiniGameState:
Expand All @@ -242,10 +244,10 @@ def _next_move(self, state: MiniGameState) -> MiniGameState:
game_id = self.game_id
assert game_id
if state.current_player_role == PlayerRole.SPYMASTER:
self.send_score(state=state)
self.send_text(f"{team} spymaster is thinking... 🤔")
# self.send_score(state=state)
self.send_text("The Spymaster is thinking... 🤔")
if _should_skip_turn(current_player_role=state.current_player_role, config=self.config):
self.send_text(f"{team} operative has skipped the turn.")
self.send_text("You skipped the turn.")
guess_request = GuessRequest(game_id=game_id, card_index=PASS_GUESS)
guess_response = self.api_client.mini.guess(request=guess_request)
return guess_response.game_state
Expand All @@ -254,7 +256,7 @@ def _next_move(self, state: MiniGameState) -> MiniGameState:
next_move_response = self.api_client.mini.next_move(request=next_move_request)
if next_move_response.given_clue:
given_clue = next_move_response.given_clue
text = f"{team} spymaster says '*{given_clue.word}*' with *{given_clue.card_amount}* card(s)."
text = f"The Spymaster says '*{given_clue.word}*' with *{given_clue.card_amount}* card(s)."
self.send_markdown(text, put_log=True)
if next_move_response.given_guess:
text = f"{team} operative: " + get_given_guess_result_message_text(
Expand All @@ -274,7 +276,11 @@ def send_board(self, state: MiniGameState, message: str | None = None):
keyboard = build_board_keyboard(table, is_game_over=state.is_game_over)
if message is None:
message = "Game over!" if state.is_game_over else "Pick your guess!"
message += f"\nTurns left: *{state.timer_tokens}*\nMistakes left: *{state.allowed_mistakes}*"
message += (
f"\n❓️ Remaining cards: *{state.score.main.unrevealed}*"
f"\n⏳️ Turns left: *{state.timer_tokens}*"
f"\n💥 Mistakes left: *{state.allowed_mistakes}*"
)
# if state.left_guesses == 1:
# message += " (bonus round)"
text = self.send_markdown(message, reply_markup=keyboard)
Expand Down
4 changes: 2 additions & 2 deletions app/bot/handlers/other/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def handle(self):
How to play:
You are the blue operative. The bot will play all other roles. \
When the blue spymaster sends a hint, you can reply with a card index (1-25), \
or just click the word on the keyboard. \
Use '-pass' and '-quit' to pass the turn and quit the game.
or just click the word on the keyboard. \n\
Use `-pass` and `-quit` to pass the turn and quit the game.
"""
self.send_markdown(text)
14 changes: 14 additions & 0 deletions app/bot/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
from codenames.classic.color import ClassicColor
from codenames.classic.winner import WinningReason
from codenames.duet.card import DuetColor
from codenames.duet.score import (
ASSASSIN_HIT,
GAME_QUIT,
MISTAKE_LIMIT_REACHED,
TARGET_REACHED,
TIMER_TOKENS_DEPLETED,
)
from codenames.generic.move import PASS_GUESS, QUIT_GAME
from pydantic import BaseModel
from the_spymaster_solvers_api.structs import APIModelIdentifier, Difficulty, Solver
Expand All @@ -15,6 +22,13 @@
WinningReason.OPPONENT_HIT_ASSASSIN: "😵",
WinningReason.OPPONENT_QUIT: "🥴",
}
GAME_RESULT_TO_EMOJI = {
TARGET_REACHED: "🤓",
ASSASSIN_HIT: "😵",
GAME_QUIT: "🥴",
TIMER_TOKENS_DEPLETED: "😴",
MISTAKE_LIMIT_REACHED: "💥",
}
COMMAND_TO_INDEX = {"-pass": PASS_GUESS, "-quit": QUIT_GAME}
AVAILABLE_MODELS = [
APIModelIdentifier(language="english", model_name="wiki-50", is_stemmed=False),
Expand Down

0 comments on commit 90037f1

Please sign in to comment.