Spaces:
Building
Building
Update sportbet.py
Browse files- sportbet.py +32 -1
sportbet.py
CHANGED
@@ -142,4 +142,35 @@ async def sportbet(interaction: discord.Interaction):
|
|
142 |
|
143 |
team_select.callback = team_callback
|
144 |
|
145 |
-
game_select.callback = game_callback
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
142 |
|
143 |
team_select.callback = team_callback
|
144 |
|
145 |
+
game_select.callback = game_callback
|
146 |
+
|
147 |
+
@app_commands.command(name="currentbets", description="view your bets")
|
148 |
+
async def currentbets(interaction: discord.Interaction):
|
149 |
+
user_id = interaction.user.id
|
150 |
+
if user_id not in user_bets or not user_bets[user_id]:
|
151 |
+
await interaction.response.send_message("You have no bets.")
|
152 |
+
return
|
153 |
+
|
154 |
+
embed = discord.Embed(title="Your Current Bets", color=0x787878)
|
155 |
+
for i, bet in enumerate(user_bets[user_id]):
|
156 |
+
scores = await fetch_nhl_scores()
|
157 |
+
game = next((g for g in scores['games'] if g['teams']['away']['abbreviation'] == bet['game_data']['teams']['away']['abbreviation'] and
|
158 |
+
g['teams']['home']['abbreviation'] == bet['game_data']['teams']['home']['abbreviation']), None)
|
159 |
+
|
160 |
+
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)
|
161 |
+
|
162 |
+
view = discord.ui.View()
|
163 |
+
cancel_select = discord.ui.Select(placeholder="Select a bet to cancel", options=[
|
164 |
+
discord.SelectOption(label=f"Bet {i+1}", value=str(i)) for i in range(len(user_bets[user_id]))
|
165 |
+
])
|
166 |
+
view.add_item(cancel_select)
|
167 |
+
|
168 |
+
async def cancel_callback(interaction: discord.Interaction):
|
169 |
+
bet_index = int(cancel_select.values[0])
|
170 |
+
cancelled_bet = user_bets[user_id].pop(bet_index)
|
171 |
+
user_cash[user_id] += cancelled_bet['amount']
|
172 |
+
await interaction.response.send_message(f"Bet cancelled. ${cancelled_bet['amount']} has been refunded.")
|
173 |
+
|
174 |
+
cancel_select.callback = cancel_callback
|
175 |
+
|
176 |
+
await interaction.response.send_message(embed=embed, view=view)
|