Spaces:
Building
Building
Update sportbet.py
Browse files- sportbet.py +14 -3
sportbet.py
CHANGED
@@ -75,11 +75,22 @@ class BetModal(discord.ui.Modal, title="Place Your Bet"):
|
|
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 |
while True:
|
79 |
scores = await fetch_nhl_scores()
|
80 |
game = next((g for g in scores['games'] if g['teams']['away']['abbreviation'] == self.game_data['teams']['away']['abbreviation'] and
|
81 |
g['teams']['home']['abbreviation'] == self.game_data['teams']['home']['abbreviation']), None)
|
82 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
if game['status']['state'] == 'FINAL':
|
84 |
winner = 'away' if game['scores']['away'] > game['scores']['home'] else 'home'
|
85 |
if game['teams'][winner]['abbreviation'] == self.team:
|
@@ -87,12 +98,12 @@ class BetModal(discord.ui.Modal, title="Place Your Bet"):
|
|
87 |
user_cash[self.user_id] += winnings
|
88 |
await interaction.user.send(f"Congratulations! Your team won. You won ${winnings}!")
|
89 |
else:
|
90 |
-
await interaction.user.send(f"Sorry, your team lost
|
91 |
|
92 |
user_bets[self.user_id] = [bet for bet in user_bets[self.user_id] if bet['game_data'] != self.game_data]
|
93 |
break
|
94 |
|
95 |
-
await asyncio.sleep(
|
96 |
|
97 |
class SportBetView(discord.ui.View):
|
98 |
def __init__(self):
|
@@ -111,7 +122,7 @@ async def show_game_selection(interaction: discord.Interaction):
|
|
111 |
upcoming_games = [game for game in scores['games'] if game['status']['state'] == 'PREVIEW']
|
112 |
|
113 |
if not upcoming_games:
|
114 |
-
await interaction.response.send_message("No
|
115 |
return
|
116 |
|
117 |
view = discord.ui.View()
|
|
|
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 |
+
previous_scores = {'away': 0, 'home': 0}
|
79 |
+
|
80 |
while True:
|
81 |
scores = await fetch_nhl_scores()
|
82 |
game = next((g for g in scores['games'] if g['teams']['away']['abbreviation'] == self.game_data['teams']['away']['abbreviation'] and
|
83 |
g['teams']['home']['abbreviation'] == self.game_data['teams']['home']['abbreviation']), None)
|
84 |
|
85 |
+
current_scores = game['scores']
|
86 |
+
|
87 |
+
for team in ['away', 'home']:
|
88 |
+
if current_scores[team] > previous_scores[team]:
|
89 |
+
team_name = game['teams'][team]['teamName']
|
90 |
+
await interaction.user.send(f"{team_name} SCORED! Current score: {current_scores['away']} - {current_scores['home']}")
|
91 |
+
|
92 |
+
previous_scores = current_scores.copy()
|
93 |
+
|
94 |
if game['status']['state'] == 'FINAL':
|
95 |
winner = 'away' if game['scores']['away'] > game['scores']['home'] else 'home'
|
96 |
if game['teams'][winner]['abbreviation'] == self.team:
|
|
|
98 |
user_cash[self.user_id] += winnings
|
99 |
await interaction.user.send(f"Congratulations! Your team won. You won ${winnings}!")
|
100 |
else:
|
101 |
+
await interaction.user.send(f"Sorry, your team lost CRY")
|
102 |
|
103 |
user_bets[self.user_id] = [bet for bet in user_bets[self.user_id] if bet['game_data'] != self.game_data]
|
104 |
break
|
105 |
|
106 |
+
await asyncio.sleep(60) # Check for updates every minute
|
107 |
|
108 |
class SportBetView(discord.ui.View):
|
109 |
def __init__(self):
|
|
|
122 |
upcoming_games = [game for game in scores['games'] if game['status']['state'] == 'PREVIEW']
|
123 |
|
124 |
if not upcoming_games:
|
125 |
+
await interaction.response.send_message("No games available for betting.")
|
126 |
return
|
127 |
|
128 |
view = discord.ui.View()
|