Update gameplay.py

Update read-lineup text helpers
This commit is contained in:
Cal Corum 2023-10-30 21:14:47 -05:00
parent a5171d4e07
commit fc35a3a1b8

View File

@ -1250,7 +1250,7 @@ class Gameplay(commands.Cog):
await interaction.channel.send( await interaction.channel.send(
content=f'{away_role.mention} @ {home_role.mention} is set!\n\n' content=f'{away_role.mention} @ {home_role.mention} is set!\n\n'
f'Go ahead and set lineups with the `/readlineup` command!', f'Go ahead and set lineups with the `/read-lineup` command!',
embed=await self.get_game_state_embed(this_game, full_length=False) embed=await self.get_game_state_embed(this_game, full_length=False)
) )
return return
@ -1341,7 +1341,7 @@ class Gameplay(commands.Cog):
await interaction.channel.send( await interaction.channel.send(
content=f'{away_role.mention} @ {home_role.mention} is set!\n\n' content=f'{away_role.mention} @ {home_role.mention} is set!\n\n'
f'Go ahead and set lineups with the `/readlineup` command!', f'Go ahead and set lineups with the `/read-lineup` command!',
embed=await self.get_game_state_embed(this_game, full_length=False) embed=await self.get_game_state_embed(this_game, full_length=False)
) )
return return
@ -1432,7 +1432,7 @@ class Gameplay(commands.Cog):
await interaction.channel.send( await interaction.channel.send(
content=f'{away_role.mention} @ {home_role.mention} is set!\n\n' content=f'{away_role.mention} @ {home_role.mention} is set!\n\n'
f'Go ahead and set lineups with the `/readlineup` command!', f'Go ahead and set lineups with the `/read-lineup` command!',
embed=await self.get_game_state_embed(this_game, full_length=False) embed=await self.get_game_state_embed(this_game, full_length=False)
) )
return return
@ -1622,7 +1622,7 @@ class Gameplay(commands.Cog):
await interaction.channel.send( await interaction.channel.send(
content=f'Game {gauntlets.games_played(this_run) + 1} of the run is set!\n\n' content=f'Game {gauntlets.games_played(this_run) + 1} of the run is set!\n\n'
f'Go ahead and set lineups with the `/readlineup` command!', f'Go ahead and set lineups with the `/read-lineup` command!',
embed=await self.get_game_state_embed(this_game, full_length=False) embed=await self.get_game_state_embed(this_game, full_length=False)
) )
return return
@ -1693,7 +1693,7 @@ class Gameplay(commands.Cog):
await self.post_stratgame(this_game, forfeit=True) await self.post_stratgame(this_game, forfeit=True)
await send_to_channel( await send_to_channel(
self.bot, 'pd-network-news', self.bot, 'pd-network-news',
f'The **{owner_team["lname"]}** made an oopsie-poopsie and had to call of their game down in ' f'The **{owner_team["lname"]}** made an oopsie-poopsie and had to call off their game down in '
f'{interaction.channel.mention}') f'{interaction.channel.mention}')
this_game = patch_game(this_game.id, active=False) this_game = patch_game(this_game.id, active=False)
await interaction.edit_original_response( await interaction.edit_original_response(
@ -2451,13 +2451,12 @@ class Gameplay(commands.Cog):
description='Import a saved lineup directly from the team sheet for PD games' description='Import a saved lineup directly from the team sheet for PD games'
) )
@app_commands.describe( @app_commands.describe(
team_abbrev='The 2- to 4-digit abbreviation for the team being set',
roster='Which roster to pull from your sheet?', roster='Which roster to pull from your sheet?',
lineup='Which handedness lineup are you using?' lineup='Which handedness lineup are you using?'
) )
@app_commands.checks.has_any_role(PD_PLAYERS_ROLE_NAME) @app_commands.checks.has_any_role(PD_PLAYERS_ROLE_NAME)
async def read_lineup_command( async def read_lineup_command(
self, interaction: discord.Interaction, team_abbrev: str, roster: Literal['Primary', 'Secondary', 'Ranked'], self, interaction: discord.Interaction, roster: Literal['Primary', 'Secondary', 'Ranked'],
lineup: Literal['v Right', 'v Left']): lineup: Literal['v Right', 'v Left']):
this_game = get_one_game(channel_id=interaction.channel_id, active=True) this_game = get_one_game(channel_id=interaction.channel_id, active=True)
if not this_game: if not this_game:
@ -2469,19 +2468,13 @@ class Gameplay(commands.Cog):
f'Please use the `/setlineup` command.') f'Please use the `/setlineup` command.')
return return
owner_team = await get_game_team(this_game, interaction.user.id) lineup_team = await get_game_team(this_game, interaction.user.id)
if 'gauntlet' in this_game.game_type: if 'gauntlet' in this_game.game_type:
lineup_team = await get_game_team(this_game, team_abbrev=f'Gauntlet-{owner_team["abbrev"]}') lineup_team = await get_game_team(this_game, team_abbrev=f'Gauntlet-{lineup_team["abbrev"]}')
else:
lineup_team = await get_game_team(this_game, team_abbrev=team_abbrev)
if owner_team['gmid'] != lineup_team['gmid']:
await interaction.response.send_message('Bruh. Only GMs of the active teams can set lineups.')
return
if not lineup_team['id'] in [this_game.away_team_id, this_game.home_team_id]: if not lineup_team['id'] in [this_game.away_team_id, this_game.home_team_id]:
await interaction.response.send_message( logging.info(f'{interaction.user.display_name} tried to run a command in Game {this_game.id} when they '
f'I do not see {lineup_team["sname"]} in this game. Please check the team abbrev and try again' f'aren\'t a GM in the game.')
) await interaction.edit_original_response(content='Bruh. Only GMs of the active teams can pull lineups.')
return return
existing_lineups = await get_team_lineups(this_game.id, lineup_team['id'], as_string=False) existing_lineups = await get_team_lineups(this_game.id, lineup_team['id'], as_string=False)
@ -2544,45 +2537,6 @@ class Gameplay(commands.Cog):
else: else:
patch_game(this_game.id, home_roster_num=roster_num) patch_game(this_game.id, home_roster_num=roster_num)
# if lineup_team['is_ai']:
# starter = starting_pitcher(lineup_team, self.bot, True if this_game.ai_team == 'home' else False)
# this_card = await db_get(f'cards', object_id=int(starter))
# all_lineups.append({
# 'game_id': this_game.id,
# 'team_id': lineup_team['id'],
# 'player_id': this_card['player']['player_id'],
# 'card_id': starter,
# 'position': 'P',
# 'batting_order': 10,
# 'after_play': 0
# })
# all_pos.append('P')
# else:
# this_card = await db_get(f'cards', object_id=sp_card_id)
# logging.debug(f'this_card: {this_card}')
#
# if this_card['team']['id'] != lineup_team['id']:
# logging.error(
# f'Card_id {sp_card_id} does not belong to {lineup_team["abbrev"]} in Game {this_game.id}'
# )
# await interaction.channel.send(
# f'Uh oh. Card ID {sp_card_id} is {this_card["player"]["p_name"]} and belongs to '
# f'{this_card["team"]["sname"]}. Will you double check that before we get started?')
# return
#
# else:
# card_ids.append(str(sp_card_id))
# all_lineups.append({
# 'game_id': this_game.id,
# 'team_id': lineup_team['id'],
# 'player_id': this_card['player']['player_id'],
# 'card_id': sp_card_id,
# 'position': 'P',
# 'batting_order': 10,
# 'after_play': 0
# })
# all_pos.append('P')
# Check roster legality # Check roster legality
if this_game.game_type in ['major-league', 'hall-of-fame']: if this_game.game_type in ['major-league', 'hall-of-fame']:
l_check = await legal_check(card_ids) l_check = await legal_check(card_ids)
@ -2597,21 +2551,6 @@ class Gameplay(commands.Cog):
logging.debug(f'Setting lineup for {lineup_team["sname"]} in PD game') logging.debug(f'Setting lineup for {lineup_team["sname"]} in PD game')
post_lineups(all_lineups) post_lineups(all_lineups)
# while True:
# # Get Starting Pitcher
# this_q = Question(
# self.bot, interaction.channel, f'Please enter the card_id of the {lineup_team["sname"]} SP',
# 'int', 45
# )
# resp = await this_q.ask([interaction.user])
#
# if not resp:
# await interaction.edit_original_response(
# content='Please enter the Starting Pitcher using the `/substitution` command'
# )
# return
# else:
try: try:
await interaction.channel.send(content=None, embed=await self.get_game_state_embed(this_game)) await interaction.channel.send(content=None, embed=await self.get_game_state_embed(this_game))
except IntegrityError as e: except IntegrityError as e:
@ -2641,39 +2580,24 @@ class Gameplay(commands.Cog):
new_player='For PD game: enter the Card ID (a number); or SBa game: enter the Player Name') new_player='For PD game: enter the Card ID (a number); or SBa game: enter the Player Name')
@commands.has_any_role(SBA_PLAYERS_ROLE_NAME, PD_PLAYERS_ROLE_NAME) @commands.has_any_role(SBA_PLAYERS_ROLE_NAME, PD_PLAYERS_ROLE_NAME)
async def substitution_command( async def substitution_command(
self, interaction: discord.Interaction, team_abbrev: str, new_player: str, order_number: Literal[ self, interaction: discord.Interaction, new_player: str, order_number: Literal[
'this-spot', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10'], 'this-spot', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10'],
new_pos: Literal['P', 'C', '1B', '2B', '3B', 'SS', 'LF', 'CF', 'RF', 'DH', 'PH', 'PR']): new_pos: Literal['P', 'C', '1B', '2B', '3B', 'SS', 'LF', 'CF', 'RF', 'DH', 'PH', 'PR']):
this_game, owner_team, this_play = await self.checks_log_interaction(interaction) this_game, owner_team, this_play = await self.checks_log_interaction(interaction)
if False in (this_game, owner_team, this_play): if False in (this_game, owner_team, this_play):
return return
owner_team = await get_game_team(this_game, interaction.user.id)
if 'gauntlet' in this_game.game_type:
lineup_team = await get_game_team(this_game, team_abbrev=f'Gauntlet-{owner_team["abbrev"]}')
else:
lineup_team = await get_game_team(this_game, team_abbrev=team_abbrev)
if owner_team['gmid'] != lineup_team['gmid']:
await interaction.edit_original_response(content='Bruh. Only GMs of the active teams can set lineups.')
return
if not lineup_team['id'] in [this_game.away_team_id, this_game.home_team_id]:
await interaction.edit_original_response(
content=f'I do not see {lineup_team["sname"]} in this game. Please check the team abbrev and try again'
)
return
try: try:
if this_game.is_pd: if this_game.is_pd:
this_card = await db_get(f'cards', object_id=int(new_player)) this_card = await db_get(f'cards', object_id=int(new_player))
if this_card["team"]["id"] != lineup_team['id']: if this_card["team"]["id"] != owner_team['id']:
raise SyntaxError(f'Easy there, champ. Looks like card ID {new_player} belongs to the ' 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.') f'{this_card["team"]["sname"]}. Try again with only cards you own.')
player_id = this_card['player']['player_id'] player_id = this_card['player']['player_id']
card_id = new_player card_id = new_player
else: else:
this_player = get_sba_player(new_player, season=SBA_SEASON) this_player = get_sba_player(new_player, season=SBA_SEASON)
if this_player['team']['id'] != lineup_team['id']: if this_player['team']['id'] != owner_team['id']:
raise SyntaxError(f'Easy there, champ. Looks like {new_player} is on ' raise SyntaxError(f'Easy there, champ. Looks like {new_player} is on '
f'{this_player["team"]["sname"]}. Try again with only your own players.') f'{this_player["team"]["sname"]}. Try again with only your own players.')
player_id = this_player['id'] player_id = this_player['id']
@ -2705,14 +2629,14 @@ class Gameplay(commands.Cog):
batting_order = int(order_number) if order_number != 'this-spot' else this_play.batting_order batting_order = int(order_number) if order_number != 'this-spot' else this_play.batting_order
# Check for simple position change # Check for simple position change
in_lineup = get_one_lineup(this_game.id, team_id=lineup_team['id'], active=True, batting_order=batting_order) in_lineup = get_one_lineup(this_game.id, team_id=owner_team['id'], active=True, batting_order=batting_order)
if in_lineup.card_id == int(card_id): if in_lineup.card_id == int(card_id):
post_pos = patch_lineup(in_lineup.id, position=new_pos) post_pos = patch_lineup(in_lineup.id, position=new_pos)
else: else:
curr_play = get_current_play(this_game.id) curr_play = get_current_play(this_game.id)
this_lineup = { this_lineup = {
'game_id': this_game.id, 'game_id': this_game.id,
'team_id': lineup_team['id'], 'team_id': owner_team['id'],
'player_id': player_id, 'player_id': player_id,
'card_id': card_id, 'card_id': card_id,
'position': new_pos.upper(), 'position': new_pos.upper(),