coollsd commited on
Commit
729c61b
·
verified ·
1 Parent(s): da55a4c

Create currentbets.py

Browse files
Files changed (1) hide show
  1. currentbets.py +32 -0
currentbets.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import discord
2
+ from discord import app_commands
3
+ @app_commands.command(name="currentbets", description="View and manage your current bets")
4
+ async def currentbets(interaction: discord.Interaction):
5
+ user_id = interaction.user.id
6
+ if user_id not in user_bets or not user_bets[user_id]:
7
+ await interaction.response.send_message("You have no active bets.")
8
+ return
9
+
10
+ embed = discord.Embed(title="Your Current Bets", color=0x787878)
11
+ for i, bet in enumerate(user_bets[user_id]):
12
+ scores = await fetch_nhl_scores()
13
+ game = next((g for g in scores['games'] if g['teams']['away']['abbreviation'] == bet['game_data']['teams']['away']['abbreviation'] and
14
+ g['teams']['home']['abbreviation'] == bet['game_data']['teams']['home']['abbreviation']), None)
15
+
16
+ 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)
17
+
18
+ view = discord.ui.View()
19
+ cancel_select = discord.ui.Select(placeholder="Select a bet to cancel", options=[
20
+ discord.SelectOption(label=f"Bet {i+1}", value=str(i)) for i in range(len(user_bets[user_id]))
21
+ ])
22
+ view.add_item(cancel_select)
23
+
24
+ async def cancel_callback(interaction: discord.Interaction):
25
+ bet_index = int(cancel_select.values[0])
26
+ cancelled_bet = user_bets[user_id].pop(bet_index)
27
+ user_cash[user_id] += cancelled_bet['amount']
28
+ await interaction.response.send_message(f"Bet cancelled. ${cancelled_bet['amount']} has been refunded.")
29
+
30
+ cancel_select.callback = cancel_callback
31
+
32
+ await interaction.response.send_message(embed=embed, view=view)