# HG changeset patch # User Kim Alvefur # Date 1409062531 -7200 # Node ID d1836dfa4ae4d2456a267f197b5fef95d69c7005 # Parent cccb151a4cc58388b6cac0d1e6c2e3d7e73cd04c mod_list_inactive: Add different output formats diff -r cccb151a4cc5 -r d1836dfa4ae4 mod_list_inactive/mod_list_inactive.lua --- 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