view mod_filter_words/mod_filter_words.lua @ 3099:c88f91626e07

mod_pastebin: Off-by-one, the hardest problem known to man The threshold set to 4 allowed 4 lines and pastebinned 5. 040eaa3844f4 unintentionally changed this so that 4 lines were pastebinned. This commit restores the previous behavior.
author Kim Alvefur <zash@zash.se>
date Sun, 03 Jun 2018 14:09:30 +0200
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