diff --git a/cogs/players.py b/cogs/players.py index a9c9ea8..4c0d018 100644 --- a/cogs/players.py +++ b/cogs/players.py @@ -1014,6 +1014,59 @@ class Players(commands.Cog): 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) + async def gauntlet_reset_command( + self, interaction: discord.Interaction, event_name: Literal['2024 Live', 'Super Ultra Championship']): + 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"]}') + if draft_team is None: + await interaction.edit_original_response( + content='Hmm, I can\'t find a gauntlet team for you. Have you signed up already?') + return + + 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] + + r_query = await db_get('gauntletruns', params=[ + ('team_id', draft_team['id']), ('is_active', True), ('gauntlet_id', this_event['id']) + ]) + + if r_query['count'] != 0: + this_run = r_query['runs'][0] + else: + await interaction.edit_original_response( + content=f'I do not see an active run for the {draft_team["lname"]}.' + ) + return + + view = helpers.Confirm(responders=[interaction.user], timeout=60) + conf_string = f'Are you sure you want to wipe your active run?' + await interaction.edit_original_response( + content=conf_string, + view=view + ) + await view.wait() + + if view.value: + await gauntlets.end_run(this_run, this_event, draft_team) + await interaction.edit_original_response( + content=f'Your {event_name} run has been reset. Run `/gauntlets start {event_name}` to redraft!', + view=None + ) + + else: + await interaction.edit_original_response( + content=f'~~{conf_string}~~\n\nNo worries, I will leave it active.', + view=None + ) + + # @commands.command(name='standings', aliases=['leaders', 'points', 'weekly'], help='Weekly standings') # async def standings_command(self, ctx, *week_or_season): # if not await legal_channel(ctx): diff --git a/gauntlets.py b/gauntlets.py index 7e39178..fec8e99 100644 --- a/gauntlets.py +++ b/gauntlets.py @@ -14,10 +14,11 @@ from db_calls import db_get, db_post, db_delete, db_patch async def wipe_team(this_team, interaction: discord.Interaction, delete_team: bool = False, delete_runs: bool = False): await interaction.edit_original_response(content=f'Looking for cards...') # Delete cards - c_query = await db_get('cards', params=[('team_id', this_team['id'])]) - await interaction.edit_original_response(content=f'Found {c_query["count"]} cards; deleting cards...') - for x in c_query['cards']: - await db_delete('cards', object_id=x['id']) + # c_query = await db_get('cards', params=[('team_id', this_team['id'])]) + # await interaction.edit_original_response(content=f'Found {c_query["count"]} cards; deleting cards...') + # for x in c_query['cards']: + # await db_delete('cards', object_id=x['id']) + c_query = await db_post(f'cards/wipe-team/{this_team["id"]}') # Delete packs await interaction.edit_original_response(content=f'Done deleting cards; searching for packs...') @@ -1584,6 +1585,21 @@ async def get_embed(this_run=None, this_event=None, this_team=None): return embed +async def end_run(this_run, this_event, this_team): + this_run = await db_patch( + 'gauntletruns', + object_id=this_run['id'], + params=[('ended', True)] + ) + l_message = f'Tough loss. That brings your {this_event["name"]} record to ' \ + f'**{this_run["wins"]}-{this_run["losses"]}**. ' + if this_run['losses'] == 2: + l_message += 'That\'s the end of this run - better luck next time!' + c_query = await db_post(f'cards/wipe-team/{this_team["id"]}') + + return l_message + + async def post_result(run_id: int, is_win: bool, this_team, bot, channel): this_run = await db_get('gauntletruns', object_id=run_id) this_event = await db_get('events', object_id=this_run['gauntlet']['id']) @@ -1666,19 +1682,27 @@ async def post_result(run_id: int, is_win: bool, this_team, bot, channel): embed=await get_embed(this_run) ) else: + # this_run = await db_patch( + # 'gauntletruns', + # object_id=this_run['id'], + # params=[('losses', this_run['losses'] + 1), ('ended', this_run['losses'] + 1 == 2)] + # ) + # l_message = f'Tough loss. That brings your {this_event["name"]} record to ' \ + # f'**{this_run["wins"]}-{this_run["losses"]}**. ' + # if this_run['losses'] == 2: + # l_message += 'That\'s the end of this run - better luck next time!' + # c_query = await db_post(f'cards/wipe-team/{this_team["id"]}') + # this_run = await db_patch( 'gauntletruns', object_id=this_run['id'], - params=[('losses', this_run['losses'] + 1), ('ended', this_run['losses'] + 1 == 2)] + params=[('losses', this_run['losses'] + 1)] ) - l_message = f'Tough loss. That brings your {this_event["name"]} record to ' \ - f'**{this_run["wins"]}-{this_run["losses"]}**. ' - if this_run['losses'] == 2: - l_message += 'That\'s the end of this run - better luck next time!' - c_query = await db_post(f'cards/wipe-team/{this_team["id"]}') + l_message = await end_run(this_run, this_event, this_team) await channel.send( content=l_message, embed=await get_embed(this_run) ) +