view mod_filter_words/mod_filter_words.lua @ 5185:09d6bbd6c8a4

mod_http_oauth2: Fix treatment of 'redirect_uri' parameter in code flow It's optional and the one stored in the client registration should really be used instead. RFC 6749 says an URI provided as parameter MUST be validated against the stored one but does not say how. Given that the client needs their secret to proceed, it seems fine to leave this for later.
author Kim Alvefur <zash@zash.se>
date Thu, 02 Mar 2023 22:00:42 +0100
parents 677fc0203da0
children
line wrap: on
line source

local filters = require "util.filters";

local replacements = module:get_option("filter_words", {});

if not replacements then
	module:log("warn", "No 'filter_words' option set, filters inactive");
	return
end

function filter_stanza(stanza)
	if stanza.name == "message" then
		local body = stanza:get_child("body");
		if body then
			body[1] = body[1]:gsub("%a+", replacements);
		end
	end
	return stanza;
end

function filter_session(session)
	filters.add_filter(session, "stanzas/in", filter_stanza);
end

function module.load()
	if module.reloading then
		module:log("warn", "RELOADING!!!");
	end
	filters.add_filter_hook(filter_session);
end

function module.unload()
	filters.remove_filter_hook(filter_session);	
end