diff options
| author | 2020-06-08 18:41:25 -0700 | |
|---|---|---|
| committer | 2020-06-08 18:41:25 -0700 | |
| commit | 378ef81383050cf4c477afc2c23abb51b700ea68 (patch) | |
| tree | aa23e950347944b7042de752464612529cf3d2af | |
| parent | Remove pointless suppress. (diff) | |
Help channels: fix claim timestamp being local
The datetime module returns a local timestamp for naïve datetimes.
It has to be timezone-aware to ensure it will always be in UTC.
| -rw-r--r-- | bot/cogs/help_channels.py | 11 | 
1 files changed, 7 insertions, 4 deletions
| diff --git a/bot/cogs/help_channels.py b/bot/cogs/help_channels.py index e521e3301..40e625338 100644 --- a/bot/cogs/help_channels.py +++ b/bot/cogs/help_channels.py @@ -5,7 +5,7 @@ import logging  import random  import typing as t  from collections import deque -from datetime import datetime +from datetime import datetime, timezone  from pathlib import Path  import discord @@ -110,7 +110,7 @@ class HelpChannels(Scheduler, commands.Cog):      unanswered = RedisCache()      # This dictionary maps a help channel to the time it was claimed -    # RedisCache[discord.TextChannel.id, datetime.datetime] +    # RedisCache[discord.TextChannel.id, UtcPosixTimestamp]      claim_times = RedisCache()      def __init__(self, bot: Bot): @@ -550,7 +550,7 @@ class HelpChannels(Scheduler, commands.Cog):          claimed_timestamp = await self.claim_times.get(channel.id)          if claimed_timestamp: -            claimed = datetime.fromtimestamp(claimed_timestamp) +            claimed = datetime.utcfromtimestamp(claimed_timestamp)              in_use_time = datetime.utcnow() - claimed              self.bot.stats.timing("help.in_use_time", in_use_time) @@ -687,7 +687,10 @@ class HelpChannels(Scheduler, commands.Cog):              self.bot.stats.incr("help.claimed") -            await self.claim_times.set(channel.id, datetime.utcnow().timestamp()) +            # Must use a timezone-aware datetime to ensure a correct POSIX timestamp. +            timestamp = datetime.now(timezone.utc).timestamp() +            await self.claim_times.set(channel.id, timestamp) +              await self.unanswered.set(channel.id, True)              log.trace(f"Releasing on_message lock for {message.id}.") | 
