Skip to content

Commit

Permalink
[Hockey] Fix preview 60, 30, and 10 minute message spam.
Browse files Browse the repository at this point in the history
Fix schedule for individual teams.
  • Loading branch information
TrustyJAID committed Nov 14, 2023
1 parent a4456b2 commit 90f6743
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
17 changes: 11 additions & 6 deletions hockey/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,10 @@ def from_statsapi(cls, data: dict) -> Schedule:
@classmethod
def from_nhle(cls, data: dict) -> Schedule:
days = []
if "games" in data:
for g in data.get("games", []):
days.append([ScheduledGame.from_nhle(g)])

for day in data.get("gameWeek", []):
games = []
for game in day.get("games", []):
Expand Down Expand Up @@ -718,14 +722,15 @@ async def club_schedule_week(self, team: str, date: Optional[datetime] = None) -
team_abr = self.team_to_abbrev(team)
date_str = "now"
if date is not None:
date_str = date.strftime("%Y-%M-%d")
date_str = date.strftime("%Y-%m-%d")
if team_abr is None:
raise HockeyAPIError("An unknown team name was provided")
async with self.session.get(
f"{self.base_url}/club-schedule/{team_abr}/week/{date_str}"
) as resp:
url = f"{self.base_url}/club-schedule/{team_abr}/week/{date_str}"
async with self.session.get(url) as resp:
if resp.status != 200:
log.error("Error accessing the Club Schedule for the week. %s", resp.status)
log.error(
"Error accessing the Club Schedule for the week. %s: %s", resp.status, url
)
raise HockeyAPIError("There was an error accessing the API.")

data = await resp.json()
Expand All @@ -739,7 +744,7 @@ async def club_schedule_month(self, team: str, date: Optional[datetime] = None)

date_str = "now"
if date is not None:
date_str = date.strftime("%Y-%M")
date_str = date.strftime("%Y-%m")
async with self.session.get(
f"{self.base_url}/club-schedule/{team_abr}/month/{date_str}"
) as resp:
Expand Down
3 changes: 3 additions & 0 deletions hockey/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,15 +713,18 @@ async def check_game_state(self, bot: Red, count: int = 0) -> bool:
if game_start < 60 and game_start > 30 and old_game_state is not GameState.preview_60:
# Post 60 minutes until game start
await self.post_time_to_game_start(bot, "60")
self.game_state = GameState.preview_60
await self.save_game_state(bot, "60")
bot.dispatch("hockey_preview", self)
if game_start < 30 and game_start > 10 and old_game_state is not GameState.preview_30:
# Post 30 minutes until game start
self.game_state = GameState.preview_30
await self.post_time_to_game_start(bot, "30")
await self.save_game_state(bot, "30")
bot.dispatch("hockey_preview", self)
if game_start < 10 and game_start > 0 and old_game_state is not GameState.preview_10:
# Post 10 minutes until game start
self.game_state = GameState.preview_10
await self.post_time_to_game_start(bot, "10")
await self.save_game_state(bot, "10")
bot.dispatch("hockey_preview", self)
Expand Down
21 changes: 12 additions & 9 deletions hockey/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,15 +511,18 @@ async def _next_batch(
if self.team:
team = self.team[0]
data = await self.api.get_schedule(team, date, end_date)
days = data.days
if not days:
# log.debug("No schedule, looking for more days")
if self._checks < self.limit:
self._checks += 1
games = await self._next_batch(date=self.date, _next=_next, _prev=_prev)
else:
raise NoSchedule
games = days[0]
if team is None:
days = data.days
if not days:
# log.debug("No schedule, looking for more days")
if self._checks < self.limit:
self._checks += 1
games = await self._next_batch(date=self.date, _next=_next, _prev=_prev)
else:
raise NoSchedule
games = days[0]
else:
games = data.games
if not games:
# log.debug("No schedule, looking for more days")
if self._checks < self.limit:
Expand Down

0 comments on commit 90f6743

Please sign in to comment.