import discord from discord import app_commands from shared import user_cash, user_bets, fetch_nhl_scores @app_commands.command(name="currentbets", description="view your bets") async def currentbets(interaction: discord.Interaction): user_id = interaction.user.id if user_id not in user_bets or not user_bets[user_id]: await interaction.response.send_message("You have no bets.") return embed = discord.Embed(title="Your Current Bets", color=0x787878) for i, bet in enumerate(user_bets[user_id]): scores = await fetch_nhl_scores() game = next((g for g in scores['games'] if g['teams']['away']['abbreviation'] == bet['game_data']['teams']['away']['abbreviation'] and g['teams']['home']['abbreviation'] == bet['game_data']['teams']['home']['abbreviation']), None) embed.add_field(name=f"Bet {i+1}", value=f"Team: {bet['team']}\nAmount: ${bet['amount']}\nGame: {bet['game_data']['teams']['away']['teamName']} vs {bet['game_data']['teams']['home']['teamName']}\nCurrent Score: {game['scores']['away']} - {game['scores']['home']}", inline=False) view = discord.ui.View() cancel_select = discord.ui.Select(placeholder="Select a bet to cancel", options=[ discord.SelectOption(label=f"Bet {i+1}", value=str(i)) for i in range(len(user_bets[user_id])) ]) view.add_item(cancel_select) async def cancel_callback(interaction: discord.Interaction): bet_index = int(cancel_select.values[0]) cancelled_bet = user_bets[user_id].pop(bet_index) user_cash[user_id] += cancelled_bet['amount'] await interaction.response.send_message(f"Bet cancelled. ${cancelled_bet['amount']} has been refunded.") cancel_select.callback = cancel_callback await interaction.response.send_message(embed=embed, view=view)