coollsd commited on
Commit
da55a4c
·
verified ·
1 Parent(s): 3a4e36f

Update sportbet.py

Browse files
Files changed (1) hide show
  1. sportbet.py +25 -3
sportbet.py CHANGED
@@ -5,6 +5,7 @@ import asyncio
5
  from datetime import datetime, timezone
6
 
7
  user_cash = {}
 
8
 
9
  def load_database():
10
  global user_cash
@@ -65,6 +66,24 @@ class BetModal(discord.ui.Modal, title="Place Your Bet"):
65
  user_cash[self.user_id] -= bet_amount
66
  await interaction.response.send_message(f"Bet placed on {self.team} for ${bet_amount}")
67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
  asyncio.create_task(self.monitor_game(interaction, bet_amount))
69
  except ValueError as e:
70
  await interaction.response.send_message(str(e), ephemeral=True)
@@ -86,11 +105,14 @@ class BetModal(discord.ui.Modal, title="Place Your Bet"):
86
  await interaction.user.send(f"WOO YOUR TEAM WON you won ${winnings}!")
87
  else:
88
  await interaction.user.send(f"Sorry, your team lost booo!")
 
 
 
89
  break
90
 
91
  await asyncio.sleep(300) # Check every 5 minutes
92
 
93
- @app_commands.command(name="sportbet", description="Bet on NHL games")
94
  async def sportbet(interaction: discord.Interaction):
95
  scores = await fetch_nhl_scores()
96
  upcoming_games = [game for game in scores['games'] if game['status']['state'] == 'PREVIEW']
@@ -103,7 +125,7 @@ async def sportbet(interaction: discord.Interaction):
103
  game_select = GameSelect(upcoming_games)
104
  view.add_item(game_select)
105
 
106
- await interaction.response.send_message("select a game:", view=view)
107
 
108
  async def game_callback(interaction: discord.Interaction):
109
  selected_game = next(game for game in upcoming_games if f"{game['teams']['away']['abbreviation']}_{game['teams']['home']['abbreviation']}" == game_select.values[0])
@@ -112,7 +134,7 @@ async def sportbet(interaction: discord.Interaction):
112
  team_select = TeamSelect(selected_game['teams']['away'], selected_game['teams']['home'])
113
  team_view.add_item(team_select)
114
 
115
- await interaction.response.edit_message(content="Select a team to bet on:", view=team_view)
116
 
117
  async def team_callback(interaction: discord.Interaction):
118
  selected_team = team_select.values[0]
 
5
  from datetime import datetime, timezone
6
 
7
  user_cash = {}
8
+ user_bets = {}
9
 
10
  def load_database():
11
  global user_cash
 
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
+ # Send DM to user
70
+ user = await interaction.client.fetch_user(self.user_id)
71
+ embed = discord.Embed(title="Bet Placed", color=0x787878)
72
+ embed.add_field(name="Team", value=self.team, inline=False)
73
+ embed.add_field(name="Amount", value=f"${bet_amount}", inline=False)
74
+ embed.add_field(name="Game", value=f"{self.game_data['teams']['away']['teamName']} vs {self.game_data['teams']['home']['teamName']}", inline=False)
75
+ embed.add_field(name="Start Time", value=self.game_data['startTime'], inline=False)
76
+ await user.send(embed=embed)
77
+
78
+ # Add bet to user_bets
79
+ if self.user_id not in user_bets:
80
+ user_bets[self.user_id] = []
81
+ user_bets[self.user_id].append({
82
+ "team": self.team,
83
+ "amount": bet_amount,
84
+ "game_data": self.game_data
85
+ })
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)
 
105
  await interaction.user.send(f"WOO YOUR TEAM WON you won ${winnings}!")
106
  else:
107
  await interaction.user.send(f"Sorry, your team lost booo!")
108
+
109
+ # Remove bet from user_bets
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(300) # Check every 5 minutes
114
 
115
+ @app_commands.command(name="sportbet", description="bet on sports game")
116
  async def sportbet(interaction: discord.Interaction):
117
  scores = await fetch_nhl_scores()
118
  upcoming_games = [game for game in scores['games'] if game['status']['state'] == 'PREVIEW']
 
125
  game_select = GameSelect(upcoming_games)
126
  view.add_item(game_select)
127
 
128
+ await interaction.response.send_message("game to bet on:", view=view)
129
 
130
  async def game_callback(interaction: discord.Interaction):
131
  selected_game = next(game for game in upcoming_games if f"{game['teams']['away']['abbreviation']}_{game['teams']['home']['abbreviation']}" == game_select.values[0])
 
134
  team_select = TeamSelect(selected_game['teams']['away'], selected_game['teams']['home'])
135
  team_view.add_item(team_select)
136
 
137
+ await interaction.response.edit_message(content="team to bet on:", view=team_view)
138
 
139
  async def team_callback(interaction: discord.Interaction):
140
  selected_team = team_select.values[0]