comparison mod_adhoc_cmd_uptime/mod_adhoc_cmd_uptime.lua @ 124:843cadf36306

mod_adhoc*: Move state handling to mod_adhoc itself
author Florian Zeitz <florob@babelmonkeys.de>
date Sat, 23 Jan 2010 04:43:28 +0100
parents a9898f13c89e
children
comparison
equal deleted inserted replaced
123:c04443ea114c 124:843cadf36306
4 -- COPYING file in the source package for more information. 4 -- COPYING file in the source package for more information.
5 -- 5 --
6 6
7 local _G = _G; 7 local _G = _G;
8 local prosody = _G.prosody; 8 local prosody = _G.prosody;
9 local st, uuid = require "util.stanza", require "util.uuid"; 9 local st = require "util.stanza";
10 local adhoc_new = module:require "adhoc".new; 10 local adhoc_new = module:require "adhoc".new;
11 11
12 function uptime() 12 function uptime()
13 local t = os.time()-prosody.start_time; 13 local t = os.time()-prosody.start_time;
14 local seconds = t%60; 14 local seconds = t%60;
21 return string.format("This server has been running for %d day%s, %d hour%s and %d minute%s (since %s)", 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 "", 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)); 23 minutes, (minutes ~= 1 and "s") or "", os.date("%c", prosody.start_time));
24 end 24 end
25 25
26 function uptime_command_handler (self, data, sessid) 26 function uptime_command_handler (self, data, state)
27 return { info = uptime(), status = "completed" }, uuid.generate(); 27 return { info = uptime(), status = "completed" };
28 end 28 end
29 29
30 local descriptor = adhoc_new("Get uptime", "uptime", uptime_command_handler); 30 local descriptor = adhoc_new("Get uptime", "uptime", uptime_command_handler);
31 31
32 module:add_item ("adhoc", descriptor); 32 module:add_item ("adhoc", descriptor);