Comparison

mod_admin_notify/mod_admin_notify.lua @ 4238:e97c509fdbe3

mod_admin_notify: New module providing an API to notify host admins
author Matthew Wild <mwild1@gmail.com>
date Mon, 09 Nov 2020 16:53:13 +0000
child 4274:44e18454e1e0
comparison
equal deleted inserted replaced
4237:a0ab7be0538d 4238: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