From 240faa03fbe7b1d26e1b185ed31fc6844b269285 Mon Sep 17 00:00:00 2001 From: jesopo Date: Wed, 29 May 2019 15:52:21 +0100 Subject: [PATCH] Move IRCv3 `server-time` code in to it's own module, save last @time tag --- modules/line_handler/ircv3.py | 1 - modules/server_time.py | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 modules/server_time.py diff --git a/modules/line_handler/ircv3.py b/modules/line_handler/ircv3.py index 42afece7..8ffcec88 100644 --- a/modules/line_handler/ircv3.py +++ b/modules/line_handler/ircv3.py @@ -10,7 +10,6 @@ CAPABILITIES = [ utils.irc.Capability("away-notify"), utils.irc.Capability("userhost-in-names"), utils.irc.Capability("message-tags", "draft/message-tags-0.2"), - utils.irc.Capability("server-time"), utils.irc.Capability("cap-notify"), utils.irc.Capability("batch"), utils.irc.Capability("echo-message"), diff --git a/modules/server_time.py b/modules/server_time.py new file mode 100644 index 00000000..e363b341 --- /dev/null +++ b/modules/server_time.py @@ -0,0 +1,17 @@ +from src import ModuleManager, utils + +CAP = utils.irc.Capability("server-time") +TAG = utils.irc.MessageTag("time") + +class Module(ModuleManager.BaseModule): + @utils.hook("received.cap.ls") + @utils.hook("received.cap.new") + def on_cap(self, event): + if CAP.available(event["capabilities"]): + return CAP.copy() + + @utils.hook("raw.received") + def raw_recv(self, event): + server_time = TAG.get_value(event["line"].tags) + if not server_time == None: + event["server"].set_setting("last-server-time", server_time)