Spaces:
Building
Building
Update sportbet.py
Browse files- sportbet.py +24 -3
sportbet.py
CHANGED
@@ -12,6 +12,13 @@ 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 GameSelect(discord.ui.Select):
|
16 |
def __init__(self, games):
|
17 |
options = [
|
@@ -111,12 +118,26 @@ class SportBetView(discord.ui.View):
|
|
111 |
|
112 |
@discord.ui.button(label="Bet Again", style=discord.ButtonStyle.primary)
|
113 |
async def bet_again(self, interaction: discord.Interaction, button: discord.ui.Button):
|
114 |
-
await
|
115 |
|
116 |
@discord.ui.button(label="View Bets", style=discord.ButtonStyle.secondary)
|
117 |
async def view_bets(self, interaction: discord.Interaction, button: discord.ui.Button):
|
118 |
await show_current_bets(interaction)
|
119 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
120 |
async def show_game_selection(interaction: discord.Interaction):
|
121 |
scores = await fetch_nhl_scores()
|
122 |
upcoming_games = [game for game in scores['games'] if game['status']['state'] == 'PREVIEW']
|
@@ -129,7 +150,7 @@ async def show_game_selection(interaction: discord.Interaction):
|
|
129 |
game_select = GameSelect(upcoming_games)
|
130 |
view.add_item(game_select)
|
131 |
|
132 |
-
await interaction.response.
|
133 |
|
134 |
async def game_callback(interaction: discord.Interaction):
|
135 |
selected_game = next(game for game in upcoming_games if f"{game['teams']['away']['abbreviation']}_{game['teams']['home']['abbreviation']}" == game_select.values[0])
|
@@ -203,4 +224,4 @@ async def sportbet(interaction: discord.Interaction):
|
|
203 |
view = SportBetView()
|
204 |
await interaction.response.send_message("?", view=view)
|
205 |
else:
|
206 |
-
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 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 = [
|
|
|
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_sport_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_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 |
game_select = GameSelect(upcoming_games)
|
151 |
view.add_item(game_select)
|
152 |
|
153 |
+
await interaction.response.edit_message(content="Select a game to bet on:", view=view)
|
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 |
view = SportBetView()
|
225 |
await interaction.response.send_message("?", view=view)
|
226 |
else:
|
227 |
+
await show_sport_selection(interaction)
|