coollsd commited on
Commit
7917f65
·
verified ·
1 Parent(s): c9bee21

Update sportbet.py

Browse files
Files changed (1) hide show
  1. 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
- luck_multipliers = {}
11
- luck_expiration = {}
12
- luck_opportunities = {}
13
- used_luck_opportunities = {}
14
- first_luck_claimed = set()
15
- auto_roll_users = set()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
- async def perform_roll(interaction: discord.Interaction):
18
- async def fetch_data(url):
19
- async with aiohttp.ClientSession() as session:
20
- async with session.get(url) as response:
21
- if response.status == 200:
22
- return await response.json()
23
- return None
24
 
25
- rap_data = await fetch_data("https://rapapi.deno.dev/")
26
- collection_data = await fetch_data("https://petsapi.deno.dev/")
27
 
28
- if not rap_data or not collection_data:
29
- return None
30
 
31
- pets = [pet for pet in collection_data['data'] if pet['configName'] in [p['configData']['id'] for p in rap_data['data']]]
32
-
33
- if not pets:
34
- return None
 
 
 
 
35
 
36
- user_id = interaction.user.id
37
- luck_multiplier = luck_multipliers.get(user_id, 1)
38
-
39
- sorted_pets = sorted(pets, key=lambda x: x['configData']['difficulty'])
40
-
41
- max_index = len(sorted_pets) - 1
42
- index = int(max_index * (luck_multiplier - 1) / 9)
43
-
44
- rolled_pet = random.choice(sorted_pets[:index+1])
 
 
 
 
 
 
 
 
 
 
 
 
 
45
 
46
- pet_rap = next((pet for pet in rap_data['data'] if pet['configData']['id'] == rolled_pet['configName']), None)
 
 
47
 
48
- if not pet_rap:
49
- return None
 
50
 
51
- rap_value = pet_rap['value']
52
- thumbnail_id = rolled_pet['configData']['thumbnail'].split('://')[1]
53
- thumbnail_url = f"https://api.rbxgleaks1.workers.dev/asset/{thumbnail_id}"
54
 
55
- def format_difficulty(difficulty):
56
- if difficulty >= 1_000_000_000:
57
- return f"{difficulty / 1_000_000_000:.1f}B ({difficulty:,})"
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
- embed = discord.Embed(title=f"{interaction.user.name} rolled: {rolled_pet['configData']['name']}", color=0x787878)
66
- embed.add_field(name="Value", value=f"{rap_value:,} diamonds", inline=True)
67
- embed.add_field(name="Difficulty", value=format_difficulty(rolled_pet['configData']['difficulty']), inline=True)
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
- roll_again_button = discord.ui.Button(style=discord.ButtonStyle.primary, label="Roll Again", custom_id="roll_again")
84
-
85
- async def roll_again_callback(interaction: discord.Interaction):
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
- roll_again_button.callback = roll_again_callback
94
 
95
- view = discord.ui.View()
96
- view.add_item(roll_again_button)
 
 
 
 
97
 
98
- sell_button = discord.ui.Button(style=discord.ButtonStyle.success, label=f"Sell Pet for ${rap_value}", custom_id="sell_pet")
99
 
100
- async def sell_pet_callback(interaction: discord.Interaction):
101
- if interaction.user.id != user_id:
102
- await interaction.response.send_message("You cannot sell this pet.", ephemeral=True)
103
- return
104
 
105
- sell_value = rap_value
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
- sell_button.callback = sell_pet_callback
115
- view.add_item(sell_button)
116
 
117
- if user_id not in first_luck_claimed:
118
- first_luck_button = discord.ui.Button(style=discord.ButtonStyle.success, label="Claim 100% Luck Forever", custom_id="first_luck")
119
-
120
- async def first_luck_callback(interaction: discord.Interaction):
121
- if interaction.user.id != user_id:
122
- await interaction.response.send_message("You cannot use this button.", ephemeral=True)
123
- return
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
- elif random.random() < 0.6 and luck_opportunities.get(user_id, 0) < 4:
140
- luck_opportunities[user_id] = luck_opportunities.get(user_id, 0) + 1
141
- increase_luck_button = discord.ui.Button(style=discord.ButtonStyle.success, label="Increase Luck", custom_id=f"increase_luck_{luck_opportunities[user_id]}")
142
 
143
- async def increase_luck_callback(interaction: discord.Interaction):
144
- if interaction.user.id != user_id:
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
- increase_luck_button.callback = increase_luck_callback
174
- view.add_item(increase_luck_button)
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
- auto_roll_users.add(user_id)
194
- auto_roll_button.style = discord.ButtonStyle.danger
195
- auto_roll_button.label = "Stop Auto Roll"
196
- await interaction.response.send_message("Auto roll started.", ephemeral=True)
197
- asyncio.create_task(auto_roll(interaction))
198
-
199
- await interaction.message.edit(view=view)
 
 
 
 
200
 
201
- auto_roll_button.callback = auto_roll_callback
202
- view.add_item(auto_roll_button)
203
-
204
- return embed, view
 
205
 
206
- async def schedule_next_luck_opportunity(interaction: discord.Interaction, user_id: int):
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 use this button.", ephemeral=True)
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
- current_luck = luck_multipliers.get(user_id, 1)
221
- new_luck = min(current_luck + 1, 10)
222
- luck_multipliers[user_id] = new_luck
223
- luck_expiration[user_id] = time.time() + 1800
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
- # Schedule the next luck opportunity
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
- async def auto_roll(interaction: discord.Interaction):
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="balance", description="Check your current balance")
268
- async def balance(interaction: discord.Interaction):
269
  user_id = interaction.user.id
270
- current_balance = user_cash.get(user_id, 0)
271
- await interaction.response.send_message(f"Your current balance is ${current_balance}.", ephemeral=True)
272
-
273
- @app_commands.command(name="dice", description="Roll the dice and bet")
274
- async def dice(interaction: discord.Interaction, bet: int):
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)