Remove static gauntlet run options

This commit is contained in:
Cal Corum 2024-12-18 09:59:27 -06:00
parent 55b35a242a
commit 3d41ec1662

View File

@ -15,6 +15,7 @@ from difflib import get_close_matches
from typing import Optional, Literal
from discord.ext.commands import Greedy
from sqlmodel import Session
import gauntlets
import helpers
@ -22,13 +23,16 @@ import helpers
# import in_game.simulations
# import in_game
# # from in_game import data_cache, simulations
from in_game.data_cache import get_pd_pitchingcard, get_pd_battingcard, get_pd_player
# from in_game.data_cache import get_pd_pitchingcard, get_pd_battingcard, get_pd_player
from in_game.gameplay_queries import get_team_or_none
from in_game.simulations import get_pos_embeds, get_result
from in_game.gameplay_models import Lineup, Play, Session, engine
from api_calls import db_get, db_post, db_patch, get_team_by_abbrev
from helpers import PD_PLAYERS_ROLE_NAME, IMAGES, PD_SEASON, random_conf_gif, fuzzy_player_search, ALL_MLB_TEAMS, \
fuzzy_search, get_channel, display_cards, get_card_embeds, get_team_embed, cardset_search, get_blank_team_card, \
get_team_by_owner, get_rosters, get_roster_sheet, legal_channel, random_conf_word, embed_pagination, get_cal_user, \
team_summary_embed, SelectView, SelectPaperdexCardset, SelectPaperdexTeam
from utilities.buttons import ask_with_buttons
logger = logging.getLogger('discord_app')
@ -939,7 +943,7 @@ class Players(commands.Cog):
@group_gauntlet.command(name='start', description='Start a new Gauntlet run')
@app_commands.checks.has_any_role(PD_PLAYERS_ROLE_NAME)
async def gauntlet_start_command(
self, interaction: discord.Interaction, event_name: Literal['2024 Season', 'Super Ultra Championship']):
self, interaction: discord.Interaction):
if 'hello' not in interaction.channel.name:
await interaction.response.send_message(
content='The draft will probably take you about 15 minutes. Why don\'t you head to your private '
@ -948,66 +952,82 @@ class Players(commands.Cog):
)
return
logger.info(f'Starting a gauntlet run for user {interaction.user.name}')
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"]}')
e_query = await db_get('events', params=[("name", event_name), ("active", True)])
if e_query['count'] == 0:
await interaction.edit_original_response(content='Hmm...looks like that event is inactive.')
return
else:
this_event = e_query['events'][0]
with Session(engine) as session:
main_team = await get_team_or_none(session, gm_id=interaction.user.id, main_team=True)
draft_team = await get_team_or_none(session, gm_id=interaction.user.id, gauntlet_team=True)
first_flag = draft_team is None
if draft_team is not None:
r_query = await db_get(
'gauntletruns',
params=[('team_id', draft_team['id']), ('gauntlet_id', this_event['id']), ('is_active', True)]
)
e_query = await db_get('events', params=[("active", True)])
if e_query['count'] == 0:
await interaction.edit_original_response(content='Hmm...I don\'t see any active events.')
return
elif e_query['count'] == 1:
this_event = e_query['events'][0]
else:
event_choice = await ask_with_buttons(
interaction,
button_options=[x['name'] for x in e_query['events']],
question='Which event would you like to take on?',
# edit_original_interaction=True,
timeout=3,
delete_question=False
)
this_event = [event for event in e_query['events'] if event['name'] == event_choice][0]
# await interaction.channel.send(
# content=f'You chose the {event_choice} event!'
# )
logger.info(f'this_event: {this_event}')
if r_query['count'] != 0:
await interaction.edit_original_response(
content=f'Looks like you already have a {r_query["runs"][0]["gauntlet"]["name"]} run active! '
f'You can check it out with the `/gauntlets status` command.'
first_flag = draft_team is None
if draft_team is not None:
r_query = await db_get(
'gauntletruns',
params=[('team_id', draft_team.id), ('gauntlet_id', this_event['id']), ('is_active', True)]
)
if r_query['count'] != 0:
await interaction.edit_original_response(
content=f'Looks like you already have a {r_query["runs"][0]["gauntlet"]["name"]} run active! '
f'You can check it out with the `/gauntlets status` command.'
)
return
try:
draft_embed = await gauntlets.run_draft(interaction, main_team, this_event, draft_team)
except ZeroDivisionError as e:
return
except Exception as e:
logger.error(f'Failed to run {this_event["name"]} draft for the {main_team.sname}: {e}')
await gauntlets.wipe_team(draft_team, interaction)
await interaction.channel.send(
content=f'Shoot - it looks like we ran into an issue running the draft. I had to clear it all out '
f'for now. I let {get_cal_user(interaction).mention} know what happened so he better '
f'fix it quick.'
)
return
try:
draft_embed = await gauntlets.run_draft(interaction, main_team, this_event, draft_team)
except ZeroDivisionError as e:
return
except Exception as e:
logger.error(f'Failed to run {event_name} draft for the {main_team["sname"]}: {e}')
draft_team = await db_get('teams', params=[('abbrev', f'Gauntlet-{main_team["abbrev"]}')])
await gauntlets.wipe_team(draft_team, interaction)
await interaction.channel.send(
content=f'Shoot - it looks like we ran into an issue running the draft. I had to clear it all out '
f'for now. I let {get_cal_user(interaction).mention} know what happened so he better '
f'fix it quick.'
)
return
if first_flag:
await interaction.channel.send(
f'Good luck, champ in the making! To start playing, follow these steps:\n\n'
f'1) Make a copy of the Team Sheet Template found in `/help-pd links`\n'
f'2) Run `/newsheet` to link it to your Gauntlet team\n'
f'3) Go play your first game with `/new-game gauntlet {this_event["name"]}`'
)
else:
await interaction.channel.send(
f'Good luck, champ in the making! In your team sheet, sync your cards with **Paper Dynasty** -> '
f'**Data Imports** -> **My Cards** then you can set your lineup here and you\'ll be ready to go!\n\n'
f'{get_roster_sheet(draft_team)}'
)
if first_flag:
await interaction.channel.send(
f'Good luck, champ in the making! To start playing, follow these steps:\n\n'
f'1) Make a copy of the Team Sheet Template found in `/help-pd links`\n'
f'2) Run `/newsheet` to link it to your Gauntlet team\n'
f'3) Go play your first game with `/new-game gauntlet {this_event["name"]}`'
await helpers.send_to_channel(
bot=self.bot,
channel_name='pd-news-ticker',
content=f'The {main_team["lname"]} have entered the {this_event["name"]} Gauntlet!',
embed=draft_embed
)
else:
await interaction.channel.send(
f'Good luck, champ in the making! In your team sheet, sync your cards with **Paper Dynasty** -> '
f'**Data Imports** -> **Team Cards** then you can set your lineup here and you\'ll be ready to go!\n\n'
f'{get_roster_sheet(draft_team)}'
)
await helpers.send_to_channel(
bot=self.bot,
channel_name='pd-news-ticker',
content=f'The {main_team["lname"]} have entered the {this_event["name"]} Gauntlet!',
embed=draft_embed
)
@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)
@ -1644,52 +1664,52 @@ class Players(commands.Cog):
this_player = await get_one_player(player_name)
logger.debug(f'this_player: {this_player}')
@app_commands.command(name='matchup', description='Simulate a matchup between a pitcher and batter')
@app_commands.describe(
pitcher_id='The pitcher\'s player_id',
batter_id='The batter\'s player_id'
)
async def matchup_command(self, interaction: discord.Interaction, pitcher_id: int, batter_id: int):
await interaction.response.defer()
try:
pit_card = await get_pd_pitchingcard(pitcher_id)
except KeyError as e:
await interaction.edit_original_response(
content=f'I could not find a pitcher card for player_id {pitcher_id}'
)
return
try:
bat_card = await get_pd_battingcard(batter_id)
except KeyError as e:
await interaction.edit_original_response(
content=f'I could not find a batter card for player_id {batter_id}'
)
return
# @app_commands.command(name='matchup', description='Simulate a matchup between a pitcher and batter')
# @app_commands.describe(
# pitcher_id='The pitcher\'s player_id',
# batter_id='The batter\'s player_id'
# )
# async def matchup_command(self, interaction: discord.Interaction, pitcher_id: int, batter_id: int):
# await interaction.response.defer()
# try:
# pit_card = await get_pd_pitchingcard(pitcher_id)
# except KeyError as e:
# await interaction.edit_original_response(
# content=f'I could not find a pitcher card for player_id {pitcher_id}'
# )
# return
# try:
# bat_card = await get_pd_battingcard(batter_id)
# except KeyError as e:
# await interaction.edit_original_response(
# content=f'I could not find a batter card for player_id {batter_id}'
# )
# return
this_pitcher = await get_pd_player(pitcher_id)
this_batter = await get_pd_player(batter_id)
# this_pitcher = await get_pd_player(pitcher_id)
# this_batter = await get_pd_player(batter_id)
# view = helpers.ButtonOptions(
# responders=[interaction.user], timeout=60,
# labels=['Reroll', None, None, None, None]
# )
# # view = helpers.ButtonOptions(
# # responders=[interaction.user], timeout=60,
# # labels=['Reroll', None, None, None, None]
# # )
await interaction.edit_original_response(
content=None,
embeds=get_pos_embeds(this_pitcher, this_batter, pit_card, bat_card),
# view=view
)
# await view.wait()
#
# if view.value:
# await question.delete()
# if view.value == 'Tagged Up':
# advance_one_runner(this_play.id, from_base=2, num_bases=1)
# elif view.value == 'Out at 3rd':
# num_outs += 1
# patch_play(this_play.id, on_second_final=False, outs=num_outs)
# else:
# await question.delete()
# await interaction.edit_original_response(
# content=None,
# embeds=get_pos_embeds(this_pitcher, this_batter, pit_card, bat_card),
# # view=view
# )
# # await view.wait()
# #
# # if view.value:
# # await question.delete()
# # if view.value == 'Tagged Up':
# # advance_one_runner(this_play.id, from_base=2, num_bases=1)
# # elif view.value == 'Out at 3rd':
# # num_outs += 1
# # patch_play(this_play.id, on_second_final=False, outs=num_outs)
# # else:
# # await question.delete()
async def setup(bot):