Software /
code /
prosody
Comparison
plugins/mod_uptime.lua @ 2015:2140c994671e
mod_uptime: Updated to use events (which also fixes a few minor issues).
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Sun, 18 Oct 2009 19:42:45 +0500 |
parent | 1524:a89fec6d76d2 |
child | 2016:5d47cfa4b2a0 |
comparison
equal
deleted
inserted
replaced
2014:913c0845ef9a | 2015:2140c994671e |
---|---|
4 -- | 4 -- |
5 -- This project is MIT/X11 licensed. Please see the | 5 -- This project is MIT/X11 licensed. Please see the |
6 -- COPYING file in the source package for more information. | 6 -- COPYING file in the source package for more information. |
7 -- | 7 -- |
8 | 8 |
9 | |
10 | |
11 local st = require "util.stanza" | 9 local st = require "util.stanza" |
12 | 10 |
13 local jid_split = require "util.jid".split; | 11 local jid_split = require "util.jid".split; |
14 local t_concat = table.concat; | 12 local t_concat = table.concat; |
15 | 13 |
16 local start_time = prosody.start_time; | 14 local start_time = prosody.start_time; |
17 | 15 prosody.events.add_handler("server-started", function() start_time = prosody.start_time end); |
18 prosody.events.add_handler("server-started", function () start_time = prosody.start_time end); | |
19 | 16 |
20 module:add_feature("jabber:iq:last"); | 17 module:add_feature("jabber:iq:last"); |
21 | 18 |
22 module:add_iq_handler({"c2s", "s2sin"}, "jabber:iq:last", | 19 module:hook("iq/host/jabber:iq:last:query", function(event) |
23 function (origin, stanza) | 20 local origin, stanza = event.origin, event.stanza; |
24 if stanza.tags[1].name == "query" then | 21 if stanza.attr.type == "get" then |
25 if stanza.attr.type == "get" then | 22 origin.send(st.reply(stanza):tag("query", {xmlns = "jabber:iq:last", seconds = tostring(os.difftime(os.time(), start_time))})); |
26 local node, host, resource = jid_split(stanza.attr.to); | 23 return true; |
27 if node or resource then | 24 end |
28 -- TODO | 25 end); |
29 else | 26 |
30 origin.send(st.reply(stanza):tag("query", {xmlns = "jabber:iq:last", seconds = tostring(os.difftime(os.time(), start_time))})); | 27 module:hook("iq/bare/jabber:iq:last:query", function(event) |
31 return true; | 28 local origin, stanza = event.origin, event.stanza; |
32 end | 29 if stanza.attr.type == "get" then |
33 end | 30 -- TODO last activity |
34 end | 31 end |
35 end); | 32 end); |