From d5f2978b016af9dc5e2a5856969402022a2772cb Mon Sep 17 00:00:00 2001 From: Cal Corum Date: Thu, 6 Feb 2025 15:12:12 -0600 Subject: [PATCH] Update new-game flow --- cogs/gameplay.py | 85 ++++++++++++++++++++++++++++++++++++------- cogs/players.py | 4 +- utilities/dropdown.py | 6 ++- 3 files changed, 79 insertions(+), 16 deletions(-) diff --git a/cogs/gameplay.py b/cogs/gameplay.py index 2cbb1f3..4641367 100644 --- a/cogs/gameplay.py +++ b/cogs/gameplay.py @@ -380,16 +380,41 @@ class Gameplay(commands.Cog): logger.info(f'Pulling and caching full {human_team.abbrev} roster') done = await get_full_roster_from_sheets(session, interaction, self.sheets, this_game, human_team, int(roster.value)) - if done: - sp_view = starting_pitcher_dropdown_view(session, this_game, human_team, this_game.league_name, [interaction.user]) - await interaction.channel.send(content=f'### {human_team.lname} Starting Pitcher', view=sp_view) - await final_message.edit( - content=f'{away_role.mention} @ {home_role.mention} is set!\n\n' - f'Go ahead and set your lineup with the `/set lineup` command!', - embed=embed + roster_choice = await ask_with_buttons( + interaction, + ['vs Left', 'vs Right'], + 'Which lineup will you be using?', + delete_question=False, + confirmation_message='Got it!' ) + sp_view = starting_pitcher_dropdown_view(session, this_game, human_team, this_game.league_name, [interaction.user]) + await interaction.channel.send(content=f'### {human_team.lname} Starting Pitcher', view=sp_view) + + try: + await asyncio.sleep(5) + this_play = await read_lineup( + session, + interaction, + this_game=this_game, + lineup_team=human_team, + sheets_auth=self.sheets, + lineup_num=1 if roster_choice == 'vs Right' else 2, + league_name=this_game.game_type + ) + except LineupsMissingException as e: + logger.error(f'Attempting to start game, pausing for 5 seconds: {e}') + await asyncio.sleep(5) + + try: + this_play = this_game.current_play_or_none(session) + await self.post_play(session, interaction, this_play, buffer_message='Game on!') + except LineupsMissingException as e: + await interaction.channel.send( + content=f'Run `/gamestate` once you have selected a Starting Pitcher to get going!' + ) + @group_new_game.command(name='gauntlet', description='Start a new Gauntlet game against an AI') @app_commands.choices( roster=[ @@ -569,15 +594,49 @@ class Gameplay(commands.Cog): # Get pitchers from rosterlinks done = await get_full_roster_from_sheets(session, interaction, self.sheets, this_game, human_team, 1) - if done: - sp_view = starting_pitcher_dropdown_view(session, this_game, human_team, game_type=this_game.league_name, responders=[interaction.user]) - sp_message = await interaction.channel.send(content=f'### {human_team.lname} Starting Pitcher', view=sp_view) + # if done: + # sp_view = starting_pitcher_dropdown_view(session, this_game, human_team, game_type=this_game.league_name, responders=[interaction.user]) + # sp_message = await interaction.channel.send(content=f'### {human_team.lname} Starting Pitcher', view=sp_view) - await final_message.edit( - content=f'{away_role.mention} @ {home_role.mention} is set!', - embed=embed + # await final_message.edit( + # content=f'{away_role.mention} @ {home_role.mention} is set!', + # embed=embed + # ) + + roster_choice = await ask_with_buttons( + interaction, + ['vs Left', 'vs Right'], + 'Which lineup will you be using?', + delete_question=False, + confirmation_message='Got it!' ) + sp_view = starting_pitcher_dropdown_view(session, this_game, human_team, this_game.league_name, [interaction.user]) + await interaction.channel.send(content=f'### {human_team.lname} Starting Pitcher', view=sp_view) + + try: + await asyncio.sleep(5) + this_play = await read_lineup( + session, + interaction, + this_game=this_game, + lineup_team=human_team, + sheets_auth=self.sheets, + lineup_num=1 if roster_choice == 'vs Right' else 2, + league_name=this_game.game_type + ) + except LineupsMissingException as e: + logger.error(f'Attempting to start game, pausing for 5 seconds: {e}') + await asyncio.sleep(5) + + try: + this_play = this_game.current_play_or_none(session) + await self.post_play(session, interaction, this_play, buffer_message='Game on!') + except LineupsMissingException as e: + await interaction.channel.send( + content=f'Run `/gamestate` once you have selected a Starting Pitcher to get going!' + ) + @group_new_game.command(name='exhibition', description='Start a new custom game against an AI') @app_commands.choices( roster=[ diff --git a/cogs/players.py b/cogs/players.py index e350810..140cbd3 100644 --- a/cogs/players.py +++ b/cogs/players.py @@ -902,7 +902,7 @@ class Players(commands.Cog): ) @app_commands.checks.has_any_role(PD_PLAYERS_ROLE_NAME) async def gauntlet_run_command( - self, interaction: discord.Interaction, event_name: ACTIVE_EVENT_LITERAL, + self, interaction: discord.Interaction, event_name: ACTIVE_EVENT_LITERAL, # type: ignore team_abbrev: str = None): await interaction.response.defer() @@ -1032,7 +1032,7 @@ class Players(commands.Cog): @group_gauntlet.command(name='reset', description='Wipe your current team so you can re-draft') @app_commands.checks.has_any_role(PD_PLAYERS_ROLE_NAME) async def gauntlet_reset_command( - self, interaction: discord.Interaction, event_name: ACTIVE_EVENT_LITERAL): + self, interaction: discord.Interaction, event_name: ACTIVE_EVENT_LITERAL): # type: ignore await interaction.response.defer() main_team = await get_team_by_owner(interaction.user.id) draft_team = await get_team_by_abbrev(f'Gauntlet-{main_team["abbrev"]}') diff --git a/utilities/dropdown.py b/utilities/dropdown.py index 1e35e55..80ed193 100644 --- a/utilities/dropdown.py +++ b/utilities/dropdown.py @@ -166,7 +166,8 @@ class SelectStartingPitcher(discord.ui.Select): try: # await interaction.delete_original_response() await interaction.edit_original_response( - content=f'The {self.team.lname} are starting **{human_sp_card.player.name_with_desc}**!\n\nRun `/set lineup` to import your lineup and `/gamestate` if you are ready to play.', + # content=f'The {self.team.lname} are starting **{human_sp_card.player.name_with_desc}**!\n\nRun `/set lineup` to import your lineup and `/gamestate` if you are ready to play.', + content=f'The {self.team.lname} are starting **{human_sp_card.player.name_with_desc}**!', view=None ) except Exception as e: @@ -384,6 +385,9 @@ class SelectBatterSub(discord.ui.Select): self.session.add(last_lineup) logger.info(f'Set {last_lineup.card.player.name_with_desc} as inactive') + if position not in ['DH', 'PR', 'PH']: + pos_rating = await get_position(self.session, human_batter_card, position) + human_bat_lineup = Lineup( team=self.team, player=human_batter_card.player,