9c2cb45da70bac21c9afd312caf2064ba98cd445
[prosody.git] / plugins / mod_uptime.lua
1 \r
2 local st = require "util.stanza"\r
3 \r
4 local jid_split = require "util.jid".split;\r
5 local t_concat = table.concat;\r
6 \r
7 local start_time = os.time();\r
8 \r
9 require "core.discomanager".set("uptime", "jabber:iq:last");\r
10 \r
11 add_iq_handler({"c2s", "s2sin"}, "jabber:iq:last", \r
12         function (origin, stanza)\r
13                 if stanza.tags[1].name == "query" then\r
14                         if stanza.attr.type == "get" then\r
15                                 local node, host, resource = jid_split(stanza.attr.to);\r
16                                 if node or resource then\r
17                                         -- TODO\r
18                                 else\r
19                                         origin.send(st.reply(stanza):tag("query", {xmlns = "jabber:iq:last", seconds = tostring(os.difftime(os.time(), start_time))}));\r
20                                         return true;\r
21                                 end\r
22                         end\r
23                 end\r
24         end);\r