aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Chris <[email protected]>2021-03-26 00:07:02 +0000
committerGravatar Chris <[email protected]>2021-03-26 00:07:02 +0000
commitfea068ff529aa0e2b2f92d0f8e58f5954a49237d (patch)
tree369462391e37b524213517bd09855dff4d8b6411
parentConvert to timestamp before posting to redis (diff)
Fix error when converting non claimant message
datetime.min cannot be converted to a timestamp as it's pre-epoch. Instead wait until we actuall need it and then create the correct datetime object depending on teh cache contents.
-rw-r--r--bot/exts/help_channels/_channel.py17
1 files changed, 10 insertions, 7 deletions
diff --git a/bot/exts/help_channels/_channel.py b/bot/exts/help_channels/_channel.py
index 22966dbe0..5845e7087 100644
--- a/bot/exts/help_channels/_channel.py
+++ b/bot/exts/help_channels/_channel.py
@@ -37,11 +37,6 @@ async def get_closing_time(channel: discord.TextChannel, init_done: bool) -> t.T
idle_minutes = constants.HelpChannels.idle_minutes_claimant
claimant_last_message_time = await _caches.claimant_last_message_times.get(channel.id)
- non_claimant_last_message_time = await _caches.non_claimant_last_message_times.get(channel.id)
- if non_claimant_last_message_time is None:
- # A non-claimant hasn't messaged since session start, set to min timestamp so only claimant
- # idle period is considered when getting the closing time.
- non_claimant_last_message_time = datetime.min.timestamp()
if (
is_empty
@@ -61,10 +56,18 @@ async def get_closing_time(channel: discord.TextChannel, init_done: bool) -> t.T
# The time at which a channel should be closed.
return msg.created_at + timedelta(minutes=idle_minutes), "latest_message"
- # Get the later time at which a channel should be closed
- non_claimant_last_message_time = datetime.utcfromtimestamp(non_claimant_last_message_time)
+ # Switch to datetime objects so we can use time deltas
claimant_last_message_time = datetime.utcfromtimestamp(claimant_last_message_time)
+ non_claimant_last_message_time = await _caches.non_claimant_last_message_times.get(channel.id)
+ if non_claimant_last_message_time:
+ non_claimant_last_message_time = datetime.utcfromtimestamp(non_claimant_last_message_time)
+ else:
+ # If it's falsey, then it indicates a non-claimant has yet to reply to this session.
+ # Set to min date time so it isn't considered when calculating the closing time.
+ non_claimant_last_message_time = datetime.min
+
+ # Get the later time at which a channel should be closed
non_claimant_last_message_time += timedelta(minutes=idle_minutes)
claimant_last_message_time += timedelta(minutes=constants.HelpChannels.idle_minutes_claimant)