Spaces:
Building
Building
Update currentbets.py
Browse files- currentbets.py +17 -55
currentbets.py
CHANGED
@@ -1,72 +1,34 @@
|
|
1 |
-
from discord import app_commands
|
2 |
import discord
|
3 |
-
from
|
|
|
4 |
|
5 |
-
@app_commands.command(name="currentbets", description="
|
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
|
10 |
return
|
11 |
|
12 |
embed = discord.Embed(title="Your Current Bets", color=0x787878)
|
13 |
-
for i, bet in enumerate(user_bets[user_id]
|
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 |
-
|
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 |
-
|
28 |
-
|
29 |
-
|
30 |
-
)
|
31 |
|
32 |
-
async def
|
33 |
-
bet_index = int(
|
34 |
-
|
35 |
-
user_cash[user_id] +=
|
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]
|
41 |
-
|
42 |
-
# Update the embed and view
|
43 |
-
new_embed = discord.Embed(title="Your Current Bets", color=0x787878)
|
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 |
|
69 |
-
|
70 |
-
view.add_item(select)
|
71 |
|
72 |
-
await interaction.response.send_message(embed=embed, view=view
|
|
|
|
|
1 |
import discord
|
2 |
+
from discord import app_commands
|
3 |
+
from shared import user_cash, user_bets, fetch_nhl_scores
|
4 |
|
5 |
+
@app_commands.command(name="currentbets", description="view your 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("You have no bets.")
|
10 |
return
|
11 |
|
12 |
embed = discord.Embed(title="Your Current Bets", color=0x787878)
|
13 |
+
for i, bet in enumerate(user_bets[user_id]):
|
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 |
+
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)
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
view = discord.ui.View()
|
21 |
+
cancel_select = discord.ui.Select(placeholder="Select a bet to cancel", options=[
|
22 |
+
discord.SelectOption(label=f"Bet {i+1}", value=str(i)) for i in range(len(user_bets[user_id]))
|
23 |
+
])
|
24 |
+
view.add_item(cancel_select)
|
25 |
|
26 |
+
async def cancel_callback(interaction: discord.Interaction):
|
27 |
+
bet_index = int(cancel_select.values[0])
|
28 |
+
cancelled_bet = user_bets[user_id].pop(bet_index)
|
29 |
+
user_cash[user_id] += cancelled_bet['amount']
|
30 |
+
await interaction.response.send_message(f"Bet cancelled. ${cancelled_bet['amount']} has been refunded.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
+
cancel_select.callback = cancel_callback
|
|
|
33 |
|
34 |
+
await interaction.response.send_message(embed=embed, view=view)
|