2 -- Copyright (C) 2008-2010 Matthew Wild
3 -- Copyright (C) 2008-2010 Waqas Hussain
5 -- This project is MIT/X11 licensed. Please see the
6 -- COPYING file in the source package for more information.
9 local st
= require
"util.stanza";
11 local start_time
= prosody
.start_time
;
12 module
:hook_global("server-started", function() start_time
= prosody
.start_time
end);
14 -- XEP-0012: Last activity
15 module
:add_feature("jabber:iq:last");
17 module
:hook("iq-get/host/jabber:iq:last:query", function(event
)
18 local origin
, stanza
= event
.origin
, event
.stanza
;
19 origin
.send(st
.reply(stanza
):tag("query", {xmlns
= "jabber:iq:last", seconds
= tostring(os
.difftime(os
.time(), start_time
))}));
24 module
:depends
"adhoc";
25 local adhoc_new
= module
:require
"adhoc".new
;
27 function uptime_text()
28 local t
= os
.time()-prosody
.start_time
;
36 return string.format("This server has been running for %d day%s, %d hour%s and %d minute%s (since %s)",
37 days
, (days
~= 1 and "s") or "", hours
, (hours
~= 1 and "s") or "",
38 minutes
, (minutes
~= 1 and "s") or "", os
.date("%c", prosody
.start_time
));
41 function uptime_command_handler ()
42 return { info
= uptime_text(), status
= "completed" };
45 local descriptor
= adhoc_new("Get uptime", "uptime", uptime_command_handler
);
47 module
:provides("adhoc", descriptor
);