mod_admin_notify/mod_admin_notify.lua
changeset 4242 e97c509fdbe3
child 4278 44e18454e1e0
equal deleted inserted replaced
4241:a0ab7be0538d 4242:e97c509fdbe3
       
     1 local it = require "util.iterators";
       
     2 local jid = require "util.jid";
       
     3 local set = require "util.set";
       
     4 local st = require "util.stanza";
       
     5 
       
     6 local roles_store = module:open_store("roles", "map");
       
     7 local config_admins = module:get_option_inherited_set("admins") / jid.prep;
       
     8 
       
     9 local function append_host(username)
       
    10 	return username.."@"..module.host;
       
    11 end
       
    12 
       
    13 local function get_admins()
       
    14 	local role_admins = roles_store:get_all("prosody:admin") or {};
       
    15 	local admins = config_admins + (set.new(it.to_array(it.keys(role_admins))) / append_host);
       
    16 	return admins;
       
    17 end
       
    18 
       
    19 function notify(text) --luacheck: ignore 131/notify
       
    20 	local base_msg = st.message({ from = module.host })
       
    21 		:text_tag("body", text);
       
    22 	for admin_jid in get_admins() do
       
    23 		local msg = st.clone(base_msg);
       
    24 		msg.attr.to = admin_jid;
       
    25 		module:send(msg);
       
    26 	end
       
    27 end