mod_watch_spam_reports/mod_watch_spam_reports.lua
author Kim Alvefur <zash@zash.se>
Sat, 17 Jun 2023 16:26:33 +0200
changeset 5555 8bfcedd93a72
parent 5026 97d34d520cfa
permissions -rw-r--r--
mod_rest: List all error conditions in OpenAPI spec These are not handled by datamanager but by util.stanza and util.error, so they are not represented in the JSON schema file.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4055
91e2e510e17c mod_watch_spam_reports: Show reporters bare JID instead of full JID
Martin Dosch <martin@mdosch.de>
parents: 4050
diff changeset
     1
local jid = require "util.jid";
4667
6e5572fc6840 mod_watch_spam_reports: Support for fetching admins from authz provider
Matthew Wild <mwild1@gmail.com>
parents: 4661
diff changeset
     2
local set = require "util.set";
4050
d518f97dad6f mod_watch_spam_reports: Module to notify admins about incoming XEP-0377 spam reports
Martin Dosch <martin@mdosch.de>
parents:
diff changeset
     3
local st = require "util.stanza";
4667
6e5572fc6840 mod_watch_spam_reports: Support for fetching admins from authz provider
Matthew Wild <mwild1@gmail.com>
parents: 4661
diff changeset
     4
local usermanager = require "core.usermanager";
4050
d518f97dad6f mod_watch_spam_reports: Module to notify admins about incoming XEP-0377 spam reports
Martin Dosch <martin@mdosch.de>
parents:
diff changeset
     5
local host = module.host;
d518f97dad6f mod_watch_spam_reports: Module to notify admins about incoming XEP-0377 spam reports
Martin Dosch <martin@mdosch.de>
parents:
diff changeset
     6
4667
6e5572fc6840 mod_watch_spam_reports: Support for fetching admins from authz provider
Matthew Wild <mwild1@gmail.com>
parents: 4661
diff changeset
     7
local admins;
6e5572fc6840 mod_watch_spam_reports: Support for fetching admins from authz provider
Matthew Wild <mwild1@gmail.com>
parents: 4661
diff changeset
     8
if usermanager.get_jids_with_role then
5026
97d34d520cfa mod_watch_spam_reports: Fix traceback due to misplaced parenthesis (thanks Menel)
Kim Alvefur <zash@zash.se>
parents: 4667
diff changeset
     9
	admins = set.new(usermanager.get_jids_with_role("prosody:admin", host));
4667
6e5572fc6840 mod_watch_spam_reports: Support for fetching admins from authz provider
Matthew Wild <mwild1@gmail.com>
parents: 4661
diff changeset
    10
else -- COMPAT w/pre-0.12
6e5572fc6840 mod_watch_spam_reports: Support for fetching admins from authz provider
Matthew Wild <mwild1@gmail.com>
parents: 4661
diff changeset
    11
	admins = module:get_option_inherited_set("admins");
6e5572fc6840 mod_watch_spam_reports: Support for fetching admins from authz provider
Matthew Wild <mwild1@gmail.com>
parents: 4661
diff changeset
    12
end
6e5572fc6840 mod_watch_spam_reports: Support for fetching admins from authz provider
Matthew Wild <mwild1@gmail.com>
parents: 4661
diff changeset
    13
4050
d518f97dad6f mod_watch_spam_reports: Module to notify admins about incoming XEP-0377 spam reports
Martin Dosch <martin@mdosch.de>
parents:
diff changeset
    14
module:depends("spam_reporting")
d518f97dad6f mod_watch_spam_reports: Module to notify admins about incoming XEP-0377 spam reports
Martin Dosch <martin@mdosch.de>
parents:
diff changeset
    15
d518f97dad6f mod_watch_spam_reports: Module to notify admins about incoming XEP-0377 spam reports
Martin Dosch <martin@mdosch.de>
parents:
diff changeset
    16
