view mod_admin_notify/mod_admin_notify.lua @ 4709:679f1834dbdb

mod_delegation: update to XEP-0355 v0.5 - namespace bump to "urn:xmpp:delegation:2" - disco remaining infos now uses the XEP defined "urn:xmpp:delegation:2:bare:disco#info:*" namespace - complemeted disco remaining infos implementation for requests made on nodes not already managed by the server - bare JID disco items now uses the XEP defined "urn:xmpp:delegation:2:bare:disco#items:*'" namespace
author Goffi <goffi@goffi.org>
date Fri, 15 Oct 2021 15:10:36 +0200
parents 44e18454e1e0
children
line wrap: on
line source

local it = require "util.iterators";
local jid = require "util.jid";
local set = require "util.set";
local st = require "util.stanza";

local roles_store = module:open_store("roles", "map");
local config_admins = module:get_option_inherited_set("admins", {}) / jid.prep;

local function append_host(username)
	return username.."@"..module.host;
end

local function get_admins()
	local role_admins = roles_store:get_all("prosody:admin") or {};
	local admins = config_admins + (set.new(it.to_array(it.keys(role_admins))) / append_host);
	return admins;
end

function notify(text) --luacheck: ignore 131/notify
	local base_msg = st.message({ from = module.host })
		:text_tag("body", text);
	for admin_jid in get_admins() do
		local msg = st.clone(base_msg);
		msg.attr.to = admin_jid;
		module:send(msg);
	end
end