Helpers checks
This commit is contained in:
parent
36dbde848e
commit
3273af6465
@ -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}')
|
||||
|
||||
@ -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,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user