From 4ec51798389d9707ba5bc274f0851c0935420a44 Mon Sep 17 00:00:00 2001 From: TrustyJAID Date: Wed, 3 Jul 2024 11:58:58 -0600 Subject: [PATCH] [Hockey] Update Ducks and Kings logos and emojis. - Fix an issue where the team name is not provided by the new API. - Prevent updates in GDT, GDC, and live when scheduled games are very far in the future. --- hockey/constants.py | 8 ++++---- hockey/gamedaychannels.py | 10 +++++++++- hockey/gamedaythreads.py | 10 +++++++++- hockey/helper.py | 2 +- hockey/hockey.py | 2 ++ 5 files changed, 25 insertions(+), 7 deletions(-) diff --git a/hockey/constants.py b/hockey/constants.py index 2d71937908..1a0e23ce94 100644 --- a/hockey/constants.py +++ b/hockey/constants.py @@ -7,11 +7,11 @@ "away": "#F95602", "conference": "Western", "division": "Pacific", - "emoji": "AnaheimDucks:664662835044810772", + "emoji": "AnaheimDucks:1255947222650982531", "home": "#B5985A", "id": 24, "invite": "https://discord.gg/Pqf9W6M", - "logo": "https://i.imgur.com/mdL4rDY.png", + "logo": "https://i.imgur.com/UN3XDe5.png", "team_url": "https://www.nhl.com/ducks", "timezone": "US/Pacific", "nickname": ["ducks", "anaheim"], @@ -202,11 +202,11 @@ "away": "#B2B7BB", "conference": "Western", "division": "Pacific", - "emoji": "LosAngelesKings:664662877700882434", + "emoji": "LosAngelesKings:1255947617901477979", "home": "#111111", "id": 26, "invite": "https://discord.gg/H6EH73h", - "logo": "https://i.imgur.com/xw77waf.png", + "logo": "https://i.imgur.com/Ny6r9tI.png", "team_url": "https://www.nhl.com/kings", "timezone": "US/Pacific", "nickname": ["kings", "la"], diff --git a/hockey/gamedaychannels.py b/hockey/gamedaychannels.py index 388712cd16..e19d5d920c 100644 --- a/hockey/gamedaychannels.py +++ b/hockey/gamedaychannels.py @@ -1,4 +1,4 @@ -from datetime import datetime +from datetime import datetime, timedelta, timezone from typing import Optional import aiohttp @@ -316,6 +316,8 @@ async def gdc_setup( else: game_list = await self.api.get_games() for game in game_list: + if (game.game_start - datetime.now(timezone.utc)) > timedelta(days=7): + continue try: await self.create_gdc(guild, game) except aiohttp.ClientConnectorError: @@ -348,6 +350,8 @@ async def check_new_gdc(self) -> None: next_game = next_games[0] if next_game is None: continue + if (next_game.game_start - datetime.now(timezone.utc)) > timedelta(days=7): + continue cur_channels = await self.config.guild(guild).gdc_chans() cur_channel = guild.get_channel(cur_channels.get(str(next_game.game_id))) if cur_channel is None: @@ -359,6 +363,8 @@ async def check_new_gdc(self) -> None: for game in game_list: if game.game_state == "Postponed": continue + if (game.game_start - datetime.now(timezone.utc)) > timedelta(days=7): + continue await self.create_gdc(guild, game) async def create_gdc(self, guild: discord.Guild, game_data: Optional[Game] = None) -> None: @@ -388,6 +394,8 @@ async def create_gdc(self, guild: discord.Guild, game_data: Optional[Game] = Non next_game = next_games[0] if next_game is None: return + if (next_game.game_start - datetime.now(timezone.utc)) > timedelta(days=7): + return else: # Return if no more games are playing for this team return diff --git a/hockey/gamedaythreads.py b/hockey/gamedaythreads.py index 9c7fbb1dfe..16a50f27dd 100644 --- a/hockey/gamedaythreads.py +++ b/hockey/gamedaythreads.py @@ -1,4 +1,4 @@ -from datetime import datetime +from datetime import datetime, timedelta, timezone from typing import Optional, Union import aiohttp @@ -390,6 +390,8 @@ async def gdt_setup( for game in game_list: if game.game_state == "Postponed": continue + if (game.game_start - datetime.now(timezone.utc)) > timedelta(days=7): + continue await self.create_gdt(guild, game) msg = _("Game Day threads for {team} setup in {channel}").format( team=team, channel=channel.mention @@ -418,6 +420,8 @@ async def check_new_gdt(self) -> None: next_game = next_games[0] if next_game is None: continue + if (next_game.game_start - datetime.now(timezone.utc)) > timedelta(days=7): + continue cur_channel = None cur_channels = await self.config.guild(guild).gdt_chans() if cur_channels and str(next_game.game_id) in cur_channels: @@ -442,6 +446,8 @@ async def check_new_gdt(self) -> None: for game in game_list: if game.game_state == "Postponed": continue + if (game.game_start - datetime.now(timezone.utc)) > timedelta(days=7): + continue await self.create_gdt(guild, game) async def create_gdt(self, guild: discord.Guild, game_data: Optional[Game] = None) -> None: @@ -479,6 +485,8 @@ async def create_gdt(self, guild: discord.Guild, game_data: Optional[Game] = Non next_game = next_games[0] if next_game is None: return + if (next_game.game_start - datetime.now(timezone.utc)) > timedelta(days=7): + return else: # Return if no more games are playing for this team log.debug("No games playing") diff --git a/hockey/helper.py b/hockey/helper.py index 54e03d0392..eb4bce4ae7 100644 --- a/hockey/helper.py +++ b/hockey/helper.py @@ -181,7 +181,7 @@ def from_name(cls, team_name: str) -> Team: @classmethod def from_nhle(cls, data: dict, home: bool = False) -> Team: - name = data.get("name", {}).get("default") + name = data.get("name", {}).get("default") or data.get("placeName", {}).get("default") team_id = data.get("id", -1) team_ids = set(i["id"] for i in TEAMS.values()) if team_id in team_ids: diff --git a/hockey/hockey.py b/hockey/hockey.py index 52bfd18e90..1162b8020f 100644 --- a/hockey/hockey.py +++ b/hockey/hockey.py @@ -387,6 +387,8 @@ async def game_check_loop(self) -> None: continue if game.schedule_state != "OK": continue + if (game.game_start - datetime.now(timezone.utc)) > timedelta(days=1): + continue self.current_games[game.id] = { "count": 0, "game": None,