module:hook("spam_reporting/spam-report", function(event)
4065
9745a623c7ed mod_watch_spam_reports: Define variable prior to using it
Martin Dosch <martin@mdosch.de>
parents: 4058
diff changeset
    17
	local reporter_bare_jid = jid.bare(event.stanza.attr.from)
4661
78ef5d9e2361 mod_watch_spam_reports: Prepare for changing 'reason' to an optional value
Kim Alvefur <zash@zash.se>
parents: 4615
diff changeset
    18
	local report = reporter_bare_jid.." reported spam from "..event.jid..": "..(event.reason or "no reason given")
4050
d518f97dad6f mod_watch_spam_reports: Module to notify admins about incoming XEP-0377 spam reports
Martin Dosch <martin@mdosch.de>
parents:
diff changeset
    19
	for admin_jid in admins
d518f97dad6f mod_watch_spam_reports: Module to notify admins about incoming XEP-0377 spam reports
Martin Dosch <martin@mdosch.de>
parents:
diff changeset
    20
		do
d518f97dad6f mod_watch_spam_reports: Module to notify admins about incoming XEP-0377 spam reports
Martin Dosch <martin@mdosch.de>
parents:
diff changeset
    21
			module:send(st.message({from=host,
d518f97dad6f mod_watch_spam_reports: Module to notify admins about incoming XEP-0377 spam reports
Martin Dosch <martin@mdosch.de>
parents:
diff changeset
    22
			type="chat",to=admin_jid},
4065
9745a623c7ed mod_watch_spam_reports: Define variable prior to using it
Martin Dosch <martin@mdosch.de>
parents: 4058
diff changeset
    23
			report));
4050
d518f97dad6f mod_watch_spam_reports: Module to notify admins about incoming XEP-0377 spam reports
Martin Dosch <martin@mdosch.de>
parents:
diff changeset
    24
		end
d518f97dad6f mod_watch_spam_reports: Module to notify admins about incoming XEP-0377 spam reports
Martin Dosch <martin@mdosch.de>
parents:
diff changeset
    25
end)
4615
7a9e1c81c63e mod_watch_spam_reports: Support spam_reporting/abuse-report
Martin Dosch <martin@mdosch.de>
parents: 4065
diff changeset
    26
7a9e1c81c63e mod_watch_spam_reports: Support spam_reporting/abuse-report
Martin Dosch <martin@mdosch.de>
parents: 4065
diff changeset
    27
module:hook("spam_reporting/abuse-report", function(event)
7a9e1c81c63e mod_watch_spam_reports: Support spam_reporting/abuse-report
Martin Dosch <martin@mdosch.de>
parents: 4065
diff changeset
    28
	local reporter_bare_jid = jid.bare(event.stanza.attr.from)
4661
78ef5d9e2361 mod_watch_spam_reports: Prepare for changing 'reason' to an optional value
Kim Alvefur <zash@zash.se>
parents: 4615
diff changeset
    29
	local report = reporter_bare_jid.." reported abuse from "..event.jid..": "..(event.reason or "no reason given")
4615
7a9e1c81c63e mod_watch_spam_reports: Support spam_reporting/abuse-report
Martin Dosch <martin@mdosch.de>
parents: 4065
diff changeset
    30
	for admin_jid in admins
7a9e1c81c63e mod_watch_spam_reports: Support spam_reporting/abuse-report
Martin Dosch <martin@mdosch.de>
parents: 4065
diff changeset
    31
		do
7a9e1c81c63e mod_watch_spam_reports: Support spam_reporting/abuse-report
Martin Dosch <martin@mdosch.de>
parents: 4065
diff changeset
    32
			module:send(st.message({from=host,
7a9e1c81c63e mod_watch_spam_reports: Support spam_reporting/abuse-report
Martin Dosch <martin@mdosch.de>
parents: 4065
diff changeset
    33
			type="chat",to=admin_jid},
7a9e1c81c63e mod_watch_spam_reports: Support spam_reporting/abuse-report
Martin Dosch <martin@mdosch.de>
parents: 4065
diff changeset
    34
			report));
7a9e1c81c63e mod_watch_spam_reports: Support spam_reporting/abuse-report
Martin Dosch <martin@mdosch.de>
parents: 4065
diff changeset
    35
		end
7a9e1c81c63e mod_watch_spam_reports: Support spam_reporting/abuse-report
Martin Dosch <martin@mdosch.de>
parents: 4065
diff changeset
    36
end)