Spaces:
Building
Building
Update sportbet.py
Browse files- sportbet.py +28 -33
sportbet.py
CHANGED
@@ -64,16 +64,7 @@ class BetModal(discord.ui.Modal, title="Place Your Bet"):
|
|
64 |
raise ValueError("poor")
|
65 |
|
66 |
user_cash[self.user_id] -= bet_amount
|
67 |
-
await interaction.response.send_message(f"Bet placed on {self.team} for ${bet_amount}")
|
68 |
|
69 |
-
user = await interaction.client.fetch_user(self.user_id)
|
70 |
-
embed = discord.Embed(title="Bet Placed", color=0x787878)
|
71 |
-
embed.add_field(name="Team", value=self.team, inline=False)
|
72 |
-
embed.add_field(name="Amount", value=f"${bet_amount}", inline=False)
|
73 |
-
embed.add_field(name="Game", value=f"{self.game_data['teams']['away']['teamName']} vs {self.game_data['teams']['home']['teamName']}", inline=False)
|
74 |
-
embed.add_field(name="Start Time", value=self.game_data['startTime'], inline=False)
|
75 |
-
await user.send(embed=embed)
|
76 |
-
|
77 |
if self.user_id not in user_bets:
|
78 |
user_bets[self.user_id] = []
|
79 |
user_bets[self.user_id].append({
|
@@ -82,6 +73,17 @@ class BetModal(discord.ui.Modal, title="Place Your Bet"):
|
|
82 |
"game_data": self.game_data
|
83 |
})
|
84 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
asyncio.create_task(self.monitor_game(interaction, bet_amount))
|
86 |
except ValueError as e:
|
87 |
await interaction.response.send_message(str(e), ephemeral=True)
|
@@ -141,35 +143,28 @@ async def sportbet(interaction: discord.Interaction):
|
|
141 |
|
142 |
game_select.callback = game_callback
|
143 |
|
144 |
-
|
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)
|
165 |
for i, bet in enumerate(user_bets[user_id]):
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
171 |
|
172 |
-
|
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)
|
|
|
64 |
raise ValueError("poor")
|
65 |
|
66 |
user_cash[self.user_id] -= bet_amount
|
|
|
67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
if self.user_id not in user_bets:
|
69 |
user_bets[self.user_id] = []
|
70 |
user_bets[self.user_id].append({
|
|
|
73 |
"game_data": self.game_data
|
74 |
})
|
75 |
|
76 |
+
embed = discord.Embed(title="Bet Placed", color=0x787878)
|
77 |
+
embed.add_field(name="Team", value=self.team, inline=False)
|
78 |
+
embed.add_field(name="Amount", value=f"${bet_amount}", inline=False)
|
79 |
+
embed.add_field(name="Game", value=f"{self.game_data['teams']['away']['teamName']} vs {self.game_data['teams']['home']['teamName']}", inline=False)
|
80 |
+
embed.add_field(name="Start Time", value=self.game_data['startTime'], inline=False)
|
81 |
+
|
82 |
+
view = discord.ui.View()
|
83 |
+
view.add_item(discord.ui.Button(label="View Current Bets", custom_id="view_bets"))
|
84 |
+
|
85 |
+
await interaction.response.send_message(embed=embed, view=view)
|
86 |
+
|
87 |
asyncio.create_task(self.monitor_game(interaction, bet_amount))
|
88 |
except ValueError as e:
|
89 |
await interaction.response.send_message(str(e), ephemeral=True)
|
|
|
143 |
|
144 |
game_select.callback = game_callback
|
145 |
|
146 |
+
async def view_current_bets(interaction: discord.Interaction):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
147 |
user_id = interaction.user.id
|
148 |
if user_id not in user_bets or not user_bets[user_id]:
|
149 |
+
await interaction.response.send_message("You have no active bets.", ephemeral=True)
|
150 |
return
|
151 |
|
152 |
embed = discord.Embed(title="Your Current Bets", color=0x787878)
|
153 |
for i, bet in enumerate(user_bets[user_id]):
|
154 |
+
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']}\nStart Time: {bet['game_data']['startTime']}", inline=False)
|
155 |
+
|
156 |
+
view = discord.ui.View()
|
157 |
+
cancel_select = discord.ui.Select(placeholder="Select a bet to cancel", options=[
|
158 |
+
discord.SelectOption(label=f"Cancel Bet {i+1}", value=str(i)) for i in range(len(user_bets[user_id]))
|
159 |
+
])
|
160 |
+
view.add_item(cancel_select)
|
161 |
+
|
162 |
+
async def cancel_callback(interaction: discord.Interaction):
|
163 |
+
bet_index = int(cancel_select.values[0])
|
164 |
+
cancelled_bet = user_bets[user_id].pop(bet_index)
|
165 |
+
user_cash[user_id] += cancelled_bet['amount']
|
166 |
+
await interaction.response.send_message(f"Bet cancelled. ${cancelled_bet['amount']} has been refunded.", ephemeral=True)
|
167 |
|
168 |
+
cancel_select.callback = cancel_callback
|
|
|
169 |
|
170 |
+
await interaction.response.send_message(embed=embed, view=view, ephemeral=True)
|