Spaces:
Building
Building
Update sportbet.py
Browse files- sportbet.py +38 -18
sportbet.py
CHANGED
@@ -26,10 +26,24 @@ async def fetch_nhl_scores():
|
|
26 |
async with session.get("https://nhl-score-api.herokuapp.com/api/scores/latest") as response:
|
27 |
return await response.json()
|
28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
class TeamSelect(discord.ui.Select):
|
30 |
-
def __init__(self,
|
31 |
-
options = [
|
32 |
-
|
|
|
|
|
|
|
33 |
|
34 |
class BetModal(discord.ui.Modal, title="Place Your Bet"):
|
35 |
bet_amount = discord.ui.TextInput(label="Bet Amount", placeholder="Enter bet amount")
|
@@ -85,22 +99,28 @@ async def sportbet(interaction: discord.Interaction):
|
|
85 |
await interaction.response.send_message("No games for betting.")
|
86 |
return
|
87 |
|
88 |
-
embed = discord.Embed(title="Upcoming NHL Games", color=0x00ff00)
|
89 |
-
for game in upcoming_games:
|
90 |
-
away_team = game['teams']['away']
|
91 |
-
home_team = game['teams']['home']
|
92 |
-
embed.add_field(name=f"{away_team['teamName']} vs {home_team['teamName']}",
|
93 |
-
value=f"Start time: {game['startTime']}", inline=False)
|
94 |
-
|
95 |
view = discord.ui.View()
|
96 |
-
|
97 |
-
view.add_item(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
|
99 |
-
|
100 |
|
101 |
-
|
102 |
-
selected_team = team_select.values[0]
|
103 |
-
game = next(game for game in upcoming_games if selected_team in [game['teams']['away']['abbreviation'], game['teams']['home']['abbreviation']])
|
104 |
-
await interaction.response.send_modal(BetModal(selected_team, interaction.user.id, game))
|
105 |
|
106 |
-
|
|
|
|
26 |
async with session.get("https://nhl-score-api.herokuapp.com/api/scores/latest") as response:
|
27 |
return await response.json()
|
28 |
|
29 |
+
class GameSelect(discord.ui.Select):
|
30 |
+
def __init__(self, games):
|
31 |
+
options = [
|
32 |
+
discord.SelectOption(
|
33 |
+
label=f"{game['teams']['away']['teamName']} vs {game['teams']['home']['teamName']}",
|
34 |
+
value=f"{game['teams']['away']['abbreviation']}_{game['teams']['home']['abbreviation']}",
|
35 |
+
description=f"Start time: {game['startTime']}"
|
36 |
+
) for game in games
|
37 |
+
]
|
38 |
+
super().__init__(placeholder="Select a game", options=options)
|
39 |
+
|
40 |
class TeamSelect(discord.ui.Select):
|
41 |
+
def __init__(self, away_team, home_team):
|
42 |
+
options = [
|
43 |
+
discord.SelectOption(label=away_team['teamName'], value=away_team['abbreviation']),
|
44 |
+
discord.SelectOption(label=home_team['teamName'], value=home_team['abbreviation'])
|
45 |
+
]
|
46 |
+
super().__init__(placeholder="Select a team to bet on", options=options)
|
47 |
|
48 |
class BetModal(discord.ui.Modal, title="Place Your Bet"):
|
49 |
bet_amount = discord.ui.TextInput(label="Bet Amount", placeholder="Enter bet amount")
|
|
|
99 |
await interaction.response.send_message("No games for betting.")
|
100 |
return
|
101 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
view = discord.ui.View()
|
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])
|
110 |
+
|
111 |
+
team_view = discord.ui.View()
|
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]
|
119 |
+
await interaction.response.send_modal(BetModal(selected_team, interaction.user.id, selected_game))
|
120 |
|
121 |
+
team_select.callback = team_callback
|
122 |
|
123 |
+
game_select.callback = game_callback
|
|
|
|
|
|
|
124 |
|
125 |
+
# Add this command to your command tree
|
126 |
+
tree.add_command(sportbet)
|