Skip to content

Commit

Permalink
[Hockey] Update Ducks and Kings logos and emojis.
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
TrustyJAID committed Jul 3, 2024
1 parent 3c78488 commit 4ec5179
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 7 deletions.
8 changes: 4 additions & 4 deletions hockey/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down Expand Up @@ -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"],
Expand Down
10 changes: 9 additions & 1 deletion hockey/gamedaychannels.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime
from datetime import datetime, timedelta, timezone
from typing import Optional

import aiohttp
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion hockey/gamedaythreads.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime
from datetime import datetime, timedelta, timezone
from typing import Optional, Union

import aiohttp
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion hockey/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions hockey/hockey.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 4ec5179

Please sign in to comment.