Spaces:
Building
Building
Update sportbet.py
Browse files- sportbet.py +17 -15
sportbet.py
CHANGED
@@ -141,11 +141,24 @@ async def sportbet(interaction: discord.Interaction):
|
|
141 |
|
142 |
game_select.callback = game_callback
|
143 |
|
144 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
async def currentbets(interaction: discord.Interaction):
|
146 |
user_id = interaction.user.id
|
147 |
if user_id not in user_bets or not user_bets[user_id]:
|
148 |
-
await interaction.response.send_message("You have no bets.")
|
149 |
return
|
150 |
|
151 |
embed = discord.Embed(title="Your Current Bets", color=0x787878)
|
@@ -156,18 +169,7 @@ async def currentbets(interaction: discord.Interaction):
|
|
156 |
|
157 |
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)
|
158 |
|
159 |
-
view =
|
160 |
-
cancel_select = discord.
|
161 |
-
discord.SelectOption(label=f"Bet {i+1}", value=str(i)) for i in range(len(user_bets[user_id]))
|
162 |
-
])
|
163 |
-
view.add_item(cancel_select)
|
164 |
-
|
165 |
-
async def cancel_callback(interaction: discord.Interaction):
|
166 |
-
bet_index = int(cancel_select.values[0])
|
167 |
-
cancelled_bet = user_bets[user_id].pop(bet_index)
|
168 |
-
user_cash[user_id] += cancelled_bet['amount']
|
169 |
-
await interaction.response.send_message(f"Bet cancelled. ${cancelled_bet['amount']} has been refunded.")
|
170 |
-
|
171 |
-
cancel_select.callback = cancel_callback
|
172 |
|
173 |
await interaction.response.send_message(embed=embed, view=view)
|
|
|
141 |
|
142 |
game_select.callback = game_callback
|
143 |
|
144 |
+
class CancelBetView(discord.ui.View):
|
145 |
+
def __init__(self, user_id):
|
146 |
+
super().__init__()
|
147 |
+
self.user_id = user_id
|
148 |
+
|
149 |
+
@discord.ui.select(placeholder="Select a bet to cancel", options=[])
|
150 |
+
async def cancel_select(self, interaction: discord.Interaction, select: discord.ui.Select):
|
151 |
+
bet_index = int(select.values[0])
|
152 |
+
cancelled_bet = user_bets[self.user_id].pop(bet_index)
|
153 |
+
user_cash[self.user_id] += cancelled_bet['amount']
|
154 |
+
await interaction.response.send_message(f"Bet cancelled. ${cancelled_bet['amount']} has been refunded.")
|
155 |
+
self.stop()
|
156 |
+
|
157 |
+
@app_commands.command(name="currentbets", description="view your current bets and cancel them")
|
158 |
async def currentbets(interaction: discord.Interaction):
|
159 |
user_id = interaction.user.id
|
160 |
if user_id not in user_bets or not user_bets[user_id]:
|
161 |
+
await interaction.response.send_message("You have no active bets.")
|
162 |
return
|
163 |
|
164 |
embed = discord.Embed(title="Your Current Bets", color=0x787878)
|
|
|
169 |
|
170 |
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)
|
171 |
|
172 |
+
view = CancelBetView(user_id)
|
173 |
+
view.cancel_select.options = [discord.SelectOption(label=f"Cancel Bet {i+1}", value=str(i)) for i in range(len(user_bets[user_id]))]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
174 |
|
175 |
await interaction.response.send_message(embed=embed, view=view)
|