From ee7a0053b714da8e9b2cf5c66f2a3b3c255cfb6a Mon Sep 17 00:00:00 2001 From: kwzrd Date: Tue, 17 Mar 2020 22:53:03 +0100 Subject: Deseasonify: keep track of `path` on github files Since the banner and avatar assets will always have the same filename, we need their full paths to differentiate between assets of different seasons. Rather than introducing more complexity to the `pretty_files` function and deconstructing the download urls, we can just store the path as provided by the API. We also now print the `path` instead of showing bools in the status embed, as just the fact that there is some banner is not enough information - we want to know which season's banner has been picked up during refresh. --- bot/branding.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'bot/branding.py') diff --git a/bot/branding.py b/bot/branding.py index 68d2d8bd..2a554eac 100644 --- a/bot/branding.py +++ b/bot/branding.py @@ -31,17 +31,13 @@ class GithubFile(t.NamedTuple): """ download_url: str + path: str sha: str async def pretty_files(files: t.Iterable[GithubFile]) -> str: - """ - Provide a human-friendly representation of `files`. - - In practice, this retrieves the filename from each file's url, - and joins them on a comma. - """ - return ", ".join(file.download_url.split("/")[-1] for file in files) + """Provide a human-friendly representation of `files`.""" + return ", ".join(file.path for file in files) async def seconds_until_midnight() -> float: @@ -134,13 +130,13 @@ class BrandingManager(commands.Cog): description=f"Active in {', '.join(m.name for m in self.current_season.months)}", ).add_field( name="Banner", - value=f"{self.banner is not None}", + value=self.banner.path if self.banner is not None else "Unavailable", ).add_field( name="Avatar", - value=f"{self.avatar is not None}", + value=self.avatar.path if self.avatar is not None else "Unavailable", ).add_field( name="Available icons", - value=await pretty_files(self.available_icons) or "Empty", + value=await pretty_files(self.available_icons) or "Unavailable", inline=False, ) @@ -187,7 +183,7 @@ class BrandingManager(commands.Cog): directory = await resp.json() return { - file["name"]: GithubFile(file["download_url"], file["sha"]) + file["name"]: GithubFile(file["download_url"], file["path"], file["sha"]) for file in directory } -- cgit v1.2.3