From 5854f28869d48f83322c315f3f1bfa5722368536 Mon Sep 17 00:00:00 2001 From: Context 77 <126421199+ctx77@users.noreply.github.com> Date: Sat, 3 Aug 2024 01:41:25 +0200 Subject: [PATCH] update .seen: f-strings and answer "noch nicht gesehen" instead of 1970. --- FaustBot/Modules/SeenObserver.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/FaustBot/Modules/SeenObserver.py b/FaustBot/Modules/SeenObserver.py index da7b501..e8b704f 100644 --- a/FaustBot/Modules/SeenObserver.py +++ b/FaustBot/Modules/SeenObserver.py @@ -15,18 +15,19 @@ class SeenObserver(PrivMsgObserverPrototype): return ".seen - um abzufragen wann zuletzt hier war" def update_on_priv_msg(self, data, connection: Connection): - if data['message'].find('.seen ') == -1: - return - if not self._is_idented_mod(data, connection): - return - who = data['message'].split(' ')[1] - user_provider = UserProvider() - activity = user_provider.get_activity(who) - output = data['nick']+": Ich habe "+who+" zuletzt am "+str(datetime.datetime.fromtimestamp(activity).strftime("%d.%m.%Y um %H:%M:%S"))+ ' Uhr gesehen' - if not self._is_idented_mod(data, connection): - connection.send_channel(output) - return - connection.send_back(output, data) + if data["message"].startswith(".seen ") and self._is_idented_mod( + data, connection + ): + who = data["message"].split(" ")[1] + + user_provider = UserProvider() + activity = user_provider.get_activity(who) + if activity == 0: + output = f"{data['nick']}: Ich habe {who} noch nicht gesehen." + else: + output = f"{data['nick']}: Ich habe {who} zuletzt am {str(datetime.datetime.fromtimestamp(activity).strftime('%d.%m.%Y um %H:%M:%S'))} Uhr gesehen." + + connection.send_back(output, data) def _is_idented_mod(self, data: dict, connection: Connection): - return data['nick'] in self._config.mods and connection.is_idented(data['nick']) \ No newline at end of file + return data["nick"] in self._config.mods and connection.is_idented(data["nick"])