# HG changeset patch # User Matthew Wild # Date 1679056249 0 # Node ID a48a4723aa2aab4a66b098997bf4dcf07cb973c7 # Parent 2bb12fb6fcbd533950084ff3fcea49fcbd922eab Add time query plugin diff -r 2bb12fb6fcbd -r a48a4723aa2a plugins/time.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/time.lua Fri Mar 17 12:30:49 2023 +0000 @@ -0,0 +1,34 @@ +local verse = require "verse"; +local dt = require "util.datetime"; + +local xmlns_time = "urn:xmpp:time"; + +function verse.plugins.time(stream) + function stream:query_time(target_jid, callback) + callback = callback or function (time) return self:event("time/response", time); end + self:send_iq(verse.iq({ type = "get", to = target_jid }) + :tag("time", { xmlns = xmlns_time }), + function (reply) + if reply.attr.type == "result" then + local query = reply:get_child("time", xmlns_time); + local resp = { + tzo = query:get_child_text("tzo"); + utc = query:get_child_text("utc"); + }; + if resp.utc then + resp.timestamp = dt.parse(resp.utc); + end + callback(resp); + else + local type, condition, text = reply:get_error(); + callback({ + error = true; + condition = condition; + text = text; + type = type; + }); + end + end); + end + return true; +end diff -r 2bb12fb6fcbd -r a48a4723aa2a squishy --- a/squishy Fri Mar 17 12:30:25 2023 +0000 +++ b/squishy Fri Mar 17 12:30:49 2023 +0000 @@ -63,7 +63,7 @@ -- Reliability "smacks", "keepalive"; -- Queries - "disco", "version", "ping", "uptime"; + "disco", "version", "ping", "uptime", "time"; -- Privacy control "blocking"; -- Jingle / file transfer