diff --git a/cogs/economy.py b/cogs/economy.py index 47c0b7d..5dca7e7 100644 --- a/cogs/economy.py +++ b/cogs/economy.py @@ -531,8 +531,14 @@ class Economy(commands.Cog): @app_commands.command(name='open-packs', description='Open packs from your inventory') @app_commands.checks.has_any_role(PD_PLAYERS) - @commands.check(legal_channel) async def open_packs_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.', + ephemeral=True + ) + return + owner_team = get_team_by_owner(interaction.user.id) if not owner_team: await interaction.response.send_message( @@ -583,7 +589,7 @@ class Economy(commands.Cog): if p_group is not None: p_count += 1 if p_group not in p_data: - p_data[p_group] = pack + p_data[p_group] = [pack] else: p_data[p_group].append(pack) @@ -613,7 +619,7 @@ class Economy(commands.Cog): embed.add_field(name=pretty_name, value=f'Qty: {len(p_data[key])}') select_options.append(discord.SelectOption(label=pretty_name, value=key)) - view = SelectView(select_objects=[SelectPackChoice(select_options)], timeout=15) + view = SelectView(select_objects=[SelectOpenPack(select_options)], timeout=15) await interaction.response.send_message(embed=embed, view=view) group_buy = app_commands.Group(name='buy', description='Make a purchase from the marketplace') @@ -736,7 +742,6 @@ class Economy(commands.Cog): ephemeral=True ) return - owner_team = get_team_by_owner(interaction.user.id) if not owner_team: await interaction.response.send_message( @@ -799,44 +804,66 @@ class Economy(commands.Cog): ) return - view = Confirm(responders=[interaction.user], timeout=30) - await interaction.response.send_message( - content=None, - embed=pack_embed + # Get Customization and make purchase + view = ButtonOptions( + [interaction.user], + timeout=15, + labels=['No Customization', 'Cardset', 'Franchise', None, None] ) - question = await interaction.channel.send( - # content=f'You currently have {num_copies} cop{"ies" if num_copies != 1 else "y"} of this card.\n\n' - content=f'Your Wallet: {owner_team["wallet"]}₼\n' - f'Pack{"s" if num_packs > 1 else ""} Price: {total_cost}₼\n' - f'After Purchase: {owner_team["wallet"] - total_cost}₼\n\n' - f'Would you like to make this purchase?', + 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: + return + + purchase = 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 + ) + return + await question.edit( - content='Saving that money. Smart.', + content=f'{"They are" if num_packs > 1 else "It is"} all yours! Go rip \'em with `/open-packs`', view=None ) return - purchase = 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 - ) - return - - await question.edit( - content=f'{"They are" if num_packs > 1 else "It is"} all yours! Go rip it with `/open`', - view=None - ) - @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 f60fdcb..f947aab 100644 --- a/helpers.py +++ b/helpers.py @@ -436,7 +436,7 @@ class Pagination(discord.ui.View): self.stop() -class SelectPackChoice(discord.ui.Select): +class SelectOpenPack(discord.ui.Select): def __init__(self, options: list): super().__init__(placeholder='Select a Pack Type', options=options) @@ -632,6 +632,223 @@ class SelectPaperdexTeam(discord.ui.Select): await embed_pagination(team_embeds, interaction.channel, interaction.user) +class SelectBuyPacksCardset(discord.ui.Select): + def __init__(self, team: dict, quantity: int, pack_type_id: int, pack_embed: discord.Embed, cost: int): + options = [ + discord.SelectOption(label='2022 Season'), + discord.SelectOption(label='2021 Season'), + discord.SelectOption(label='2019 Season'), + discord.SelectOption(label='2013 Season'), + discord.SelectOption(label='2012 Season') + ] + self.team = team + self.quantity = quantity + self.pack_type_id = pack_type_id + self.pack_embed = pack_embed + self.cost = cost + super().__init__(placeholder='Select a Cardset', options=options) + + async def callback(self, interaction: discord.Interaction): + logging.info(f'SelectBuyPacksCardset - selection: {self.values[0]}') + cardset_id = None + if self.values[0] == '2022 Season': + cardset_id = 3 + elif self.values[0] == '2021 Season': + cardset_id = 1 + elif self.values[0] == '2019 Season': + cardset_id = 5 + elif self.values[0] == '2013 Season': + cardset_id = 6 + elif self.values[0] == '2012 Season': + cardset_id = 7 + + self.pack_embed.description = f'{self.pack_embed.description} - {self.values[0]}' + view = Confirm(responders=[interaction.user], timeout=30) + await interaction.response.edit_message( + content=None, + embed=self.pack_embed, + view=None + ) + question = await interaction.channel.send( + content=f'Your Wallet: {self.team["wallet"]}₼\n' + f'Pack{"s" if self.quantity > 1 else ""} Price: {self.cost}₼\n' + f'After Purchase: {self.team["wallet"] - self.cost}₼\n\n' + f'Would you like to make this purchase?', + view=view + ) + await view.wait() + + if not view.value: + await question.edit( + content='Saving that money. Smart.', + view=None + ) + return + + p_model = { + 'team_id': self.team['id'], + 'pack_type_id': self.pack_type_id, + 'pack_cardset_id': cardset_id + } + db_post('packs', payload={'packs': [p_model for x in range(self.quantity)]}) + db_post(f'teams/{self.team["id"]}/money/-{self.cost}') + + await question.edit( + content=f'{"They are" if self.quantity > 1 else "It is"} all yours! Go rip \'em with `/open-packs`', + view=None + ) + + +class SelectBuyPacksTeam(discord.ui.Select): + def __init__( + self, which: Literal['AL', 'NL'], team: dict, quantity: int, pack_type_id: int, pack_embed: discord.Embed, + cost: int): + self.which = which + self.team = team + self.quantity = quantity + self.pack_type_id = pack_type_id + self.pack_embed = pack_embed + self.cost = cost + if which == 'AL': + options = [ + discord.SelectOption(label='Baltimore Orioles'), + discord.SelectOption(label='Boston Red Sox'), + discord.SelectOption(label='Chicago White Sox'), + discord.SelectOption(label='Cleveland Guardians'), + discord.SelectOption(label='Detroit Tigers'), + discord.SelectOption(label='Houston Astros'), + discord.SelectOption(label='Kansas City Royals'), + discord.SelectOption(label='Los Angeles Angels'), + discord.SelectOption(label='Minnesota Twins'), + discord.SelectOption(label='New York Yankees'), + discord.SelectOption(label='Oakland Athletics'), + discord.SelectOption(label='Seattle Mariners'), + discord.SelectOption(label='Tampa Bay Rays'), + discord.SelectOption(label='Texas Rangers'), + discord.SelectOption(label='Toronto Blue Jays') + ] + else: + options = [ + discord.SelectOption(label='Arizona Diamondbacks'), + discord.SelectOption(label='Atlanta Braves'), + discord.SelectOption(label='Chicago Cubs'), + discord.SelectOption(label='Cincinnati Reds'), + discord.SelectOption(label='Colorado Rockies'), + discord.SelectOption(label='Los Angeles Dodgers'), + discord.SelectOption(label='Miami Marlins'), + discord.SelectOption(label='Milwaukee Brewers'), + discord.SelectOption(label='New York Mets'), + discord.SelectOption(label='Philadelphia Phillies'), + discord.SelectOption(label='Pittsburgh Pirates'), + discord.SelectOption(label='San Diego Padres'), + discord.SelectOption(label='San Francisco Giants'), + discord.SelectOption(label='St. Louis Cardinals'), + discord.SelectOption(label='Washington Nationals') + ] + super().__init__(placeholder=f'Select an {which} team', options=options) + + async def callback(self, interaction: discord.Interaction): + team_id = None + if self.which == 'AL': + if self.values[0] == 'Baltimore Orioles': + team_id = 3 + elif self.values[0] == 'Boston Red Sox': + team_id = 4 + elif self.values[0] == 'Chicago White Sox': + team_id = 6 + elif self.values[0] == 'Cleveland Guardians': + team_id = 8 + elif self.values[0] == 'Detroit Tigers': + team_id = 10 + elif self.values[0] == 'Houston Astros': + team_id = 11 + elif self.values[0] == 'Kansas City Royals': + team_id = 12 + elif self.values[0] == 'Los Angeles Angels': + team_id = 13 + elif self.values[0] == 'Minnesota Twins': + team_id = 17 + elif self.values[0] == 'New York Yankees': + team_id = 19 + elif self.values[0] == 'Oakland Athletics': + team_id = 20 + elif self.values[0] == 'Seattle Mariners': + team_id = 24 + elif self.values[0] == 'Tampa Bay Rays': + team_id = 27 + elif self.values[0] == 'Texas Rangers': + team_id = 28 + elif self.values[0] == 'Toronto Blue Jays': + team_id = 29 + else: + if self.values[0] == 'Arizona Diamondbacks': + team_id = 1 + elif self.values[0] == 'Atlanta Braves': + team_id = 2 + elif self.values[0] == 'Chicago Cubs': + team_id = 5 + elif self.values[0] == 'Cincinnati Reds': + team_id = 7 + elif self.values[0] == 'Colorado Rockies': + team_id = 9 + elif self.values[0] == 'Los Angeles Dodgers': + team_id = 14 + elif self.values[0] == 'Miami Marlins': + team_id = 15 + elif self.values[0] == 'Milwaukee Brewers': + team_id = 16 + elif self.values[0] == 'New York Mets': + team_id = 18 + elif self.values[0] == 'Philadelphia Phillies': + team_id = 21 + elif self.values[0] == 'Pittsburgh Pirates': + team_id = 22 + elif self.values[0] == 'San Diego Padres': + team_id = 23 + elif self.values[0] == 'San Francisco Giants': + team_id = 25 + elif self.values[0] == 'St. Louis Cardinals': + team_id = 26 + elif self.values[0] == 'Washington Nationals': + team_id = 30 + + self.pack_embed.description = f'{self.pack_embed.description} - {self.values[0]}' + view = Confirm(responders=[interaction.user], timeout=30) + await interaction.response.edit_message( + content=None, + embed=self.pack_embed, + view=None + ) + question = await interaction.channel.send( + content=f'Your Wallet: {self.team["wallet"]}₼\n' + f'Pack{"s" if self.quantity > 1 else ""} Price: {self.cost}₼\n' + f'After Purchase: {self.team["wallet"] - self.cost}₼\n\n' + f'Would you like to make this purchase?', + view=view + ) + await view.wait() + + if not view.value: + await question.edit( + content='Saving that money. Smart.', + view=None + ) + return + + p_model = { + 'team_id': self.team['id'], + 'pack_type_id': self.pack_type_id, + 'pack_team_id': team_id + } + db_post('packs', payload={'packs': [p_model for x in range(self.quantity)]}) + db_post(f'teams/{self.team["id"]}/money/-{self.cost}') + + await question.edit( + content=f'{"They are" if self.quantity > 1 else "It is"} all yours! Go rip \'em with `/open-packs`', + view=None + ) + + class SelectView(discord.ui.View): def __init__(self, select_objects: [discord.ui.Select], timeout: float = 300.0): super().__init__(timeout=timeout) @@ -1659,10 +1876,16 @@ async def roll_for_cards(all_packs: list, extra_val=None) -> list: mvp_flag = None if counts[key]['count'] > 0: - pl = db_get('players/random', params=[ + params = [ ('min_rarity', counts[key]['rarity']), ('max_rarity', counts[key]['rarity']), ('limit', counts[key]['count']) - ]) + ] + if all_packs[0]['pack_team'] is not None: + params.append(('franchise', all_packs[0]['pack_team']['lname'])) + elif all_packs[0]['pack_cardset'] is not None: + params.append(('cardset_id', all_packs[0]['pack_cardset']['id'])) + + pl = db_get('players/random', params=params) if pl['count'] != counts[key]['count']: mvp_flag = counts[key]['count'] - pl['count'] @@ -2439,4 +2662,26 @@ async def open_choice_pack(this_pack, team: dict, context): await msg.edit(content=None, embeds=card_embeds[page_num - 1], view=view) +async def confirm_pack_purchase(interaction, owner_team, num_packs, total_cost, pack_embed): + view = Confirm(responders=[interaction.user], timeout=30) + await interaction.edit_original_response( + content=None, + embed=pack_embed + ) + question = await interaction.channel.send( + content=f'Your Wallet: {owner_team["wallet"]}₼\n' + f'Pack{"s" if num_packs > 1 else ""} Price: {total_cost}₼\n' + f'After Purchase: {owner_team["wallet"] - total_cost}₼\n\n' + f'Would you like to make this purchase?', + view=view + ) + await view.wait() + if not view.value: + await question.edit( + content='Saving that money. Smart.', + view=None + ) + return None + else: + return question