Spaces:
Building
Building
Update sportbet.py
Browse files- sportbet.py +180 -288
sportbet.py
CHANGED
@@ -1,325 +1,217 @@
|
|
1 |
import discord
|
2 |
from discord import app_commands
|
3 |
import aiohttp
|
4 |
-
import random
|
5 |
-
import time
|
6 |
import asyncio
|
7 |
-
|
8 |
from cash import user_cash
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
-
async def
|
18 |
-
|
19 |
-
|
20 |
-
async with session.get(url) as response:
|
21 |
-
if response.status == 200:
|
22 |
-
return await response.json()
|
23 |
-
return None
|
24 |
|
25 |
-
|
26 |
-
|
27 |
|
28 |
-
|
29 |
-
return None
|
30 |
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
|
|
|
|
|
|
|
|
35 |
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
|
46 |
-
|
|
|
|
|
47 |
|
48 |
-
|
49 |
-
|
|
|
50 |
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
elif difficulty >= 1_000_000:
|
59 |
-
return f"{difficulty / 1_000_000:.1f}M ({difficulty:,})"
|
60 |
-
elif difficulty >= 1_000:
|
61 |
-
return f"{difficulty / 1_000:.1f}K ({difficulty:,})"
|
62 |
-
else:
|
63 |
-
return f"{difficulty} ({difficulty:,})"
|
64 |
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
embed.add_field(name="Category", value=rolled_pet['category'], inline=True)
|
69 |
-
embed.set_thumbnail(url=thumbnail_url)
|
70 |
-
|
71 |
-
luck_text = ""
|
72 |
-
if user_id in luck_expiration:
|
73 |
-
remaining_time = int(luck_expiration[user_id] - time.time())
|
74 |
-
if remaining_time > 0:
|
75 |
-
luck_percentage = (luck_multiplier - 1) * 100
|
76 |
-
luck_text = f"\nYou have {remaining_time // 60} minutes and {remaining_time % 60} seconds of luck left! ({luck_percentage}% luck)"
|
77 |
-
else:
|
78 |
-
del luck_multipliers[user_id]
|
79 |
-
del luck_expiration[user_id]
|
80 |
-
|
81 |
-
embed.set_footer(text=f"Click 'Roll Again' to roll again!{luck_text}")
|
82 |
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
await interaction.response.defer()
|
87 |
-
result = await perform_roll(interaction)
|
88 |
-
if result:
|
89 |
-
await interaction.followup.send(embed=result[0], view=result[1])
|
90 |
-
else:
|
91 |
-
await interaction.followup.send("An error occurred.")
|
92 |
|
93 |
-
|
94 |
|
95 |
-
|
96 |
-
|
|
|
|
|
|
|
|
|
97 |
|
98 |
-
|
99 |
|
100 |
-
|
101 |
-
|
102 |
-
await interaction.response.
|
103 |
-
return
|
104 |
|
105 |
-
|
106 |
-
user_cash[user_id] = user_cash.get(user_id, 0) + sell_value
|
107 |
-
await interaction.response.send_message(f"You sold the pet for ${sell_value}. Your new balance is ${user_cash[user_id]}.", ephemeral=True)
|
108 |
-
for item in view.children:
|
109 |
-
if item.custom_id == "sell_pet":
|
110 |
-
view.remove_item(item)
|
111 |
-
break
|
112 |
-
await interaction.message.edit(view=view)
|
113 |
|
114 |
-
|
115 |
-
view.add_item(sell_button)
|
116 |
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
luck_multipliers[user_id] = 10 # 100% luck
|
126 |
-
first_luck_claimed.add(user_id)
|
127 |
-
|
128 |
-
await interaction.response.send_message("You've claimed 100% luck forever!", ephemeral=True)
|
129 |
-
|
130 |
-
for item in view.children:
|
131 |
-
if item.custom_id == "first_luck":
|
132 |
-
view.remove_item(item)
|
133 |
-
break
|
134 |
-
await interaction.message.edit(view=view)
|
135 |
-
|
136 |
-
first_luck_button.callback = first_luck_callback
|
137 |
-
view.add_item(first_luck_button)
|
138 |
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
|
143 |
-
|
144 |
-
|
145 |
-
await interaction.response.send_message("You cannot use this button.", ephemeral=True)
|
146 |
-
return
|
147 |
-
|
148 |
-
if user_id in used_luck_opportunities and len(used_luck_opportunities[user_id]) >= 4:
|
149 |
-
await interaction.response.send_message("You have already used all your luck opportunities.", ephemeral=True)
|
150 |
-
return
|
151 |
-
|
152 |
-
current_luck = luck_multipliers.get(user_id, 1)
|
153 |
-
new_luck = min(current_luck + 1, 10)
|
154 |
-
luck_multipliers[user_id] = new_luck
|
155 |
-
luck_expiration[user_id] = time.time() + 1800
|
156 |
-
|
157 |
-
if user_id not in used_luck_opportunities:
|
158 |
-
used_luck_opportunities[user_id] = set()
|
159 |
-
used_luck_opportunities[user_id].add(luck_opportunities[user_id])
|
160 |
-
|
161 |
-
luck_percentage = (new_luck - 1) * 100
|
162 |
-
await interaction.response.send_message(f"Your luck has been increased to {luck_percentage}% for 30 minutes!", ephemeral=True)
|
163 |
-
|
164 |
-
for item in view.children:
|
165 |
-
if item.custom_id == interaction.custom_id:
|
166 |
-
view.remove_item(item)
|
167 |
-
break
|
168 |
-
await interaction.message.edit(view=view)
|
169 |
-
|
170 |
-
# Schedule the next luck opportunity
|
171 |
-
asyncio.create_task(schedule_next_luck_opportunity(interaction, user_id))
|
172 |
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
auto_roll_button = discord.ui.Button(
|
177 |
-
style=discord.ButtonStyle.primary if user_id not in auto_roll_users else discord.ButtonStyle.danger,
|
178 |
-
label="Auto Roll" if user_id not in auto_roll_users else "Stop Auto Roll",
|
179 |
-
custom_id="auto_roll"
|
180 |
-
)
|
181 |
-
|
182 |
-
async def auto_roll_callback(interaction: discord.Interaction):
|
183 |
-
if interaction.user.id != user_id:
|
184 |
-
await interaction.response.send_message("You cannot use this button.", ephemeral=True)
|
185 |
-
return
|
186 |
-
|
187 |
-
if user_id in auto_roll_users:
|
188 |
-
auto_roll_users.remove(user_id)
|
189 |
-
auto_roll_button.style = discord.ButtonStyle.primary
|
190 |
-
auto_roll_button.label = "Auto Roll"
|
191 |
-
await interaction.response.send_message("Auto roll stopped.", ephemeral=True)
|
192 |
else:
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
|
|
|
|
|
|
|
|
200 |
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
|
|
205 |
|
206 |
-
async def
|
207 |
-
await asyncio.sleep(1800) # Wait for 30 minutes
|
208 |
-
luck_opportunities[user_id] = luck_opportunities.get(user_id, 0) + 1
|
209 |
-
increase_luck_button = discord.ui.Button(style=discord.ButtonStyle.success, label="Increase Luck", custom_id=f"increase_luck_{luck_opportunities[user_id]}")
|
210 |
-
|
211 |
-
async def increase_luck_callback(interaction: discord.Interaction):
|
212 |
if interaction.user.id != user_id:
|
213 |
-
await interaction.response.send_message("You cannot
|
214 |
-
return
|
215 |
-
|
216 |
-
if user_id in used_luck_opportunities and len(used_luck_opportunities[user_id]) >= 4:
|
217 |
-
await interaction.response.send_message("You have already used all your luck opportunities.", ephemeral=True)
|
218 |
return
|
219 |
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
if user_id not in used_luck_opportunities:
|
226 |
-
used_luck_opportunities[user_id] = set()
|
227 |
-
used_luck_opportunities[user_id].add(luck_opportunities[user_id])
|
228 |
-
|
229 |
-
luck_percentage = (new_luck - 1) * 100
|
230 |
-
await interaction.response.send_message(f"Your luck has been increased to {luck_percentage}% for 30 minutes!", ephemeral=True)
|
231 |
-
|
232 |
-
view = interaction.message.components[0]
|
233 |
-
for item in view.children:
|
234 |
-
if item.custom_id == interaction.custom_id:
|
235 |
-
view.remove_item(item)
|
236 |
-
break
|
237 |
-
await interaction.message.edit(view=view)
|
238 |
|
239 |
-
|
240 |
-
asyncio.create_task(schedule_next_luck_opportunity(interaction, user_id))
|
241 |
-
|
242 |
-
increase_luck_button.callback = increase_luck_callback
|
243 |
-
|
244 |
-
view = interaction.message.components[0]
|
245 |
-
view.add_item(increase_luck_button)
|
246 |
-
await interaction.message.edit(view=view)
|
247 |
|
248 |
-
|
249 |
-
user_id = interaction.user.id
|
250 |
-
while user_id in auto_roll_users:
|
251 |
-
result = await perform_roll(interaction)
|
252 |
-
if result:
|
253 |
-
await interaction.followup.send(embed=result[0], view=result[1])
|
254 |
-
else:
|
255 |
-
await interaction.followup.send("An error occurred.")
|
256 |
-
await asyncio.sleep(5) # Wait for 5 seconds between rolls
|
257 |
-
|
258 |
-
@app_commands.command(name="petroll", description="Roll for a random pet")
|
259 |
-
async def petroll(interaction: discord.Interaction):
|
260 |
-
await interaction.response.defer()
|
261 |
-
result = await perform_roll(interaction)
|
262 |
-
if result:
|
263 |
-
await interaction.followup.send(embed=result[0], view=result[1])
|
264 |
-
else:
|
265 |
-
await interaction.followup.send("errer")
|
266 |
|
267 |
-
@app_commands.command(name="
|
268 |
-
async def
|
269 |
user_id = interaction.user.id
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
await roll_dice(interaction, bet)
|
276 |
-
|
277 |
-
async def roll_dice(interaction: discord.Interaction, bet: int):
|
278 |
-
user_id = interaction.user.id
|
279 |
-
balance = user_cash.get(user_id, 0)
|
280 |
-
|
281 |
-
if bet <= 0:
|
282 |
-
await interaction.response.send_message("Bet Higher than 0 Idiot.")
|
283 |
-
return
|
284 |
-
|
285 |
-
if bet > balance:
|
286 |
-
await interaction.response.send_message(f"You don't have enough cash. Your current balance is ${balance:.2f}")
|
287 |
-
return
|
288 |
-
|
289 |
-
embed = discord.Embed(title="Dice Roll", description=f"{interaction.user.name} is betting ${bet:.2f}", color=0x787878)
|
290 |
-
embed.add_field(name="Current Balance", value=f"${balance:.2f}", inline=False)
|
291 |
-
|
292 |
-
roll_button = discord.ui.Button(style=discord.ButtonStyle.primary, label="Roll the Dice", custom_id="roll_dice")
|
293 |
-
|
294 |
-
async def roll_dice_callback(interaction: discord.Interaction):
|
295 |
-
nonlocal balance
|
296 |
-
result = random.choice(["win", "lose"])
|
297 |
-
|
298 |
-
if result == "win":
|
299 |
-
winnings = bet
|
300 |
-
balance += winnings
|
301 |
-
result_text = f"You won ${winnings:.2f}!"
|
302 |
-
else:
|
303 |
-
balance -= bet
|
304 |
-
result_text = f"You lost ${bet:.2f}."
|
305 |
-
|
306 |
-
user_cash[user_id] = balance
|
307 |
-
|
308 |
-
embed.clear_fields()
|
309 |
-
embed.add_field(name="Result", value=result_text, inline=False)
|
310 |
-
embed.add_field(name="New Balance", value=f"${balance:.2f}", inline=False)
|
311 |
-
|
312 |
-
roll_again_button = discord.ui.Button(style=discord.ButtonStyle.primary, label="Roll Again", custom_id="roll_again")
|
313 |
-
|
314 |
-
async def roll_again_callback(interaction: discord.Interaction):
|
315 |
-
if interaction.user.id == user_id:
|
316 |
-
await roll_dice(interaction, bet)
|
317 |
-
else:
|
318 |
-
await interaction.response.send_message("you cant roll this", ephemeral=True)
|
319 |
-
|
320 |
-
roll_again_button.callback = roll_again_callback
|
321 |
-
|
322 |
-
new_view = discord.ui.View()
|
323 |
-
new_view.add_item(roll_again_button)
|
324 |
-
|
325 |
-
await interaction.response.edit_
|
|
|
1 |
import discord
|
2 |
from discord import app_commands
|
3 |
import aiohttp
|
|
|
|
|
4 |
import asyncio
|
5 |
+
from datetime import datetime, timezone
|
6 |
from cash import user_cash
|
7 |
|
8 |
+
user_bets = {}
|
9 |
+
|
10 |
+
async def fetch_nhl_scores():
|
11 |
+
async with aiohttp.ClientSession() as session:
|
12 |
+
async with session.get("https://nhl-score-api.herokuapp.com/api/scores/latest") as response:
|
13 |
+
return await response.json()
|
14 |
+
|
15 |
+
class GameSelect(discord.ui.Select):
|
16 |
+
def __init__(self, games):
|
17 |
+
options = [
|
18 |
+
discord.SelectOption(
|
19 |
+
label=f"{game['teams']['away']['teamName']} vs {game['teams']['home']['teamName']}",
|
20 |
+
value=f"{game['teams']['away']['abbreviation']}_{game['teams']['home']['abbreviation']}",
|
21 |
+
description=f"Start time: <t:{int(datetime.fromisoformat(game['startTime'].replace('Z', '+00:00')).timestamp())}:R>"
|
22 |
+
) for game in games
|
23 |
+
]
|
24 |
+
super().__init__(placeholder="Select a game", options=options)
|
25 |
+
|
26 |
+
class TeamSelect(discord.ui.Select):
|
27 |
+
def __init__(self, away_team, home_team):
|
28 |
+
options = [
|
29 |
+
discord.SelectOption(label=away_team['teamName'], value=away_team['abbreviation']),
|
30 |
+
discord.SelectOption(label=home_team['teamName'], value=home_team['abbreviation'])
|
31 |
+
]
|
32 |
+
super().__init__(placeholder="Select a team to bet on", options=options)
|
33 |
+
|
34 |
+
class BetModal(discord.ui.Modal, title="Place Your Bet"):
|
35 |
+
bet_amount = discord.ui.TextInput(label="Bet Amount", placeholder="Enter bet amount")
|
36 |
+
|
37 |
+
def __init__(self, team, user_id, game_data):
|
38 |
+
super().__init__()
|
39 |
+
self.team = team
|
40 |
+
self.user_id = user_id
|
41 |
+
self.game_data = game_data
|
42 |
+
|
43 |
+
async def on_submit(self, interaction: discord.Interaction):
|
44 |
+
try:
|
45 |
+
bet_amount = int(self.bet_amount.value)
|
46 |
+
if bet_amount <= 0:
|
47 |
+
raise ValueError("Bet more than 0 dollars")
|
48 |
+
if bet_amount > user_cash.get(self.user_id, 0):
|
49 |
+
raise ValueError("You are too poor. Check your balance and try again")
|
50 |
+
|
51 |
+
user_cash[self.user_id] -= bet_amount
|
52 |
+
await interaction.response.send_message(f"Bet placed on {self.team} for ${bet_amount}")
|
53 |
+
|
54 |
+
user = await interaction.client.fetch_user(self.user_id)
|
55 |
+
embed = discord.Embed(title="Bet Placed", color=0x787878)
|
56 |
+
embed.add_field(name="Team", value=self.team, inline=False)
|
57 |
+
embed.add_field(name="Amount", value=f"${bet_amount}", inline=False)
|
58 |
+
embed.add_field(name="Game", value=f"{self.game_data['teams']['away']['teamName']} vs {self.game_data['teams']['home']['teamName']}", inline=False)
|
59 |
+
embed.add_field(name="Start Time", value=f"<t:{int(datetime.fromisoformat(self.game_data['startTime'].replace('Z', '+00:00')).timestamp())}:R>", inline=False)
|
60 |
+
await user.send(embed=embed)
|
61 |
+
|
62 |
+
if self.user_id not in user_bets:
|
63 |
+
user_bets[self.user_id] = []
|
64 |
+
user_bets[self.user_id].append({
|
65 |
+
"team": self.team,
|
66 |
+
"amount": bet_amount,
|
67 |
+
"game_data": self.game_data
|
68 |
+
})
|
69 |
+
|
70 |
+
asyncio.create_task(self.monitor_game(interaction, bet_amount))
|
71 |
+
except ValueError as e:
|
72 |
+
await interaction.response.send_message(str(e), ephemeral=True)
|
73 |
|
74 |
+
async def monitor_game(self, interaction, bet_amount):
|
75 |
+
game_start = datetime.fromisoformat(self.game_data['startTime'].replace('Z', '+00:00'))
|
76 |
+
await asyncio.sleep((game_start - datetime.now(timezone.utc)).total_seconds())
|
|
|
|
|
|
|
|
|
77 |
|
78 |
+
user = await interaction.client.fetch_user(self.user_id)
|
79 |
+
await user.send(f"Your team {self.team} has started playing!")
|
80 |
|
81 |
+
previous_scores = {self.game_data['teams']['away']['abbreviation']: 0, self.game_data['teams']['home']['abbreviation']: 0}
|
|
|
82 |
|
83 |
+
while True:
|
84 |
+
scores = await fetch_nhl_scores()
|
85 |
+
game = next((g for g in scores['games'] if g['teams']['away']['abbreviation'] == self.game_data['teams']['away']['abbreviation'] and
|
86 |
+
g['teams']['home']['abbreviation'] == self.game_data['teams']['home']['abbreviation']), None)
|
87 |
+
|
88 |
+
if game is None or game['status']['state'] == 'PREVIEW':
|
89 |
+
await asyncio.sleep(60)
|
90 |
+
continue
|
91 |
|
92 |
+
current_scores = game['scores']
|
93 |
+
|
94 |
+
for team in [self.game_data['teams']['away']['abbreviation'], self.game_data['teams']['home']['abbreviation']]:
|
95 |
+
if current_scores[team] > previous_scores[team]:
|
96 |
+
team_name = game['teams']['away']['teamName'] if team == game['teams']['away']['abbreviation'] else game['teams']['home']['teamName']
|
97 |
+
await user.send(f"{team_name} SCORED! Current score: {current_scores[self.game_data['teams']['away']['abbreviation']]} - {current_scores[self.game_data['teams']['home']['abbreviation']]}")
|
98 |
+
|
99 |
+
previous_scores = current_scores.copy()
|
100 |
+
|
101 |
+
if game['status']['state'] == 'FINAL':
|
102 |
+
winner = self.game_data['teams']['away']['abbreviation'] if current_scores[self.game_data['teams']['away']['abbreviation']] > current_scores[self.game_data['teams']['home']['abbreviation']] else self.game_data['teams']['home']['abbreviation']
|
103 |
+
if winner == self.team:
|
104 |
+
winnings = bet_amount * 2
|
105 |
+
user_cash[self.user_id] += winnings
|
106 |
+
await user.send(f"Congratulations! Your team won. You won ${winnings}!")
|
107 |
+
else:
|
108 |
+
await user.send(f"Sorry, your team lost. Better luck next time!")
|
109 |
+
|
110 |
+
user_bets[self.user_id] = [bet for bet in user_bets[self.user_id] if bet['game_data'] != self.game_data]
|
111 |
+
break
|
112 |
+
|
113 |
+
await asyncio.sleep(60) # Check for updates every minute
|
114 |
|
115 |
+
class SportBetView(discord.ui.View):
|
116 |
+
def __init__(self):
|
117 |
+
super().__init__()
|
118 |
|
119 |
+
@discord.ui.button(label="Bet Again", style=discord.ButtonStyle.primary)
|
120 |
+
async def bet_again(self, interaction: discord.Interaction, button: discord.ui.Button):
|
121 |
+
await show_game_selection(interaction)
|
122 |
|
123 |
+
@discord.ui.button(label="View Bets", style=discord.ButtonStyle.secondary)
|
124 |
+
async def view_bets(self, interaction: discord.Interaction, button: discord.ui.Button):
|
125 |
+
await show_current_bets(interaction)
|
126 |
|
127 |
+
async def show_game_selection(interaction: discord.Interaction):
|
128 |
+
scores = await fetch_nhl_scores()
|
129 |
+
upcoming_games = [game for game in scores['games'] if game['status']['state'] == 'PREVIEW']
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
|
131 |
+
if not upcoming_games:
|
132 |
+
await interaction.response.send_message("No games available for betting.")
|
133 |
+
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
134 |
|
135 |
+
view = discord.ui.View()
|
136 |
+
game_select = GameSelect(upcoming_games)
|
137 |
+
view.add_item(game_select)
|
|
|
|
|
|
|
|
|
|
|
|
|
138 |
|
139 |
+
await interaction.response.send_message("Select a game to bet on:", view=view)
|
140 |
|
141 |
+
async def game_callback(interaction: discord.Interaction):
|
142 |
+
selected_game = next(game for game in upcoming_games if f"{game['teams']['away']['abbreviation']}_{game['teams']['home']['abbreviation']}" == game_select.values[0])
|
143 |
+
|
144 |
+
team_view = discord.ui.View()
|
145 |
+
team_select = TeamSelect(selected_game['teams']['away'], selected_game['teams']['home'])
|
146 |
+
team_view.add_item(team_select)
|
147 |
|
148 |
+
await interaction.response.edit_message(content="Select a team to bet on:", view=team_view)
|
149 |
|
150 |
+
async def team_callback(interaction: discord.Interaction):
|
151 |
+
selected_team = team_select.values[0]
|
152 |
+
await interaction.response.send_modal(BetModal(selected_team, interaction.user.id, selected_game))
|
|
|
153 |
|
154 |
+
team_select.callback = team_callback
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
155 |
|
156 |
+
game_select.callback = game_callback
|
|
|
157 |
|
158 |
+
async def show_current_bets(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 |
+
scores = await fetch_nhl_scores()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
166 |
|
167 |
+
for i, bet in enumerate(user_bets[user_id]):
|
168 |
+
game = next((g for g in scores['games'] if g['teams']['away']['abbreviation'] == bet['game_data']['teams']['away']['abbreviation'] and
|
169 |
+
g['teams']['home']['abbreviation'] == bet['game_data']['teams']['home']['abbreviation']), None)
|
170 |
|
171 |
+
start_time = datetime.fromisoformat(bet['game_data']['startTime'].replace('Z', '+00:00'))
|
172 |
+
current_time = datetime.now(timezone.utc)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
173 |
|
174 |
+
if current_time < start_time:
|
175 |
+
status = f"Starts <t:{int(start_time.timestamp())}:R>"
|
176 |
+
score = "N/A"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
177 |
else:
|
178 |
+
status = game['status']['state'] if game else "Unknown"
|
179 |
+
score = f"{game['scores'][bet['game_data']['teams']['away']['abbreviation']]} - {game['scores'][bet['game_data']['teams']['home']['abbreviation']]}" if game and 'scores' in game else "Unknown"
|
180 |
+
|
181 |
+
embed.add_field(name=f"Bet {i+1}", value=(
|
182 |
+
f"Team: {bet['team']}\n"
|
183 |
+
f"Amount: ${bet['amount']}\n"
|
184 |
+
f"Game: {bet['game_data']['teams']['away']['teamName']} vs {bet['game_data']['teams']['home']['teamName']}\n"
|
185 |
+
f"Status: {status}\n"
|
186 |
+
f"Current Score: {score}\n"
|
187 |
+
f"Start Time: <t:{int(start_time.timestamp())}:F>"
|
188 |
+
), inline=False)
|
189 |
|
190 |
+
view = discord.ui.View()
|
191 |
+
cancel_select = discord.ui.Select(placeholder="Select a bet to cancel", options=[
|
192 |
+
discord.SelectOption(label=f"Bet {i+1}", value=str(i)) for i in range(len(user_bets[user_id]))
|
193 |
+
])
|
194 |
+
view.add_item(cancel_select)
|
195 |
|
196 |
+
async def cancel_callback(interaction: discord.Interaction):
|
|
|
|
|
|
|
|
|
|
|
197 |
if interaction.user.id != user_id:
|
198 |
+
await interaction.response.send_message("You cannot cancel other users' bets.", ephemeral=True)
|
|
|
|
|
|
|
|
|
199 |
return
|
200 |
|
201 |
+
bet_index = int(cancel_select.values[0])
|
202 |
+
cancelled_bet = user_bets[user_id].pop(bet_index)
|
203 |
+
user_cash[user_id] += cancelled_bet['amount']
|
204 |
+
await interaction.response.send_message(f"Bet cancelled. ${cancelled_bet['amount']} has been refunded")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
205 |
|
206 |
+
cancel_select.callback = cancel_callback
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
207 |
|
208 |
+
await interaction.response.send_message(embed=embed, view=view)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
209 |
|
210 |
+
@app_commands.command(name="sportbet", description="Bet on sports games")
|
211 |
+
async def sportbet(interaction: discord.Interaction):
|
212 |
user_id = interaction.user.id
|
213 |
+
if user_id in user_bets and user_bets[user_id]:
|
214 |
+
view = SportBetView()
|
215 |
+
await interaction.response.send_message("?", view=view)
|
216 |
+
else:
|
217 |
+
await show_game_selection(interaction)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|