Record and show when a !to was created
This commit is contained in:
parent
dc102f258d
commit
e095c56f77
2 changed files with 11 additions and 4 deletions
|
@ -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")
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue