From 9fdf8033bbaefdbe83f6f860e3414b962ff570c4 Mon Sep 17 00:00:00 2001 From: TrustyJAID Date: Tue, 14 Nov 2023 11:19:20 -0700 Subject: [PATCH] [Hockey] Not sure how pickems didn't save game state correctly but this should fix it. --- hockey/hockeypickems.py | 6 +++--- hockey/pickems.py | 6 +++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/hockey/hockeypickems.py b/hockey/hockeypickems.py index 01ca32464f..46aded138e 100644 --- a/hockey/hockeypickems.py +++ b/hockey/hockeypickems.py @@ -13,7 +13,7 @@ from hockey.helper import utc_to_local from .abc import HockeyMixin -from .game import Game, GameType +from .game import Game, GameState, GameType from .pickems import Pickems _ = Translator("Hockey", __file__) @@ -206,7 +206,7 @@ async def set_guild_pickem_winner(self, game: Game, edit_message: bool = False) if not await pickem.check_winner(game): # log.debug("Game %r does not have a winner yet.", game) continue - if game.game_state == pickem.game_state: + if game.game_state is pickem.game_state: # log.debug("Game state %s not equal to pickem game state %s", game.game_state, pickem.game_state) continue pickem.game_state = game.game_state @@ -486,7 +486,7 @@ async def create_pickems_channel( async def make_pickems_msg(self, guild: discord.Guild, game: Game) -> str: winner = "" - if game.game_state == "Final": + if game.game_state.value > GameState.over.value: team = game.home_team if game.home_score > game.away_score else game.away_team team_emoji = game.home_emoji if game.home_score > game.away_score else game.away_emoji winner = _("**WINNER:** {team_emoji} {team}").format(team_emoji=team_emoji, team=team) diff --git a/hockey/pickems.py b/hockey/pickems.py index 60366456ed..34226bc6d2 100644 --- a/hockey/pickems.py +++ b/hockey/pickems.py @@ -241,9 +241,13 @@ def from_json(cls, data: dict) -> Pickems: log.trace("Pickems from_json data: %s", data) game_start = datetime.strptime(data["game_start"], "%Y-%m-%dT%H:%M:%SZ") game_start = game_start.replace(tzinfo=timezone.utc) + try: + game_state = GameState(data["game_state"]) + except ValueError: + game_state = GameState.from_statsapi(data["game_state"]) return cls( game_id=data["game_id"], - game_state=GameState(data["game_state"]), + game_state=game_state, messages=data.get("messages", []), guild=data["guild"], game_start=game_start,