Add early game-end logic

This commit is contained in:
Cal Corum 2023-10-20 16:02:14 -05:00
parent ebfab450b9
commit 347dc33b45

View File

@ -57,34 +57,37 @@ class Gameplay(commands.Cog):
await score_channel.set_permissions(player_role, read_messages=False)
return
embed = get_team_embed('Live Scoreboard')
valid_scores = False
for x in active_games:
await asyncio.sleep(1)
gs = await self.get_game_state(x)
if not gs['error']:
valid_scores = True
channel = guild.get_channel(gs["channel_id"])
g_message = gs['scorebug']
g_message += f'Pitcher: {gs["pitcher"]["name"]}\n' \
f'Batter: {gs["batter"]["name"]}\n' \
f'Location: {channel.mention if channel is not None else "Your Butt"}\n' \
f'-------------------------'
embed.add_field(
name=f'{gs["away_team"]["sname"]} @ {gs["home_team"]["sname"]}',
value=g_message,
inline=False
)
try:
embed = get_team_embed('Live Scoreboard')
valid_scores = False
for x in active_games:
await asyncio.sleep(1)
gs = await self.get_game_state(x)
if not gs['error']:
valid_scores = True
channel = guild.get_channel(gs["channel_id"])
g_message = gs['scorebug']
g_message += f'Pitcher: {gs["pitcher"]["name"]}\n' \
f'Batter: {gs["batter"]["name"]}\n' \
f'Location: {channel.mention if channel is not None else "Your Butt"}\n' \
f'-------------------------'
embed.add_field(
name=f'{gs["away_team"]["sname"]} @ {gs["home_team"]["sname"]}',
value=g_message,
inline=False
)
if valid_scores:
async for message in score_channel.history(limit=25):
await message.delete()
if valid_scores:
async for message in score_channel.history(limit=25):
await message.delete()
await score_channel.set_permissions(player_role, read_messages=True)
await score_channel.send(content=None, embed=embed)
else:
await score_channel.set_permissions(player_role, read_messages=False)
return
await score_channel.set_permissions(player_role, read_messages=True)
await score_channel.send(content=None, embed=embed)
else:
await score_channel.set_permissions(player_role, read_messages=False)
return
except Exception as e:
logging.error(f'Could not update live_scoreboard: {e}')
@tasks.loop(hours=36)
async def update_ratings_guides(self):
@ -1553,7 +1556,47 @@ class Gameplay(commands.Cog):
await interaction.edit_original_response(content='Bruh. Only GMs of the active teams can end games.')
return
await response.edit(content=None, embed=await self.get_game_state_embed(this_game))
latest_play = get_latest_play(this_game.id)
"""
If the game isn't over
Not 0 outs
Top of inning <= 9 and not 10-run lead
Top 9th inning or earlier and not 10-run lead
"""
valid_end = False
if latest_play.starting_outs == 0:
if latest_play.inning_half == 'top':
if latest_play.inning_num > 9 and latest_play.away_score != latest_play.home_score:
valid_end = True
if abs(latest_play.home_score - latest_play.away_score) >= 10:
valid_end = True
elif latest_play.inning_half == 'bot' and abs(latest_play.home_score - latest_play.away_score) >= 10:
valid_end = True
if not valid_end:
view = Confirm(responders=[interaction.user])
question = await interaction.channel.send(
'It doesn\'t look like this game is over, yet. I can end it, but no rewards will be paid out.\n\n'
'Should I end this game?',
view=view
)
await view.wait()
if view.value:
patch_game(this_game.id, active=False)
await question.edit(
content='Roger dodger - it is game over.', view=None
)
return
else:
await question.edit(
content='It stays.', view=None
)
return
await response.edit(content=None, embed=await self.get_game_state_embed(this_game, full_length=False))
view = Confirm(responders=[interaction.user], timeout=60, label_type='yes')
question = await interaction.edit_original_response(content=f'Should I end this game?', view=view)
await view.wait()