diff options
author | Matthew Wild <mwild1@gmail.com> | 2010-06-11 13:29:15 +0100 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2010-06-11 13:29:15 +0100 |
commit | 3a3911c0173d043d81ecb13dc2930698e8b2e517 (patch) | |
tree | 7bf8dff7fea258bc5c7c660ffcf42d5489bc23d3 | |
parent | 3bc4f15db0c64106ad2c268a5f9601bc7033d6f0 (diff) | |
download | prosody-3a3911c0173d043d81ecb13dc2930698e8b2e517.tar.gz prosody-3a3911c0173d043d81ecb13dc2930698e8b2e517.zip |
mod_uptime: Add ad-hoc command
-rw-r--r-- | plugins/mod_uptime.lua | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/plugins/mod_uptime.lua b/plugins/mod_uptime.lua index 24d10180..c3860af6 100644 --- a/plugins/mod_uptime.lua +++ b/plugins/mod_uptime.lua @@ -11,6 +11,7 @@ local st = require "util.stanza"; local start_time = prosody.start_time; prosody.events.add_handler("server-started", function() start_time = prosody.start_time end); +-- XEP-0012: Last activity module:add_feature("jabber:iq:last"); module:hook("iq/host/jabber:iq:last:query", function(event) @@ -20,3 +21,28 @@ module:hook("iq/host/jabber:iq:last:query", function(event) return true; end end); + +-- Ad-hoc command +local adhoc_new = module:require "adhoc".new; + +function uptime_text() + local t = os.time()-prosody.start_time; + local seconds = t%60; + t = (t - seconds)/60; + local minutes = t%60; + t = (t - minutes)/60; + local hours = t%24; + t = (t - hours)/24; + local days = t; + return string.format("This server has been running for %d day%s, %d hour%s and %d minute%s (since %s)", + days, (days ~= 1 and "s") or "", hours, (hours ~= 1 and "s") or "", + minutes, (minutes ~= 1 and "s") or "", os.date("%c", prosody.start_time)); +end + +function uptime_command_handler (self, data, state) + return { info = uptime_text(), status = "completed" }; +end + +local descriptor = adhoc_new("Get uptime", "uptime", uptime_command_handler); + +module:add_item ("adhoc", descriptor); |