From 90f6743b46ddfa26bf8952daf6a5957a73c19138 Mon Sep 17 00:00:00 2001 From: TrustyJAID Date: Mon, 13 Nov 2023 18:41:40 -0700 Subject: [PATCH] [Hockey] Fix preview 60, 30, and 10 minute message spam. Fix schedule for individual teams. --- hockey/api.py | 17 +++++++++++------ hockey/game.py | 3 +++ hockey/schedule.py | 21 ++++++++++++--------- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/hockey/api.py b/hockey/api.py index 8416c44647..48143e2baa 100644 --- a/hockey/api.py +++ b/hockey/api.py @@ -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", []): @@ -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() @@ -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: diff --git a/hockey/game.py b/hockey/game.py index 0df26dfbd6..b88f37cb57 100644 --- a/hockey/game.py +++ b/hockey/game.py @@ -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) diff --git a/hockey/schedule.py b/hockey/schedule.py index 166aa77f44..0babf910b2 100644 --- a/hockey/schedule.py +++ b/hockey/schedule.py @@ -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: