mod_welcome: Use module:hook instead of module:add_event_hook
[prosody.git] / plugins / mod_uptime.lua
1 -- Prosody IM v0.4
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
10 \r
11 local st = require "util.stanza"\r
12 \r
13 local jid_split = require "util.jid".split;\r
14 local t_concat = table.concat;\r
15 \r
16 local start_time = os.time();\r
17 \r
18 module:add_feature("jabber:iq:last");\r
19 \r
20 module:add_iq_handler({"c2s", "s2sin"}, "jabber:iq:last", \r
21         function (origin, stanza)\r
22                 if stanza.tags[1].name == "query" then\r
23                         if stanza.attr.type == "get" then\r
24                                 local node, host, resource = jid_split(stanza.attr.to);\r
25                                 if node or resource then\r
26                                         -- TODO\r
27                                 else\r
28                                         origin.send(st.reply(stanza):tag("query", {xmlns = "jabber:iq:last", seconds = tostring(os.difftime(os.time(), start_time))}));\r
29                                         return true;\r
30                                 end\r
31                         end\r
32                 end\r
33         end);\r