coollsd commited on
Commit
cf00815
1 Parent(s): 14b4ddb

Update currentbets.py

Browse files
Files changed (1) hide show
  1. currentbets.py +23 -11
currentbets.py CHANGED
@@ -1,34 +1,40 @@
1
  from discord import app_commands
2
  import discord
3
- from your_main_file import user_bets, user_cash
4
 
5
- @app_commands.command(name="currentbets", description="view bets")
6
  async def currentbets(interaction: discord.Interaction):
7
  user_id = interaction.user.id
8
  if user_id not in user_bets or not user_bets[user_id]:
9
- await interaction.response.send_message("no bets", ephemeral=True)
10
  return
11
 
12
- embed = discord.Embed(title="Current Bets", color=0x787878)
13
  for i, bet in enumerate(user_bets[user_id], 1):
 
 
 
 
 
 
14
  embed.add_field(
15
  name=f"Bet {i}",
16
- value=f"Team: {bet['team']}\nAmount: ${bet['amount']}\nGame: {bet['game_data']['teams']['away']['teamName']} vs {bet['game_data']['teams']['home']['teamName']}\nStart Time: {bet['game_data']['startTime']}",
17
  inline=False
18
  )
19
 
20
  view = discord.ui.View()
21
  select = discord.ui.Select(
22
- placeholder="Select a bet to delete",
23
  options=[discord.SelectOption(label=f"Bet {i}", value=str(i-1)) for i in range(1, len(user_bets[user_id])+1)]
24
  )
25
 
26
  async def select_callback(interaction: discord.Interaction):
27
  bet_index = int(select.values[0])
28
  removed_bet = user_bets[user_id].pop(bet_index)
29
- user_cash[user_id] += removed_bet['amount']
30
 
31
- await interaction.response.send_message(f"Bet on {removed_bet['team']} for ${removed_bet['amount']} has been deleted and refunded.", ephemeral=True)
32
 
33
  if not user_bets[user_id]:
34
  del user_bets[user_id]
@@ -38,19 +44,25 @@ async def currentbets(interaction: discord.Interaction):
38
  new_view = discord.ui.View()
39
  if user_id in user_bets and user_bets[user_id]:
40
  for i, bet in enumerate(user_bets[user_id], 1):
 
 
 
 
 
 
41
  new_embed.add_field(
42
  name=f"Bet {i}",
43
- value=f"Team: {bet['team']}\nAmount: ${bet['amount']}\nGame: {bet['game_data']['teams']['away']['teamName']} vs {bet['game_data']['teams']['home']['teamName']}\nStart Time: {bet['game_data']['startTime']}",
44
  inline=False
45
  )
46
  new_select = discord.ui.Select(
47
- placeholder="Select a bet to delete",
48
  options=[discord.SelectOption(label=f"Bet {i}", value=str(i-1)) for i in range(1, len(user_bets[user_id])+1)]
49
  )
50
  new_select.callback = select_callback
51
  new_view.add_item(new_select)
52
  else:
53
- new_embed.description = "You don't have any bets."
54
 
55
  await interaction.message.edit(embed=new_embed, view=new_view)
56
 
 
1
  from discord import app_commands
2
  import discord
3
+ from main import user_cash, user_bets, fetch_nhl_scores
4
 
5
+ @app_commands.command(name="currentbets", description="vie wbets")
6
  async def currentbets(interaction: discord.Interaction):
7
  user_id = interaction.user.id
8
  if user_id not in user_bets or not user_bets[user_id]:
9
+ await interaction.response.send_message("You got any bets.", ephemeral=True)
10
  return
11
 
12
+ embed = discord.Embed(title="Your Current Bets", color=0x787878)
13
  for i, bet in enumerate(user_bets[user_id], 1):
14
+ scores = await fetch_nhl_scores()
15
+ game = next((g for g in scores['games'] if g['teams']['away']['abbreviation'] == bet['game_data']['teams']['away']['abbreviation'] and
16
+ g['teams']['home']['abbreviation'] == bet['game_data']['teams']['home']['abbreviation']), None)
17
+
18
+ score_info = f"Current Score: {game['scores']['away']} - {game['scores']['home']}" if game and 'scores' in game else "Score not available"
19
+
20
  embed.add_field(
21
  name=f"Bet {i}",
22
+ value=f"Team: {bet['team']}\nAmount: ${bet['amount']}\nGame: {bet['game_data']['teams']['away']['teamName']} vs {bet['game_data']['teams']['home']['teamName']}\n{score_info}",
23
  inline=False
24
  )
25
 
26
  view = discord.ui.View()
27
  select = discord.ui.Select(
28
+ placeholder="Select a bet to cancel",
29
  options=[discord.SelectOption(label=f"Bet {i}", value=str(i-1)) for i in range(1, len(user_bets[user_id])+1)]
30
  )
31
 
32
  async def select_callback(interaction: discord.Interaction):
33
  bet_index = int(select.values[0])
34
  removed_bet = user_bets[user_id].pop(bet_index)
35
+ user_cash[user_id] += removed_bet['amount'] # Refund the bet amount
36
 
37
+ await interaction.response.send_message(f"Bet on {removed_bet['team']} for ${removed_bet['amount']} has been cancelled and refunded.", ephemeral=True)
38
 
39
  if not user_bets[user_id]:
40
  del user_bets[user_id]
 
44
  new_view = discord.ui.View()
45
  if user_id in user_bets and user_bets[user_id]:
46
  for i, bet in enumerate(user_bets[user_id], 1):
47
+ scores = await fetch_nhl_scores()
48
+ game = next((g for g in scores['games'] if g['teams']['away']['abbreviation'] == bet['game_data']['teams']['away']['abbreviation'] and
49
+ g['teams']['home']['abbreviation'] == bet['game_data']['teams']['home']['abbreviation']), None)
50
+
51
+ score_info = f"Current Score: {game['scores']['away']} - {game['scores']['home']}" if game and 'scores' in game else "Score not available"
52
+
53
  new_embed.add_field(
54
  name=f"Bet {i}",
55
+ value=f"Team: {bet['team']}\nAmount: ${bet['amount']}\nGame: {bet['game_data']['teams']['away']['teamName']} vs {bet['game_data']['teams']['home']['teamName']}\n{score_info}",
56
  inline=False
57
  )
58
  new_select = discord.ui.Select(
59
+ placeholder="Select a bet to cancel",
60
  options=[discord.SelectOption(label=f"Bet {i}", value=str(i-1)) for i in range(1, len(user_bets[user_id])+1)]
61
  )
62
  new_select.callback = select_callback
63
  new_view.add_item(new_select)
64
  else:
65
+ new_embed.description = "none active bets."
66
 
67
  await interaction.message.edit(embed=new_embed, view=new_view)
68