Mercurial > prosody-modules
comparison mod_list_inactive/mod_list_inactive.lua @ 1496:cccb151a4cc5
mod_list_inactive: Delay joining JIDs until they are used
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 26 Aug 2014 16:15:23 +0200 |
parents | 589991b148e8 |
children | d1836dfa4ae4 |
comparison
equal
deleted
inserted
replaced
1495:9a1b3f0d0939 | 1496:cccb151a4cc5 |
---|---|
1 -- Copyright (C) 2012-2013 Kim Alvefur | 1 -- Copyright (C) 2012-2013 Kim Alvefur |
2 | 2 |
3 local um = require "core.usermanager"; | 3 local um = require "core.usermanager"; |
4 local sm = require "core.storagemanager"; | 4 local sm = require "core.storagemanager"; |
5 local dm_load = require "util.datamanager".load; | 5 local dm_load = require "util.datamanager".load; |
6 local jid_join = require"util.jid".join; | |
6 | 7 |
7 local multipliers = { | 8 local multipliers = { |
8 d = 86400, -- day | 9 d = 86400, -- day |
9 w = 604800, -- week | 10 w = 604800, -- week |
10 m = 2629746, -- month | 11 m = 2629746, -- month |
21 local max_age, unit = assert(arg[2], "No time range given"):match("^(%d*)%s*([dwmy]?)"); | 22 local max_age, unit = assert(arg[2], "No time range given"):match("^(%d*)%s*([dwmy]?)"); |
22 max_age = os.time() - ( tonumber(max_age) or 1 ) * ( multipliers[unit] or 1 ); | 23 max_age = os.time() - ( tonumber(max_age) or 1 ) * ( multipliers[unit] or 1 ); |
23 for user in um.users(host) do | 24 for user in um.users(host) do |
24 local last_active = dm_load(user, host, "lastlog"); | 25 local last_active = dm_load(user, host, "lastlog"); |
25 last_active = last_active and last_active.timestamp or 0; | 26 last_active = last_active and last_active.timestamp or 0; |
26 local bare = user.."@"..host; | |
27 if last_active < max_age then | 27 if last_active < max_age then |
28 print(("user:delete%q"):format(bare)); | 28 print(("user:delete%q"):format(jid_join(user, host))); |
29 end | 29 end |
30 end | 30 end |
31 end | 31 end |
32 | 32 |