Spaces:
Building
Building
Update sportbet.py
Browse files- sportbet.py +6 -24
sportbet.py
CHANGED
@@ -12,13 +12,6 @@ async def fetch_nhl_scores():
|
|
12 |
async with session.get("https://nhl-score-api.herokuapp.com/api/scores/latest") as response:
|
13 |
return await response.json()
|
14 |
|
15 |
-
class SportSelect(discord.ui.Select):
|
16 |
-
def __init__(self):
|
17 |
-
options = [
|
18 |
-
discord.SelectOption(label="NHL", value="nhl", description="National Hockey League")
|
19 |
-
]
|
20 |
-
super().__init__(placeholder="Select a sport", options=options)
|
21 |
-
|
22 |
class GameSelect(discord.ui.Select):
|
23 |
def __init__(self, games):
|
24 |
options = [
|
@@ -82,6 +75,9 @@ class BetModal(discord.ui.Modal, title="Place Your Bet"):
|
|
82 |
game_start = datetime.fromisoformat(self.game_data['startTime'].replace('Z', '+00:00'))
|
83 |
await asyncio.sleep((game_start - datetime.now(timezone.utc)).total_seconds())
|
84 |
|
|
|
|
|
|
|
85 |
previous_scores = {'away': 0, 'home': 0}
|
86 |
|
87 |
while True:
|
@@ -118,26 +114,12 @@ class SportBetView(discord.ui.View):
|
|
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
|
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_sport_selection(interaction: discord.Interaction):
|
128 |
-
view = discord.ui.View()
|
129 |
-
sport_select = SportSelect()
|
130 |
-
view.add_item(sport_select)
|
131 |
-
|
132 |
-
await interaction.response.send_message("Select a sport to bet on:", view=view)
|
133 |
-
|
134 |
-
async def sport_callback(interaction: discord.Interaction):
|
135 |
-
selected_sport = sport_select.values[0]
|
136 |
-
if selected_sport == "nhl":
|
137 |
-
await show_game_selection(interaction)
|
138 |
-
|
139 |
-
sport_select.callback = sport_callback
|
140 |
-
|
141 |
async def show_game_selection(interaction: discord.Interaction):
|
142 |
scores = await fetch_nhl_scores()
|
143 |
upcoming_games = [game for game in scores['games'] if game['status']['state'] == 'PREVIEW']
|
@@ -150,7 +132,7 @@ async def show_game_selection(interaction: discord.Interaction):
|
|
150 |
game_select = GameSelect(upcoming_games)
|
151 |
view.add_item(game_select)
|
152 |
|
153 |
-
await interaction.response.
|
154 |
|
155 |
async def game_callback(interaction: discord.Interaction):
|
156 |
selected_game = next(game for game in upcoming_games if f"{game['teams']['away']['abbreviation']}_{game['teams']['home']['abbreviation']}" == game_select.values[0])
|
@@ -224,4 +206,4 @@ async def sportbet(interaction: discord.Interaction):
|
|
224 |
view = SportBetView()
|
225 |
await interaction.response.send_message("?", view=view)
|
226 |
else:
|
227 |
-
await
|
|
|
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 = [
|
|
|
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 |
+
# Notify user that the game has started
|
79 |
+
await interaction.user.send(f"GAME STARTED! Your team {self.team} is now playing!")
|
80 |
+
|
81 |
previous_scores = {'away': 0, 'home': 0}
|
82 |
|
83 |
while True:
|
|
|
114 |
|
115 |
@discord.ui.button(label="Bet Again", style=discord.ButtonStyle.primary)
|
116 |
async def bet_again(self, interaction: discord.Interaction, button: discord.ui.Button):
|
117 |
+
await show_game_selection(interaction)
|
118 |
|
119 |
@discord.ui.button(label="View Bets", style=discord.ButtonStyle.secondary)
|
120 |
async def view_bets(self, interaction: discord.Interaction, button: discord.ui.Button):
|
121 |
await show_current_bets(interaction)
|
122 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
async def show_game_selection(interaction: discord.Interaction):
|
124 |
scores = await fetch_nhl_scores()
|
125 |
upcoming_games = [game for game in scores['games'] if game['status']['state'] == 'PREVIEW']
|
|
|
132 |
game_select = GameSelect(upcoming_games)
|
133 |
view.add_item(game_select)
|
134 |
|
135 |
+
await interaction.response.send_message("Select a game to bet on:", view=view)
|
136 |
|
137 |
async def game_callback(interaction: discord.Interaction):
|
138 |
selected_game = next(game for game in upcoming_games if f"{game['teams']['away']['abbreviation']}_{game['teams']['home']['abbreviation']}" == game_select.values[0])
|
|
|
206 |
view = SportBetView()
|
207 |
await interaction.response.send_message("?", view=view)
|
208 |
else:
|
209 |
+
await show_game_selection(interaction)
|