|
1 local verse = require "verse"; |
|
2 local jid = require "util.jid"; |
|
3 local sha256 = require "util.hashes".sha256; |
|
4 |
|
5 function riddim.plugins.rtbl_admin(bot) |
|
6 bot.stream:add_plugin("pubsub"); |
|
7 |
|
8 local config = bot.config.rtbl_admin; |
|
9 |
|
10 bot:hook("commands/rtbl-add", function (command) |
|
11 local reported_jid = command.param and jid.prep(command.param:match("^%S+")); |
|
12 local hash = sha256(reported_jid, true); |
|
13 bot.stream.pubsub(config.host, config.node):publish( |
|
14 hash, -- item id |
|
15 nil, -- options (not implemented anyway) |
|
16 -- <report xmlns="urn:xmpp:reporting:1" reason="urn:xmpp:reporting:abuse"/> |
|
17 verse.stanza("report", { |
|
18 xmlns = "urn:xmpp:reporting:1"; |
|
19 reason = "urn:xmpp:reporting:spam"; }), |
|
20 function (success) -- callback |
|
21 if not success then |
|
22 command:reply("Failed to update RTBL"); |
|
23 return; |
|
24 end |
|
25 command:reply("RTBL entry added"); |
|
26 end |
|
27 ); |
|
28 end); |
|
29 |
|
30 bot:hook("commands/rtbl-remove", function (command) |
|
31 local reported_jid = command.param and jid.prep(command.param:match("^%S+")); |
|
32 local hash = sha256(reported_jid, true); |
|
33 bot.stream.pubsub(config.host, config.node):retract( |
|
34 hash, -- item id |
|
35 function (success) -- callback |
|
36 if not success then |
|
37 command:reply("Failed to update RTBL"); |
|
38 return; |
|
39 end |
|
40 command:reply("RTBL entry removed"); |
|
41 end |
|
42 ); |
|
43 end); |
|
44 end |