Comparison

mod_adhoc_cmd_uptime/mod_adhoc_cmd_uptime.lua @ 38:b9bf8a35b064

mod_adhoc_cmd_uptime: Initial commit
author Florian Zeitz <florob@babelmonkeys.de>
date Mon, 12 Oct 2009 20:54:40 +0200
child 109:9b63fd1196c0
comparison
equal deleted inserted replaced
37:6018c0370d89 38:b9bf8a35b064
1 -- Copyright (C) 2009 Florian Zeitz
2 --
3 -- This file is MIT/X11 licensed. Please see the
4 -- COPYING file in the source package for more information.
5 --
6
7 local _G = _G;
8 local prosody = _G.prosody;
9 local st, uuid = require "util.stanza", require "util.uuid";
10 local adhoc_new = module:require "adhoc".new;
11
12 function uptime()
13 local t = os.time()-prosody.start_time;
14 local seconds = t%60;
15 t = (t - seconds)/60;
16 local minutes = t%60;
17 t = (t - minutes)/60;
18 local hours = t%24;
19 t = (t - hours)/24;
20 local days = t;
21 return string.format("This server has been running for %d day%s, %d hour%s and %d minute%s (since %s)",
22 days, (days ~= 1 and "s") or "", hours, (hours ~= 1 and "s") or "",
23 minutes, (minutes ~= 1 and "s") or "", os.date("%c", prosody.start_time));
24 end
25
26 function uptime_command_handler (item, origin, stanza)
27 origin.send(st.reply(stanza):add_child(item:cmdtag("completed", uuid.generate()):tag("note", {type="info"}):text(uptime())));
28 return true;
29 end
30
31 local descriptor = adhoc_new("Get uptime", "uptime", uptime_command_handler);
32
33 function module.unload()
34 module:remove_item("adhoc", descriptor);
35 end
36
37 module:add_item ("adhoc", descriptor);
38