From e095c56f778629420d3b996c22274839ef8352a2 Mon Sep 17 00:00:00 2001 From: jesopo Date: Wed, 24 Apr 2019 14:32:56 +0100 Subject: [PATCH] Record and show when a !to was created --- modules/to.py | 11 +++++++---- src/utils/__init__.py | 4 ++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/modules/to.py b/modules/to.py index 146c63ee..89a1b748 100644 --- a/modules/to.py +++ b/modules/to.py @@ -5,9 +5,11 @@ class Module(ModuleManager.BaseModule): def channel_message(self, event): messages = event["channel"].get_user_setting(event["user"].get_id(), "to", []) - for nickname, message in messages: - event["channel"].send_message("%s: <%s> %s" % ( - event["user"].nickname, nickname, message)) + for nickname, message, timestamp in messages: + timestamp_parsed = utils.iso8601_parse(timestamp) + timestamp_human = utils.datetime_human(timestamp_parsed) + event["channel"].send_message("%s: <%s> %s (at %s UTC)" % ( + event["user"].nickname, nickname, message, timestamp_human)) if messages: event["channel"].del_user_setting(event["user"].get_id(), "to") @@ -22,7 +24,8 @@ class Module(ModuleManager.BaseModule): messages = event["target"].get_user_setting(target_user.get_id(), "to", []) messages.append([event["user"].nickname, - " ".join(event["args_split"][1:])]) + " ".join(event["args_split"][1:]), + utils.iso8601_format_now()]) event["target"].set_user_setting(target_user.get_id(), "to", messages) event["stdout"].write("Message saved") diff --git a/src/utils/__init__.py b/src/utils/__init__.py index 0a51493f..b3af3f61 100644 --- a/src/utils/__init__.py +++ b/src/utils/__init__.py @@ -6,6 +6,7 @@ class Direction(enum.Enum): Recv = 1 ISO8601_PARSE = "%Y-%m-%dT%H:%M:%S%z" +DATETIME_HUMAN = "%Y/%m/%d %H:%M:%S" def iso8601_format(dt: datetime.datetime, milliseconds: bool=False) -> str: timespec = "seconds" @@ -19,6 +20,9 @@ def iso8601_format_now() -> str: def iso8601_parse(s: str) -> datetime.datetime: return datetime.datetime.strptime(s, ISO8601_PARSE) +def datetime_human(dt: datetime.datetime): + return datetime.datetime.strftime(dt, DATETIME_HUMAN) + TIME_SECOND = 1 TIME_MINUTE = TIME_SECOND*60 TIME_HOUR = TIME_MINUTE*60