From a1c44a0540255eb9125d3e4434eaa109dbee4a70 Mon Sep 17 00:00:00 2001 From: Cal Corum Date: Mon, 13 May 2024 17:02:32 -0500 Subject: [PATCH] Refactor /buy pack --- cogs/economy.py | 170 +++++++++++++++++++++++++++--------------------- helpers.py | 1 + 2 files changed, 98 insertions(+), 73 deletions(-) diff --git a/cogs/economy.py b/cogs/economy.py index 1341b30..9f6d74a 100644 --- a/cogs/economy.py +++ b/cogs/economy.py @@ -821,12 +821,8 @@ class Economy(commands.Cog): @group_buy.command(name='pack', description='Buy a pack or 7 from the marketplace') @app_commands.checks.has_any_role(PD_PLAYERS) - @app_commands.describe( - num_packs='Number of packs to purchase', - pack_name='Name of the pack you want (e.g. \'Standard\', \'Premium\')' - ) - async def buy_pack_slash(self, interaction: discord.Interaction, num_packs: int = 1, - pack_name: Literal['Standard', 'Premium'] = None): + @app_commands.describe() + async def buy_pack_slash(self, interaction: discord.Interaction): if interaction.channel.name in ['paper-dynasty-chat', 'pd-news-ticker', 'pd-network-news']: await interaction.response.send_message( f'Please head to down to {get_channel(interaction, "pd-bot-hole")} to run this command.', @@ -839,27 +835,50 @@ class Economy(commands.Cog): f'I don\'t see a team for you, yet. You can sign up with the `/newteam` command!' ) - if not pack_name: - p_query = await db_get('packtypes', params=[('available', True)]) - if 'count' not in p_query: - await interaction.response.send_message( - f'Welp, I couldn\'t find any packs in my database. Should probably go ping ' - f'{get_cal_user(interaction).mention} about that.' - ) - return - - embed = get_team_embed('Packs for Purchase') - embed.description = 'Run `/buy pack `' - for x in p_query['packtypes']: - embed.add_field(name=f'{x["name"]} - {x["cost"]}₼', value=f'{x["description"]}') - + p_query = await db_get('packtypes', params=[('available', True)]) + if 'count' not in p_query: await interaction.response.send_message( - content=None, - embed=embed + f'Welp, I couldn\'t find any packs in my database. Should probably go ping ' + f'{get_cal_user(interaction).mention} about that.' ) return - p_query = await db_get('packtypes', params=[('name', pack_name.lower().replace('pack', '')), ('available', True)]) + embed = get_team_embed('Packs for Purchase') + # embed.description = 'Run `/buy pack `' + for x in p_query['packtypes']: + embed.add_field(name=f'{x["name"]} - {x["cost"]}₼', value=f'{x["description"]}') + + pack_options = [x['name'] for x in p_query['packtypes'][:5] if x['available'] and x['cost']] + if len(pack_options) < 5: + pack_options.extend(['na' for x in range(5 - len(pack_options))]) + view = ButtonOptions( + responders=[interaction.user], timeout=60, + labels=pack_options + ) + + await interaction.response.send_message( + content=None, + embed=embed + ) + + question = await interaction.channel.send( + f'Which pack would you like to purchase?', view=view + ) + await view.wait() + + if view.value: + pack_name = view.value + await question.delete() + this_q = Question(self.bot, interaction.channel, 'How many would you like?', 'int', 60) + num_packs = await this_q.ask([interaction.user]) + else: + await question.delete() + await interaction.channel.send('Hm. Another window shopper. I\'ll be here when you\'re serious.') + return + + p_query = await db_get( + 'packtypes', params=[('name', pack_name.lower().replace('pack', '')), ('available', True)] + ) if 'count' not in p_query: await interaction.response.send_message( f'Hmm...I don\'t recognize {pack_name.title()} as a pack type. Check on that and get back to me.', @@ -873,6 +892,8 @@ class Economy(commands.Cog): pack_cover = IMAGES['pack-sta'] elif pack_type['name'] == 'Premium': pack_cover = IMAGES['pack-pre'] + elif pack_type['name'] == 'Promo Choice': + pack_cover = IMAGES['mvp-hype'] total_cost = pack_type['cost'] * num_packs pack_embed = image_embed( @@ -883,7 +904,7 @@ class Economy(commands.Cog): ) if total_cost > owner_team['wallet']: - await interaction.response.send_message( + await interaction.channel.send( content=None, embed=pack_embed ) @@ -896,65 +917,68 @@ class Economy(commands.Cog): return # Get Customization and make purchase - view = ButtonOptions( - [interaction.user], - timeout=15, - labels=['No Customization', 'Cardset', 'Franchise', None, None] - ) - view.option1.style = discord.ButtonStyle.danger - await interaction.response.send_message( - content='Would you like to apply a pack customization?', - embed=pack_embed, - view=view - ) - await view.wait() - await interaction.edit_original_response(content=None, view=None) + if pack_name in ['Standard', 'Premium']: + view = ButtonOptions( + [interaction.user], + timeout=15, + labels=['No Customization', 'Cardset', 'Franchise', None, None] + ) + view.option1.style = discord.ButtonStyle.danger + await interaction.response.send_message( + content='Would you like to apply a pack customization?', + embed=pack_embed, + view=view + ) + await view.wait() + await interaction.edit_original_response(content=None, view=None) - if not view.value: - await interaction.channel.send(f'You think on it and get back to me.') - return - elif view.value == 'Cardset': - await interaction.delete_original_response() - view = SelectView([SelectBuyPacksCardset(owner_team, num_packs, pack_type['id'], pack_embed, total_cost)]) - await interaction.channel.send( - content=None, - view=view - ) - elif view.value == 'Franchise': - await interaction.delete_original_response() - view = SelectView( - [ - SelectBuyPacksTeam('AL', owner_team, num_packs, pack_type['id'], pack_embed, total_cost), - SelectBuyPacksTeam('NL', owner_team, num_packs, pack_type['id'], pack_embed, total_cost) - ], - timeout=30 - ) - await interaction.channel.send( - content=None, - view=view - ) - else: - question = await confirm_pack_purchase(interaction, owner_team, num_packs, total_cost, pack_embed) - if question is None: + if not view.value: + await interaction.channel.send(f'You think on it and get back to me.') return - - purchase = await db_get( - f'teams/{owner_team["id"]}/buy/pack/{pack_type["id"]}', - params=[('ts', team_hash(owner_team)), ('quantity', num_packs)] - ) - if not purchase: - await question.edit( - f'That didn\'t go through for some reason. If this happens again, go ping the shit out of Cal.', - view=None + elif view.value == 'Cardset': + await interaction.delete_original_response() + view = SelectView([SelectBuyPacksCardset(owner_team, num_packs, pack_type['id'], pack_embed, total_cost)]) + await interaction.channel.send( + content=None, + view=view + ) + return + elif view.value == 'Franchise': + await interaction.delete_original_response() + view = SelectView( + [ + SelectBuyPacksTeam('AL', owner_team, num_packs, pack_type['id'], pack_embed, total_cost), + SelectBuyPacksTeam('NL', owner_team, num_packs, pack_type['id'], pack_embed, total_cost) + ], + timeout=30 + ) + await interaction.channel.send( + content=None, + view=view ) return + question = await confirm_pack_purchase(interaction, owner_team, num_packs, total_cost, pack_embed) + if question is None: + return + + purchase = await db_get( + f'teams/{owner_team["id"]}/buy/pack/{pack_type["id"]}', + params=[('ts', team_hash(owner_team)), ('quantity', num_packs)] + ) + if not purchase: await question.edit( - content=f'{"They are" if num_packs > 1 else "It is"} all yours! Go rip \'em with `/open-packs`', + f'That didn\'t go through for some reason. If this happens again, go ping the shit out of Cal.', view=None ) return + await question.edit( + content=f'{"They are" if num_packs > 1 else "It is"} all yours! Go rip \'em with `/open-packs`', + view=None + ) + return + @app_commands.command(name='selldupes', description='Sell all of your duplicate cards') @app_commands.checks.has_any_role(PD_PLAYERS) @commands.check(legal_channel) diff --git a/helpers.py b/helpers.py index e5ea83b..1b78e71 100644 --- a/helpers.py +++ b/helpers.py @@ -20,6 +20,7 @@ from typing import Optional, Literal SBA_SEASON = 9 PD_SEASON = 7 LIVE_CARDSET_ID = 17 +LIVE_PROMO_CARDSET_ID = 18 SBA_COLOR = 'a6ce39' PD_PLAYERS = 'Paper Dynasty Players' SBA_PLAYERS_ROLE_NAME = f'Season {SBA_SEASON} Players'