From ee09986439c5e750513bdbaca556c742affd33ed Mon Sep 17 00:00:00 2001 From: kwzrd Date: Sun, 22 Mar 2020 15:41:32 +0100 Subject: Deseasonify: return timedelta rather than raw seconds This will allow more introspection in the sense of displaying the remaining time until midnight in a human-readable format. --- bot/branding.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'bot/branding.py') diff --git a/bot/branding.py b/bot/branding.py index 0b5c7b7e..eb360f5f 100644 --- a/bot/branding.py +++ b/bot/branding.py @@ -48,9 +48,9 @@ async def pretty_files(files: t.Iterable[GithubFile]) -> str: return "\n".join(file.path for file in files) -async def seconds_until_midnight() -> float: +async def time_until_midnight() -> timedelta: """ - Give the amount of seconds needed to wait until the next-up UTC midnight. + Determine amount of time until the next-up UTC midnight. The exact `midnight` moment is actually delayed to 5 seconds after, in order to avoid potential problems due to imprecise sleep. @@ -59,7 +59,7 @@ async def seconds_until_midnight() -> float: tomorrow = now + timedelta(days=1) midnight = datetime.combine(tomorrow, time(second=5)) - return (midnight - now).total_seconds() + return midnight - now class BrandingManager(commands.Cog): @@ -138,7 +138,8 @@ class BrandingManager(commands.Cog): elif next(self.should_cycle): await self.cycle() - await asyncio.sleep(await seconds_until_midnight()) + until_midnight = await time_until_midnight() + await asyncio.sleep(until_midnight.total_seconds()) async def _info_embed(self) -> discord.Embed: """Make an informative embed representing current season.""" -- cgit v1.2.3