comparison mod_filter_words/mod_filter_words.lua @ 2273:677fc0203da0

mod_filter_words: Very basic module in its early stages, to filter words in messages
author Matthew Wild <mwild1@gmail.com>
date Thu, 18 Aug 2016 10:25:29 +0100
parents
children
comparison
equal deleted inserted replaced
2272:65d9093525ca 2273:677fc0203da0
1 local filters = require "util.filters";
2
3 local replacements = module:get_option("filter_words", {});
4
5 if not replacements then
6 module:log("warn", "No 'filter_words' option set, filters inactive");
7 return
8 end
9
10 function filter_stanza(stanza)
11 if stanza.name == "message" then
12 local body = stanza:get_child("body");
13 if body then
14 body[1] = body[1]:gsub("%a+", replacements);
15 end
16 end
17 return stanza;
18 end
19
20 function filter_session(session)
21 filters.add_filter(session, "stanzas/in", filter_stanza);
22 end
23
24 function module.load()
25 if module.reloading then
26 module:log("warn", "RELOADING!!!");
27 end
28 filters.add_filter_hook(filter_session);
29 end
30
31 function module.unload()
32 filters.remove_filter_hook(filter_session);
33 end