coollsd commited on
Commit
82c48f2
·
verified ·
1 Parent(s): 22e2165

Update sportbet.py

Browse files
Files changed (1) hide show
  1. 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, teams):
31
- options = [discord.SelectOption(label=f"{team['teamName']} ({team['abbreviation']})", value=team['abbreviation']) for team in teams]
32
- super().__init__(placeholder="Select a team", 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")
@@ -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
- team_select = TeamSelect(sum([game['teams'].values() for game in upcoming_games], []))
97
- view.add_item(team_select)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98
 
99
- await interaction.response.send_message(embed=embed, view=view)
100
 
101
- async def team_callback(interaction: discord.Interaction):
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
- team_select.callback = team_callback
 
 
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)