Spaces:
Building
Building
Update sportbet.py
Browse files- sportbet.py +17 -14
sportbet.py
CHANGED
@@ -154,7 +154,11 @@ class BetModal(discord.ui.Modal, title="Place Your Bet"):
|
|
154 |
"league": self.league,
|
155 |
"team": self.team,
|
156 |
"amount": bet_amount,
|
157 |
-
"game_data": self.game_data
|
|
|
|
|
|
|
|
|
158 |
})
|
159 |
|
160 |
asyncio.create_task(self.monitor_game(interaction))
|
@@ -164,21 +168,19 @@ class BetModal(discord.ui.Modal, title="Place Your Bet"):
|
|
164 |
|
165 |
async def monitor_game(self, interaction):
|
166 |
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
self.game_data['lowerTeam']['name']: None,
|
171 |
-
self.game_data['upperTeam']['name']: None,
|
172 |
}
|
173 |
|
174 |
while True:
|
175 |
-
scores_response
|
176 |
event_list_key='events' if 'events' in scores_response.get('sectionList', [{}])[0] else 'games'
|
177 |
current_game=None
|
178 |
|
179 |
for section in scores_response.get('sectionList', []):
|
180 |
for event in section.get(event_list_key , []):
|
181 |
-
if event['id']
|
182 |
current_game=event
|
183 |
break
|
184 |
|
@@ -187,14 +189,15 @@ class BetModal(discord.ui.Modal, title="Place Your Bet"):
|
|
187 |
continue
|
188 |
|
189 |
current_scores={
|
190 |
-
|
191 |
-
|
192 |
}
|
193 |
|
194 |
score_changed=False
|
195 |
|
196 |
-
for
|
197 |
-
|
|
|
198 |
|
199 |
if previous_score is None or current_score!=previous_score:
|
200 |
score_changed=True
|
@@ -202,8 +205,8 @@ class BetModal(discord.ui.Modal, title="Place Your Bet"):
|
|
202 |
previous_scores=current_scores.copy()
|
203 |
|
204 |
if score_changed:
|
205 |
-
away_score=current_scores[
|
206 |
-
home_score=current_scores[
|
207 |
message=f"Current score update: {away_score} - {home_score}"
|
208 |
user=await interaction.client.fetch_user(self.user_id)
|
209 |
await user.send(message)
|
|
|
154 |
"league": self.league,
|
155 |
"team": self.team,
|
156 |
"amount": bet_amount,
|
157 |
+
"game_data": self.game_data,
|
158 |
+
"previous_scores": {
|
159 |
+
"away": None,
|
160 |
+
"home": None,
|
161 |
+
}
|
162 |
})
|
163 |
|
164 |
asyncio.create_task(self.monitor_game(interaction))
|
|
|
168 |
|
169 |
async def monitor_game(self, interaction):
|
170 |
|
171 |
+
previous_scores={
|
172 |
+
"away": None,
|
173 |
+
"home": None,
|
|
|
|
|
174 |
}
|
175 |
|
176 |
while True:
|
177 |
+
scores_response=await fetch_nhl_scores() if self.league =="NHL" else fetch_nfl_scores()
|
178 |
event_list_key='events' if 'events' in scores_response.get('sectionList', [{}])[0] else 'games'
|
179 |
current_game=None
|
180 |
|
181 |
for section in scores_response.get('sectionList', []):
|
182 |
for event in section.get(event_list_key , []):
|
183 |
+
if event['id']==self.game_data['id']:
|
184 |
current_game=event
|
185 |
break
|
186 |
|
|
|
189 |
continue
|
190 |
|
191 |
current_scores={
|
192 |
+
"away": current_game['lowerTeam'].get('score'),
|
193 |
+
"home": current_game['upperTeam'].get('score'),
|
194 |
}
|
195 |
|
196 |
score_changed=False
|
197 |
|
198 |
+
for key in ["away","home"]:
|
199 |
+
current_score=current_scores[key]
|
200 |
+
previous_score=previous_scores[key]
|
201 |
|
202 |
if previous_score is None or current_score!=previous_score:
|
203 |
score_changed=True
|
|
|
205 |
previous_scores=current_scores.copy()
|
206 |
|
207 |
if score_changed:
|
208 |
+
away_score=current_scores["away"] or 'N/A'
|
209 |
+
home_score=current_scores["home"] or 'N/A'
|
210 |
message=f"Current score update: {away_score} - {home_score}"
|
211 |
user=await interaction.client.fetch_user(self.user_id)
|
212 |
await user.send(message)
|