comparison mod_report_tracker/mod_report_tracker.lua @ 6036:765e0235c202

mod_report_tracker: Add trait for reported accounts, for mod_report_affiliations
author Matthew Wild <mwild1@gmail.com>
date Mon, 25 Nov 2024 14:06:16 +0000
parents b04518fa0987
children
comparison
equal deleted inserted replaced
6035:b04518fa0987 6036:765e0235c202
1 local um = require "core.usermanager"; 1 local um = require "core.usermanager";
2 local cache = require "util.cache";
2 local jid = require "util.jid"; 3 local jid = require "util.jid";
3
4 local trusted_reporters = module:get_option_inherited_set("trusted_reporters", {}); 4 local trusted_reporters = module:get_option_inherited_set("trusted_reporters", {});
5 5
6 local reports_received = module:open_store("reports_received"); 6 local reports_received = module:open_store("reports_received");
7 7
8 local xmlns_reporting = "urn:xmpp:reporting:1"; 8 local xmlns_reporting = "urn:xmpp:reporting:1";
9
10 local reported_users = cache.new(256);
9 11
10 local function is_trusted_reporter(reporter_jid) 12 local function is_trusted_reporter(reporter_jid)
11 return trusted_reporters:contains(reporter_jid); 13 return trusted_reporters:contains(reporter_jid);
12 end 14 end
13 15
52 current_reports.last = os.time(); 54 current_reports.last = os.time();
53 current_reports.count = current_reports.count + 1; 55 current_reports.count = current_reports.count + 1;
54 end 56 end
55 57
56 reports_received:set(reported_user, reporter_jid, current_reports); 58 reports_received:set(reported_user, reporter_jid, current_reports);
59 reported_users:set(reported_user, true);
57 60
58 module:log("info", "Received abuse report about <%s> from <%s>", reported_jid, reporter_jid); 61 module:log("info", "Received abuse report about <%s> from <%s>", reported_jid, reporter_jid);
59 62
60 module:fire_event(module.name.."/account-reported", { 63 module:fire_event(module.name.."/account-reported", {
61 report_from = reporter_jid; 64 report_from = reporter_jid;
69 -- Message was handled 72 -- Message was handled
70 return true; 73 return true;
71 end 74 end
72 75
73 module:hook("message/host", handle_report); 76 module:hook("message/host", handle_report);
77
78 module:add_item("account-trait", {
79 name = "reported-by-trusted-server";
80 prob_bad_true = 0.80;
81 prob_bad_false = 0.50;
82 });
83
84 module:hook("get-account-traits", function (event)
85 local username = event.username;
86 local reported = reported_users:get(username);
87 if reported == nil then
88 -- Check storage, update cache
89 reported = not not reports_received:get(username);
90 reported_users:set(username, reported);
91 end
92 event.traits["reported-by-trusted-server"] = reported;
93 end);