Mercurial > prosody-modules
changeset 1497:d1836dfa4ae4
mod_list_inactive: Add different output formats
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 26 Aug 2014 16:15:31 +0200 (2014-08-26) |
parents | cccb151a4cc5 |
children | e82592ed744b |
files | mod_list_inactive/mod_list_inactive.lua |
diffstat | 1 files changed, 11 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/mod_list_inactive/mod_list_inactive.lua Tue Aug 26 16:15:23 2014 +0200 +++ b/mod_list_inactive/mod_list_inactive.lua Tue Aug 26 16:15:31 2014 +0200 @@ -12,6 +12,12 @@ y = 31556952, -- year } +local output_formats = { + default = "%s", + event = "%s %s", + delete = "user:delete%q -- %s" +} + function module.command(arg) local items = {}; local host = arg[1]; @@ -21,11 +27,15 @@ local max_age, unit = assert(arg[2], "No time range given"):match("^(%d*)%s*([dwmy]?)"); max_age = os.time() - ( tonumber(max_age) or 1 ) * ( multipliers[unit] or 1 ); + + local output = assert(output_formats[arg[3] or "default"], "No such output format: "..tostring(arg[3] or "default")); + for user in um.users(host) do local last_active = dm_load(user, host, "lastlog"); + local last_action = last_active and last_active.event or "?" last_active = last_active and last_active.timestamp or 0; if last_active < max_age then - print(("user:delete%q"):format(jid_join(user, host))); + print(output:format(jid_join(user, host), last_action)); end end end