plugins/rtbl_admin.lua

changeset 171
7362add76bcd
parent 168
1c2b8d10ceed
equal deleted inserted replaced
170:eae589a33624 171:7362add76bcd
4 4
5 function riddim.plugins.rtbl_admin(bot) 5 function riddim.plugins.rtbl_admin(bot)
6 bot.stream:add_plugin("pubsub"); 6 bot.stream:add_plugin("pubsub");
7 7
8 local config = bot.config.rtbl_admin; 8 local config = bot.config.rtbl_admin;
9 if not config then return; end
9 10
10 local permitted_affiliations = config.permitted_affiliations or { admin = true, owner = true }; 11 local permitted_affiliations = config.permitted_affiliations or { admin = true, owner = true };
11 12
12 bot:hook("commands/rtbl-add", function (command) 13 bot:hook("commands/rtbl-add", function (command)
13 if config.control_room ~= (command.room and command.room.jid) then 14 if config.control_room ~= (command.room and command.room.jid) then
14 return; 15 return;
15 elseif not permitted_affiliations[command.sender.affiliation] then 16 elseif not permitted_affiliations[command.sender.affiliation] then
16 return "You have insufficient permissions to use this command"; 17 return "You have insufficient permissions to use this command";
17 end 18 end
18 local reported_jid = command.param and jid.prep(command.param:match("^%S+")); 19
20 local reported_jid, comment = command.param:match("^(%S+)%s*(.*)$");
21 if not command.param or not reported_jid then
22 return "rtbl-add JID [spam|abuse] [COMMENT]";
23 end
24
25 reported_jid = jid.prep(reported_jid);
26 if not reported_jid then
27 return "Invalid JID";
28 end
29
30 -- <report xmlns="urn:xmpp:reporting:1" reason="urn:xmpp:reporting:abuse">
31 -- <text>OPTIONAL</text>
32 -- </report>
33 local report = verse.stanza("report", { xmlns = "urn:xmpp:reporting:1", reason = "urn:xmpp:reporting:abuse" });
34 if comment and comment ~= "" then
35 local tag = comment:lower():match("^%w+");
36 if tag == "spam" or tag == "abuse" then
37 report.attr.reason = "urn:xmpp:reporting:"..tag;
38 comment = comment:match("^%w+%s+(.+)$");
39 end
40 if comment then
41 report:tag("text"):text(comment):up();
42 end
43 end
44
19 local hash = sha256(reported_jid, true); 45 local hash = sha256(reported_jid, true);
20 bot.stream.pubsub(config.host, config.node):publish( 46 bot.stream.pubsub(config.host, config.node):publish(
21 hash, -- item id 47 hash, -- item id
22 nil, -- options (not implemented anyway) 48 nil, -- options (not implemented anyway)
23 -- <report xmlns="urn:xmpp:reporting:1" reason="urn:xmpp:reporting:abuse"/> 49 report,
24 verse.stanza("report", {
25 xmlns = "urn:xmpp:reporting:1";
26 reason = "urn:xmpp:reporting:abuse"; }),
27 function (success) -- callback 50 function (success) -- callback
28 if not success then 51 if not success then
29 command:reply("Failed to update RTBL"); 52 command:reply("Failed to update RTBL");
30 return; 53 return;
31 end 54 end

mercurial