diff options
| author | 2021-03-25 22:26:30 +0000 | |
|---|---|---|
| committer | 2021-03-25 22:26:30 +0000 | |
| commit | f22865931b9cc40b406d8af488d3e65321626f57 (patch) | |
| tree | c9c481c59395f732c919f2061d0a253499a7c4ea | |
| parent | Create utc datetime objects from timestamps (diff) | |
Refactor help channel update message cache function for clearer flow
| -rw-r--r-- | bot/exts/help_channels/_message.py | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/bot/exts/help_channels/_message.py b/bot/exts/help_channels/_message.py index 9506f7edd..d60b31dea 100644 --- a/bot/exts/help_channels/_message.py +++ b/bot/exts/help_channels/_message.py @@ -49,22 +49,21 @@ async def update_message_caches(message: discord.Message) -> None: # Confirm the channel is an in use help channel if is_in_category(channel, constants.Categories.help_in_use): log.trace(f"Checking if #{channel} ({channel.id}) has had a reply.") - # Use datetime naive time stamp to be consistant with timestamps from discord. - timestamp = datetime.now().timestamp() claimant_id = await _caches.claimants.get(channel.id) - # Overwrite the claimant message time, if its from the claimant. - if message.author.id == claimant_id: - await _caches.claimant_last_message_times.set(channel.id, timestamp) - return - if not claimant_id: # The mapping for this channel doesn't exist, we can't do anything. return - # Cache the timestamp of the non-claimants message - await _caches.non_claimant_last_message_times.set(channel.id, timestamp) + # Use datetime naive time stamp to be consistant with timestamps from discord. + timestamp = message.created_at.timestamp() + + # Overwrite the appropriate last message cache depending on the author of the message + if message.author.id == claimant_id: + await _caches.claimant_last_message_times.set(channel.id, timestamp) + else: + await _caches.non_claimant_last_message_times.set(channel.id, timestamp) async def get_last_message(channel: discord.TextChannel) -> t.Optional[discord.Message]: |