Software /
code /
verse
Annotate
plugins/time.lua @ 500:674daff6c73b
use util.bitcompat from Prosody for bitwise compat layer
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 23 Jun 2023 12:26:43 +0200 |
parent | 490:6b2f31da9610 |
rev | line source |
---|---|
480 | 1 local verse = require "verse"; |
490
6b2f31da9610
Update for new Prosody module namespace
Kim Alvefur <zash@zash.se>
parents:
480
diff
changeset
|
2 local dt = require "prosody.util.datetime"; |
480 | 3 |
4 local xmlns_time = "urn:xmpp:time"; | |
5 | |
6 function verse.plugins.time(stream) | |
7 function stream:query_time(target_jid, callback) | |
8 callback = callback or function (time) return self:event("time/response", time); end | |
9 self:send_iq(verse.iq({ type = "get", to = target_jid }) | |
10 :tag("time", { xmlns = xmlns_time }), | |
11 function (reply) | |
12 if reply.attr.type == "result" then | |
13 local query = reply:get_child("time", xmlns_time); | |
14 local resp = { | |
15 tzo = query:get_child_text("tzo"); | |
16 utc = query:get_child_text("utc"); | |
17 }; | |
18 if resp.utc then | |
19 resp.timestamp = dt.parse(resp.utc); | |
20 end | |
21 callback(resp); | |
22 else | |
23 local type, condition, text = reply:get_error(); | |
24 callback({ | |
25 error = true; | |
26 condition = condition; | |
27 text = text; | |
28 type = type; | |
29 }); | |
30 end | |
31 end); | |
32 end | |
33 return true; | |
34 end |