# HG changeset patch # User Matthew Wild # Date 1471512329 -3600 # Node ID 677fc0203da036e20885c6f6f136f7331bb5a4fa # Parent 65d9093525ca006151464cdf34cb230f082e427c mod_filter_words: Very basic module in its early stages, to filter words in messages diff -r 65d9093525ca -r 677fc0203da0 mod_filter_words/mod_filter_words.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mod_filter_words/mod_filter_words.lua Thu Aug 18 10:25:29 2016 +0100 @@ -0,0 +1,33 @@ +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