mod_uptime: Updated to use events (which also fixes a few minor issues).
[prosody.git] / plugins / mod_uptime.lua
1 -- Prosody IM
2 -- Copyright (C) 2008-2009 Matthew Wild
3 -- Copyright (C) 2008-2009 Waqas Hussain
4 -- 
5 -- This project is MIT/X11 licensed. Please see the
6 -- COPYING file in the source package for more information.
7 --
8
9 local st = require "util.stanza"
10
11 local jid_split = require "util.jid".split;
12 local t_concat = table.concat;
13
14 local start_time = prosody.start_time;
15 prosody.events.add_handler("server-started", function() start_time = prosody.start_time end);
16
17 module:add_feature("jabber:iq:last");
18
19 module:hook("iq/host/jabber:iq:last:query", function(event)
20         local origin, stanza = event.origin, event.stanza;
21         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))}));
23                 return true;
24         end
25 end);
26
27 module:hook("iq/bare/jabber:iq:last:query", function(event)
28         local origin, stanza = event.origin, event.stanza;
29         if stanza.attr.type == "get" then
30                 -- TODO last activity
31         end
32 end);