Skip to content

Commit

Permalink
🎢 Upgrade game infra (#18)
Browse files Browse the repository at this point in the history
* 🎢 Upgrade game infra

* MR fixes
  • Loading branch information
asaf-kali authored Jan 18, 2025
1 parent 614de6e commit e48bcbb
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 78 deletions.
6 changes: 3 additions & 3 deletions app/bot/handlers/gameplay/process_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from bot.models import COMMAND_TO_INDEX
from codenames.classic.board import Board
from the_spymaster_api.structs import GuessRequest
from the_spymaster_api.structs.classic.responses import GuessResponse
from the_spymaster_api.structs.classic.responses import ClassicGuessResponse
from the_spymaster_util.logger import get_logger

log = get_logger(__name__)
Expand Down Expand Up @@ -44,10 +44,10 @@ def handle(self):
self.send_markdown(text)
return self.fast_forward(response.game_state)

def _guess(self, card_index: int) -> GuessResponse:
def _guess(self, card_index: int) -> ClassicGuessResponse:
assert self.game_id
request = GuessRequest(game_id=self.game_id, card_index=card_index)
return self.api_client.guess(request)
return self.api_client.classic.guess(request)


def _get_card_index(board: Board, text: str) -> int:
Expand Down
6 changes: 3 additions & 3 deletions app/bot/handlers/gameplay/start.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from bot.handlers.other.event_handler import EventHandler
from bot.models import GameConfig, Session
from codenames.utils.vocabulary.languages import SupportedLanguage
from the_spymaster_api.structs.classic.requests import StartGameRequest
from the_spymaster_api.structs.classic.requests import ClassicStartGameRequest
from the_spymaster_util.logger import get_logger

log = get_logger(__name__)
Expand All @@ -13,8 +13,8 @@ def handle(self):
log.info(f"Got start event from {self.user_full_name}")
game_config = self.config or GameConfig()
language = SupportedLanguage(game_config.language)
request = StartGameRequest(language=language, first_team=game_config.first_team)
response = self.api_client.start_game(request)
request = ClassicStartGameRequest(language=language, first_team=game_config.first_team)
response = self.api_client.classic.start_game(request)
log.update_context(game_id=response.game_id)
log.debug("Game starting", extra={"game_id": response.game_id, "game_config": game_config.dict()})
session = Session(game_id=response.game_id, config=game_config)
Expand Down
6 changes: 3 additions & 3 deletions app/bot/handlers/other/event_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,11 @@ def _next_move(self, state: ClassicGameState) -> ClassicGameState:
if _should_skip_turn(current_player_role=state.current_player_role, config=self.config):
self.send_text(f"{team} operative has skipped the turn.")
guess_request = GuessRequest(game_id=game_id, card_index=PASS_GUESS)
guess_response = self.api_client.guess(request=guess_request)
guess_response = self.api_client.classic.guess(request=guess_request)
return guess_response.game_state
solver = self.config.solver
next_move_request = NextMoveRequest(game_id=game_id, solver=solver)
next_move_response = self.api_client.next_move(request=next_move_request)
next_move_response = self.api_client.classic.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)."
Expand Down Expand Up @@ -287,7 +287,7 @@ def send_board(self, state: ClassicGameState, message: Optional[str] = None):

def _get_game_state(self, game_id: str) -> ClassicGameState:
request = GetGameStateRequest(game_id=game_id)
return self.api_client.get_game_state(request=request).game_state
return self.api_client.classic.get_game_state(request=request).game_state
# self.set_state(new_state=response.game_state)

def on_error(self, error: Exception):
Expand Down
4 changes: 2 additions & 2 deletions app/bot/the_spymaster_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@


class TheSpymasterBot:
def __init__(self, telegram_token: str, base_url: str, dynamo_persistence: bool = False):
self.api_client = TheSpymasterClient(base_url=base_url)
def __init__(self, telegram_token: str, server_host: str, dynamo_persistence: bool = False):
self.api_client = TheSpymasterClient(server_host=server_host)
persistence = DynamoPersistence() if dynamo_persistence else DictPersistence()
self.updater = Updater(token=telegram_token, persistence=persistence)
self._construct_updater()
Expand Down
2 changes: 1 addition & 1 deletion app/lambda_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
configure_sentry(config=config)
bot = TheSpymasterBot(
telegram_token=config.telegram_token,
base_url=config.base_backend_url,
server_host=config.base_backend_url,
dynamo_persistence=True,
)
log.info("Bootstrap complete.")
Expand Down
2 changes: 1 addition & 1 deletion app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def main():
configure_logging(config=config)
bot = TheSpymasterBot(
telegram_token=config.telegram_token,
base_url=config.base_backend_url,
server_host=config.base_backend_url,
dynamo_persistence=True,
)
bot.poll()
Expand Down
119 changes: 60 additions & 59 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e48bcbb

Please sign in to comment.