aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Chris <[email protected]>2021-03-25 23:24:32 +0000
committerGravatar Chris <[email protected]>2021-03-25 23:24:32 +0000
commita3a5fc491a6fe47791f6a46ceda733f2b01442d7 (patch)
tree5a62c8a6d2524fb6e5825433286533a41c05e606
parentRefactor if block within help channel system to be more readable (diff)
Reset a channel's non-claimant cache on claim, to indicate that the session has yet to be answered.
-rw-r--r--bot/exts/help_channels/_channel.py11
-rw-r--r--bot/exts/help_channels/_cog.py5
2 files changed, 9 insertions, 7 deletions
diff --git a/bot/exts/help_channels/_channel.py b/bot/exts/help_channels/_channel.py
index 9497cb4fb..22966dbe0 100644
--- a/bot/exts/help_channels/_channel.py
+++ b/bot/exts/help_channels/_channel.py
@@ -36,17 +36,20 @@ async def get_closing_time(channel: discord.TextChannel, init_done: bool) -> t.T
else:
idle_minutes = constants.HelpChannels.idle_minutes_claimant
- non_claimant_last_message_time = await _caches.non_claimant_last_message_times.get(channel.id)
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
or not init_done
- or non_claimant_last_message_time is None
or claimant_last_message_time is None
):
- # if the current help channel has no messages, the help system cog is starting or
- # at least one of the caches is empty use the last message in the channel to determine closing time instead.
+ # If the current help channel has no messages, the help system cog is starting or
+ # the claimant cache is empty, use the last message in the channel to determine closing time instead.
msg = await _message.get_last_message(channel)
diff --git a/bot/exts/help_channels/_cog.py b/bot/exts/help_channels/_cog.py
index a8828348c..d9b288280 100644
--- a/bot/exts/help_channels/_cog.py
+++ b/bot/exts/help_channels/_cog.py
@@ -116,9 +116,8 @@ class HelpChannels(commands.Cog):
await _caches.claim_times.set(message.channel.id, message.created_at)
await _caches.claimant_last_message_times.set(message.channel.id, message.created_at)
- # non_claimant needs to be set too, to satisfy the condition in `_channel.get_closing_time` the first time.
- # Otherwise it will fall back to the old method if no other messages are sent.
- await _caches.non_claimant_last_message_times.set(message.channel.id, message.created_at)
+ # Reset thie non_claimant cache for this channel to indicate that this session has yet to be answered.
+ await _caches.non_claimant_last_message_times.delete(message.channel.id)
# Not awaited because it may indefinitely hold the lock while waiting for a channel.
scheduling.create_task(self.move_to_available(), name=f"help_claim_{message.id}")