diff --git a/cogs/gameplay.py b/cogs/gameplay.py index d60ceb2..012c14b 100644 --- a/cogs/gameplay.py +++ b/cogs/gameplay.py @@ -1793,29 +1793,54 @@ class Gameplay(commands.Cog): valid_end = False logging.debug(f'latest play: {latest_play}') - if latest_play.starting_outs == 0: - logging.debug(f'no outs') - if latest_play.inning_half.lower() == 'top': - logging.debug(f'top of inning') - if latest_play.inning_num > 9 and latest_play.away_score != latest_play.home_score: - logging.debug(f'after the ninth and not tied') - valid_end = True - if abs(latest_play.home_score - latest_play.away_score) >= 10: - logging.debug(f'not after ninth, but mercy') - valid_end = True - if latest_play.inning_half.lower() == 'bot': - if (latest_play.home_score > latest_play.away_score) and latest_play.inning_num >= 9: - logging.debug(f'bottom half and home team winning') - valid_end = True - if abs(latest_play.home_score - latest_play.away_score) >= 10: - logging.debug(f'bottom half and mercy') - valid_end = True - elif abs(latest_play.home_score - latest_play.away_score) >= 10 and latest_play.inning_half.lower() == 'bot': - logging.info(f'bottom half and it is a mercy') - valid_end = True - elif latest_play.inning_num >= 9 and latest_play.inning_half.lower() == 'bot' and \ - latest_play.home_score > latest_play.away_score: - valid_end = True + if not this_game.short_game: + if latest_play.starting_outs == 0: + logging.debug(f'no outs') + if latest_play.inning_half.lower() == 'top': + logging.debug(f'top of inning') + if latest_play.inning_num > 9 and latest_play.away_score != latest_play.home_score: + logging.debug(f'after the ninth and not tied') + valid_end = True + if abs(latest_play.home_score - latest_play.away_score) >= 10: + logging.debug(f'not after ninth, but mercy') + valid_end = True + if latest_play.inning_half.lower() == 'bot': + if (latest_play.home_score > latest_play.away_score) and latest_play.inning_num >= 9: + logging.debug(f'bottom half and home team winning') + valid_end = True + if abs(latest_play.home_score - latest_play.away_score) >= 10: + logging.debug(f'bottom half and mercy') + valid_end = True + elif abs(latest_play.home_score - latest_play.away_score) >= 10 and latest_play.inning_half.lower() == 'bot': + logging.info(f'bottom half and it is a mercy') + valid_end = True + elif latest_play.inning_num >= 9 and latest_play.inning_half.lower() == 'bot' and \ + latest_play.home_score > latest_play.away_score: + valid_end = True + else: + if latest_play.starting_outs == 0: + logging.debug(f'no outs') + if latest_play.inning_half.lower() == 'top': + logging.debug(f'top of inning') + if latest_play.inning_num > 3 and latest_play.away_score != latest_play.home_score: + logging.debug(f'after the ninth and not tied') + valid_end = True + if abs(latest_play.home_score - latest_play.away_score) >= 10: + logging.debug(f'not after ninth, but mercy') + valid_end = True + if latest_play.inning_half.lower() == 'bot': + if (latest_play.home_score > latest_play.away_score) and latest_play.inning_num >= 3: + logging.debug(f'bottom half and home team winning') + valid_end = True + if abs(latest_play.home_score - latest_play.away_score) >= 10: + logging.debug(f'bottom half and mercy') + valid_end = True + elif abs(latest_play.home_score - latest_play.away_score) >= 10 and latest_play.inning_half.lower() == 'bot': + logging.info(f'bottom half and it is a mercy') + valid_end = True + elif latest_play.inning_num >= 3 and latest_play.inning_half.lower() == 'bot' and \ + latest_play.home_score > latest_play.away_score: + valid_end = True # valid_end = True # TODO: REMOVE THIS BEFORE GO-LIVE if not valid_end: @@ -2748,22 +2773,42 @@ class Gameplay(commands.Cog): if False in (this_game, owner_team, this_play): return - if this_play.pitcher.team_id != owner_team['id']: - await interaction.edit_original_response( - content='It looks like your team is batting right now - please make this sub once you take the field.') - return - this_card = await db_get(f'cards', object_id=int(new_player)) - if this_card["team"]["id"] != owner_team['id']: - raise SyntaxError(f'Easy there, champ. Looks like card ID {new_player} belongs to the ' - f'{this_card["team"]["sname"]}. Try again with only cards you own.') - player_id = this_card['player']['player_id'] - card_id = new_player + if this_play is None: + this_card = await db_get(f'cards', object_id=int(new_player)) + if this_card["team"]["id"] != owner_team['id']: + raise SyntaxError(f'Easy there, champ. Looks like card ID {new_player} belongs to the ' + f'{this_card["team"]["sname"]}. Try again with only cards you own.') + player_id = this_card['player']['player_id'] + card_id = new_player + after_play = 0 + + old_pit_order = 10 + if batting_order is None: + batting_order = 10 + else: + batting_order = int(batting_order) - old_pit_order = this_play.pitcher.batting_order - if batting_order is None: - batting_order = old_pit_order else: - batting_order = int(batting_order) + if this_play.pitcher.team_id != owner_team['id']: + await interaction.edit_original_response( + content='It looks like your team is batting right now - ' + 'please make this sub once you take the field.') + return + + this_card = await db_get(f'cards', object_id=int(new_player)) + if this_card["team"]["id"] != owner_team['id']: + raise SyntaxError(f'Easy there, champ. Looks like card ID {new_player} belongs to the ' + f'{this_card["team"]["sname"]}. Try again with only cards you own.') + player_id = this_card['player']['player_id'] + card_id = new_player + + old_pit_order = this_play.pitcher.batting_order + if batting_order is None: + batting_order = old_pit_order + else: + batting_order = int(batting_order) + + after_play = this_play.play_num - 1 this_lineup = { 'game_id': this_game.id, @@ -2772,7 +2817,7 @@ class Gameplay(commands.Cog): 'card_id': card_id, 'position': 'P', 'batting_order': batting_order, - 'after_play': this_play.play_num - 1 if this_play else 0 + 'after_play': after_play } make_sub(this_lineup) @@ -2815,22 +2860,23 @@ class Gameplay(commands.Cog): # return this_game, False, False this_play = get_current_play(this_game.id) - # Allow specific commands to not rollback the play (e.g. /show-card) - if this_play.locked and not block_rollback: - logging.info(f'{interaction.user.display_name} tried to run a command in Game {this_game.id} while the ' - f'play was locked.') - undo_play(this_play.id) - await interaction.edit_original_response( - content=f'Looks like your game got hung up there for a second. I just rolled it back a play to ' - f'release it. If you have any more issues, let Cal know.' - ) - this_play = get_current_play(this_game.id) + if this_play is not None: + # Allow specific commands to not rollback the play (e.g. /show-card) + if this_play.locked and not block_rollback: + logging.info(f'{interaction.user.display_name} tried to run a command in Game {this_game.id} while the ' + f'play was locked.') + undo_play(this_play.id) + await interaction.edit_original_response( + content=f'Looks like your game got hung up there for a second. I just rolled it back a play to ' + f'release it. If you have any more issues, let Cal know.' + ) + this_play = get_current_play(this_game.id) - if not this_play.pitcher: - logging.info(f'{interaction.user.display_name} tried to run a command in Game {this_game.id} without a ' - f'pitcher in the lineup.') - await interaction.edit_original_response(content=f'Please sub in a pitcher before logging a new play.') - this_play = None + if not this_play.pitcher: + logging.info(f'{interaction.user.display_name} tried to run a command in Game {this_game.id} without a ' + f'pitcher in the lineup.') + await interaction.edit_original_response(content=f'Please sub in a pitcher before logging a new play.') + this_play = None return this_game, owner_team, this_play diff --git a/cogs/players.py b/cogs/players.py index e28fff3..075960c 100644 --- a/cogs/players.py +++ b/cogs/players.py @@ -267,7 +267,7 @@ def get_record_embed(team: dict, results: dict, league: str): embed.add_field( name=f'NL Central', value=f'CHC: {results["CHC"][0]} - {results["CHC"][1]} ({results["CHC"][2]} RD)\n' - f'CHW: {results["CIN"][0]} - {results["CIN"][1]} ({results["CIN"][2]} RD)\n' + f'CIN: {results["CIN"][0]} - {results["CIN"][1]} ({results["CIN"][2]} RD)\n' f'MIL: {results["MIL"][0]} - {results["MIL"][1]} ({results["MIL"][2]} RD)\n' f'PIT: {results["PIT"][0]} - {results["PIT"][1]} ({results["PIT"][2]} RD)\n' f'STL: {results["STL"][0]} - {results["STL"][1]} ({results["STL"][2]} RD)\n' diff --git a/db_calls_gameplay.py b/db_calls_gameplay.py index c22f59f..e0b6aab 100644 --- a/db_calls_gameplay.py +++ b/db_calls_gameplay.py @@ -703,8 +703,8 @@ async def get_team_lineups( if pitchers_only: all_lineups = all_lineups.where(Lineup.position == 'P') - if all_lineups.count() == 0: - return None + # if all_lineups.count() == 0: + # return None if as_string: l_string = ''