From 91be567228046171aa12db04d77dcc9189ae57f9 Mon Sep 17 00:00:00 2001 From: mathieui Date: Sat, 10 Apr 2021 22:52:01 +0200 Subject: feature: add a function to retrieve the last message from the logs --- poezio/logger.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/poezio/logger.py b/poezio/logger.py index b7fe83c8..7b6a5dc5 100644 --- a/poezio/logger.py +++ b/poezio/logger.py @@ -334,6 +334,19 @@ def build_log_message(nick: str, return logged_msg + ''.join(' %s\n' % line for line in lines) +def last_message_in_archive(filepath: Path) -> Optional[Dict]: + """Get the last message from the local archive. + + :param filepath: the log file path + """ + last_msg = None + for msg in iterate_messages_reverse(filepath): + if msg['type'] == 'message': + last_msg = msg + break + return last_msg + + def iterate_messages_reverse(filepath: Path): """Get the latest messages from the log file, one at a time. -- cgit v1.2.3