From 4b59919d57127d4bb691073ec137e440da14b91a Mon Sep 17 00:00:00 2001 From: Cal Corum Date: Wed, 3 May 2023 14:14:14 -0500 Subject: [PATCH] Gameplay bug fixes --- ai_manager.py | 13 ++++++++----- cogs/gameplay.py | 2 +- db_calls_gameplay.py | 6 ++++-- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/ai_manager.py b/ai_manager.py index cd5c153..14d3618 100644 --- a/ai_manager.py +++ b/ai_manager.py @@ -244,11 +244,12 @@ async def build_lineup(team_object: dict, game_id: int, league_name: str, vs_han ('pos_include', 'RF'), ('pos_include', 'DH'), ('inc_dex', False), ('sort_by', 'cost-desc') ] params.extend(set_params) - all_players = await db_get( + p_query = await db_get( endpoint='players', params=params, timeout=10 - )['players'] + ) + all_players = p_query['players'] except ConnectionError as e: raise ConnectionError(f'Error pulling batters for the {team_object["lname"]}. Cal help plz.') @@ -416,8 +417,10 @@ async def get_starting_pitcher(team_object: dict, game_id: int, is_home: bool, l async def get_relief_pitcher(this_play: StratPlay, ai_team: dict, used_pitchers: list, league_name: str = None) -> dict: - c_query = await db_get('cards', object_id=x.card_id) - used_codes = [c_query["player"]["strat_code"] for x in used_pitchers] + used_codes = [] + for x in used_pitchers: + c_query = await db_get('cards', object_id=x.card_id) + used_codes.append(c_query["player"]["strat_code"]) logging.info(f'get_rp - used_pitchers: {used_codes}') reliever = None @@ -532,7 +535,7 @@ async def pitching_ai_note(this_play: StratPlay, this_pitcher: dict): logging.debug(f'{this_pitcher["team"]["sname"]} going the to pen.') if len(used_pitchers) < 8: - make_sub(get_relief_pitcher( + make_sub(await get_relief_pitcher( this_play, this_pitcher['team'], used_pitchers, this_play.game.game_type )) pitcher = await get_player(this_play.game, get_pitcher(this_play.game, this_play)) diff --git a/cogs/gameplay.py b/cogs/gameplay.py index cae4d2d..95589a7 100644 --- a/cogs/gameplay.py +++ b/cogs/gameplay.py @@ -2333,7 +2333,7 @@ class Gameplay(commands.Cog): used_pitchers = await get_team_lineups( game_id=this_play.game.id, team_id=ai_team['id'], inc_inactive=True, pitchers_only=True, as_string=False ) - make_sub(ai_manager.get_relief_pitcher(this_play, ai_team, used_pitchers, this_game.game_type)) + make_sub(await ai_manager.get_relief_pitcher(this_play, ai_team, used_pitchers, this_game.game_type)) await interaction.edit_original_response( content=None, embed=await self.get_game_state_embed(this_game) diff --git a/db_calls_gameplay.py b/db_calls_gameplay.py index 33bbcf5..67bd33c 100644 --- a/db_calls_gameplay.py +++ b/db_calls_gameplay.py @@ -485,11 +485,13 @@ async def get_game_team(game: StratGame, gm_id: int = None, team_abbrev: str = N f'tm_abbrev: {team_abbrev} / team_id: {team_id} / game: {game}') if game.is_pd: if gm_id: - return await db_get('teams', params=[('season', PD_SEASON), ('gm_id', gm_id)])['teams'][0] + t_query = await db_get('teams', params=[('season', PD_SEASON), ('gm_id', gm_id)]) + return t_query['teams'][0] elif team_id: return await db_get('teams', object_id=team_id) else: - return await db_get('teams', params=[('season', PD_SEASON), ('abbrev', team_abbrev)])['teams'][0] + t_query = await db_get('teams', params=[('season', PD_SEASON), ('abbrev', team_abbrev)]) + return t_query['teams'][0] else: if gm_id: return get_sba_team_by_owner(season=SBA_SEASON, owner_id=gm_id)