view mod_filter_words/mod_filter_words.lua @ 4491:35381608d323

mod_s2s_auth_dane: Fix traceback in DANE-TA check because unpack() moved It moved into the table package in Lua 5.2, error happens when compat is disabled or gone (ie 5.3+). This happened in DANE-TA, which is disabled by default.
author Kim Alvefur <zash@zash.se>
date Wed, 03 Mar 2021 11:51:39 +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