Mercurial > prosody-modules
annotate mod_filter_words/mod_filter_words.lua @ 4327:beb3342f1137
mod_cloud_notify_encrypted: New module for Encrypted Push Notifications
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Tue, 12 Jan 2021 15:43:26 +0000 |
parents | 677fc0203da0 |
children |
rev | line source |
---|---|
2273
677fc0203da0
mod_filter_words: Very basic module in its early stages, to filter words in messages
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 local filters = require "util.filters"; |
677fc0203da0
mod_filter_words: Very basic module in its early stages, to filter words in messages
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 |
677fc0203da0
mod_filter_words: Very basic module in its early stages, to filter words in messages
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 local replacements = module:get_option("filter_words", {}); |
677fc0203da0
mod_filter_words: Very basic module in its early stages, to filter words in messages
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 |
677fc0203da0
mod_filter_words: Very basic module in its early stages, to filter words in messages
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 if not replacements then |
677fc0203da0
mod_filter_words: Very basic module in its early stages, to filter words in messages
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 module:log("warn", "No 'filter_words' option set, filters inactive"); |
677fc0203da0
mod_filter_words: Very basic module in its early stages, to filter words in messages
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 return |
677fc0203da0
mod_filter_words: Very basic module in its early stages, to filter words in messages
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 end |
677fc0203da0
mod_filter_words: Very basic module in its early stages, to filter words in messages
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 |
677fc0203da0
mod_filter_words: Very basic module in its early stages, to filter words in messages
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 function filter_stanza(stanza) |
677fc0203da0
mod_filter_words: Very basic module in its early stages, to filter words in messages
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 if stanza.name == "message" then |
677fc0203da0
mod_filter_words: Very basic module in its early stages, to filter words in messages
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 local body = stanza:get_child("body"); |
677fc0203da0
mod_filter_words: Very basic module in its early stages, to filter words in messages
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 if body then |
677fc0203da0
mod_filter_words: Very basic module in its early stages, to filter words in messages
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 body[1] = body[1]:gsub("%a+", replacements); |
677fc0203da0
mod_filter_words: Very basic module in its early stages, to filter words in messages
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 end |
677fc0203da0
mod_filter_words: Very basic module in its early stages, to filter words in messages
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 end |
677fc0203da0
mod_filter_words: Very basic module in its early stages, to filter words in messages
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 return stanza; |
677fc0203da0
mod_filter_words: Very basic module in its early stages, to filter words in messages
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 end |
677fc0203da0
mod_filter_words: Very basic module in its early stages, to filter words in messages
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 |
677fc0203da0
mod_filter_words: Very basic module in its early stages, to filter words in messages
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 function filter_session(session) |
677fc0203da0
mod_filter_words: Very basic module in its early stages, to filter words in messages
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 filters.add_filter(session, "stanzas/in", filter_stanza); |
677fc0203da0
mod_filter_words: Very basic module in its early stages, to filter words in messages
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 end |
677fc0203da0
mod_filter_words: Very basic module in its early stages, to filter words in messages
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 |
677fc0203da0
mod_filter_words: Very basic module in its early stages, to filter words in messages
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 function module.load() |
677fc0203da0
mod_filter_words: Very basic module in its early stages, to filter words in messages
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 if module.reloading then |
677fc0203da0
mod_filter_words: Very basic module in its early stages, to filter words in messages
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 module:log("warn", "RELOADING!!!"); |
677fc0203da0
mod_filter_words: Very basic module in its early stages, to filter words in messages
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 end |
677fc0203da0
mod_filter_words: Very basic module in its early stages, to filter words in messages
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 filters.add_filter_hook(filter_session); |
677fc0203da0
mod_filter_words: Very basic module in its early stages, to filter words in messages
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 end |
677fc0203da0
mod_filter_words: Very basic module in its early stages, to filter words in messages
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 |
677fc0203da0
mod_filter_words: Very basic module in its early stages, to filter words in messages
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 function module.unload() |
677fc0203da0
mod_filter_words: Very basic module in its early stages, to filter words in messages
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 filters.remove_filter_hook(filter_session); |
677fc0203da0
mod_filter_words: Very basic module in its early stages, to filter words in messages
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 end |