From 3273af64655480a3472db5f26c4422caa36c68d4 Mon Sep 17 00:00:00 2001 From: Cal Corum Date: Fri, 24 Jan 2025 10:08:35 -0600 Subject: [PATCH] Helpers checks --- in_game/game_helpers.py | 5 +++++ utilities/dropdown.py | 17 ++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/in_game/game_helpers.py b/in_game/game_helpers.py index 7478fa0..ad24d73 100644 --- a/in_game/game_helpers.py +++ b/in_game/game_helpers.py @@ -8,6 +8,7 @@ from db_calls_gameplay import StratGame, StratPlay, StratLineup, StratManagerAi, complete_play, get_team_lineups, get_or_create_bullpen, get_player, get_sheets, make_sub, get_one_lineup, \ advance_one_runner, get_one_lineup, ai_batting, get_manager from api_calls import db_get, db_post +from exceptions import LegalityCheckNotRequired from helpers import Pagination, get_team_embed, image_embed, Confirm from typing import Literal, Optional @@ -173,6 +174,10 @@ def get_pitcher(this_game: StratGame, this_play: StratPlay): async def legal_check(card_ids: list, difficulty_name: str): + if difficulty_name.lower() == 'exhibition': + logger.info(f'Legality check not required for exhibition games.') + return {'legal': True, 'error_string': None} + all_ids = [str(x) for x in card_ids] l_string = "&card_id=".join(all_ids) legality = await db_post(f'cards/legal-check/{difficulty_name}?card_id={l_string}') diff --git a/utilities/dropdown.py b/utilities/dropdown.py index 0c89a84..b0d2384 100644 --- a/utilities/dropdown.py +++ b/utilities/dropdown.py @@ -9,7 +9,7 @@ from discord.utils import MISSING from sqlmodel import Session from api_calls import db_delete, db_get, db_post -from exceptions import CardNotFoundException, PlayNotFoundException, log_exception +from exceptions import CardNotFoundException, LegalityCheckNotRequired, PlayNotFoundException, log_exception from helpers import get_card_embeds, random_insult from in_game.game_helpers import legal_check from in_game.gameplay_models import Game, Lineup, Play, Team @@ -140,12 +140,15 @@ class SelectStartingPitcher(discord.ui.Select): await get_position(self.session, human_sp_card, 'P') - legal_data = await legal_check([self.values[0]], difficulty_name=self.league_name) - if not legal_data['legal']: - await interaction.edit_original_response( - content=f'It looks like this is a Ranked Legal game and {human_sp_card.player.name_with_desc} is not legal in {self.league_name} games. You can start a new game once you pick a new SP.' - ) - return + try: + legal_data = await legal_check([self.values[0]], difficulty_name=self.league_name) + if not legal_data['legal']: + await interaction.edit_original_response( + content=f'It looks like this is a Ranked Legal game and {human_sp_card.player.name_with_desc} is not legal in {self.league_name} games. You can start a new game once you pick a new SP.' + ) + return + except LegalityCheckNotRequired: + pass human_sp_lineup = Lineup( team_id=self.team.id,