From e4f073172a9be766607bfeefe56ce8944aa521ae Mon Sep 17 00:00:00 2001 From: dgw Date: Sun, 6 Mar 2022 13:17:24 -0600 Subject: [PATCH 1/2] seen: modify calculation to work now that `trigger.time` is Aware --- sopel/modules/seen.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/sopel/modules/seen.py b/sopel/modules/seen.py index fa9461047b..d4bf715a2c 100644 --- a/sopel/modules/seen.py +++ b/sopel/modules/seen.py @@ -9,7 +9,6 @@ """ from __future__ import annotations -import datetime import time from sopel import plugin @@ -31,8 +30,8 @@ def seen(bot, trigger): bot.reply("I'm right here!") return - timestamp = bot.db.get_nick_value(nick, 'seen_timestamp') - if not timestamp: + saw = bot.db.get_nick_value(nick, 'seen_timestamp') + if not saw: bot.reply("Sorry, I haven't seen {nick} around.".format(nick=nick)) return @@ -40,8 +39,8 @@ def seen(bot, trigger): message = bot.db.get_nick_value(nick, 'seen_message') action = bot.db.get_nick_value(nick, 'seen_action') - saw = datetime.datetime.utcfromtimestamp(timestamp) - delta = seconds_to_human((trigger.time - saw).total_seconds()) + # as of Sopel 8, trigger.time is an aware datetime + delta = seconds_to_human(trigger.time.timestamp() - saw) msg = "I last saw " + nick if bot.make_identifier(channel) == trigger.sender: From fa32d02dba53c5f2d1b167160a03aa33e8bfef80 Mon Sep 17 00:00:00 2001 From: dgw Date: Mon, 7 Mar 2022 16:01:31 -0600 Subject: [PATCH 2/2] seen: store `trigger.time.timestamp()` instead of `time.time()` This is for timezone safety. Co-authored-by: Exirel --- sopel/modules/seen.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sopel/modules/seen.py b/sopel/modules/seen.py index d4bf715a2c..71605ab9eb 100644 --- a/sopel/modules/seen.py +++ b/sopel/modules/seen.py @@ -9,8 +9,6 @@ """ from __future__ import annotations -import time - from sopel import plugin from sopel.tools.time import seconds_to_human @@ -65,7 +63,9 @@ def seen(bot, trigger): @plugin.require_chanmsg def note(bot, trigger): nick = trigger.nick - bot.db.set_nick_value(nick, 'seen_timestamp', time.time()) + # as of Sopel 8, `trigger.time` is Aware, meaning we should store its value + # for timezone safety when comparing it later + bot.db.set_nick_value(nick, 'seen_timestamp', trigger.time.timestamp()) bot.db.set_nick_value(nick, 'seen_channel', trigger.sender) bot.db.set_nick_value(nick, 'seen_message', trigger) bot.db.set_nick_value(nick, 'seen_action', trigger.ctcp is not None)