annotate mod_list_inactive/mod_list_inactive.lua @ 1446:843769eb40c3

mod_profile: Don't include photo in vCard4 version (use XEP-0084 instead)
author Kim Alvefur <zash@zash.se>
date Wed, 25 Jun 2014 20:45:01 +0200
parents 589991b148e8
children cccb151a4cc5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1267
589991b148e8 mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 -- Copyright (C) 2012-2013 Kim Alvefur
589991b148e8 mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2
589991b148e8 mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3 local um = require "core.usermanager";
589991b148e8 mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4 local sm = require "core.storagemanager";
589991b148e8 mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5 local dm_load = require "util.datamanager".load;
589991b148e8 mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6
589991b148e8 mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7 local multipliers = {
589991b148e8 mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8 d = 86400, -- day
589991b148e8 mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9 w = 604800, -- week
589991b148e8 mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10 m = 2629746, -- month
589991b148e8 mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11 y = 31556952, -- year
589991b148e8 mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 }
589991b148e8 mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13
589991b148e8 mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14 function module.command(arg)
589991b148e8 mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15 local items = {};
589991b148e8 mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16 local host = arg[1];
589991b148e8 mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17 assert(hosts[host], "Host "..tostring(host).." does not exist");
589991b148e8 mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 sm.initialize_host(host);
589991b148e8 mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19 um.initialize_host(host);
589991b148e8 mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20
589991b148e8 mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21 local max_age, unit = assert(arg[2], "No time range given"):match("^(%d*)%s*([dwmy]?)");
589991b148e8 mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 max_age = os.time() - ( tonumber(max_age) or 1 ) * ( multipliers[unit] or 1 );
589991b148e8 mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 for user in um.users(host) do
589991b148e8 mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24 local last_active = dm_load(user, host, "lastlog");
589991b148e8 mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25 last_active = last_active and last_active.timestamp or 0;
589991b148e8 mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 local bare = user.."@"..host;
589991b148e8 mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27 if last_active < max_age then
589991b148e8 mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28 print(("user:delete%q"):format(bare));
589991b148e8 mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff changeset
29 end
589991b148e8 mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff changeset
30 end
589991b148e8 mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31 end
589991b148e8 mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff changeset
32