aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar kwzrd <[email protected]>2020-03-22 15:41:32 +0100
committerGravatar kwzrd <[email protected]>2020-03-22 15:45:32 +0100
commitee09986439c5e750513bdbaca556c742affd33ed (patch)
treed608aeb9648b3d2dffbdc198887db9816cf14b2e
parentDeseasonify: add ok_hand emoji constant (diff)
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.
-rw-r--r--bot/branding.py9
1 files changed, 5 insertions, 4 deletions
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."""