Mon, 06 Dec 2021 11:27:16 +0000
rtbl_admin: Notify subscribers on item removal (requires verse 98dc1750584d)
165 | 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"; | |
166
95b668d73ff9
rtbl_admin: Fix reason string (abuse is defined to be the most generic)
Matthew Wild <mwild1@gmail.com>
parents:
165
diff
changeset
|
19 | reason = "urn:xmpp:reporting:abuse"; }), |
165 | 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 | |
167
2073137bc943
rtbl_admin: Notify subscribers on item removal (requires verse 98dc1750584d)
Matthew Wild <mwild1@gmail.com>
parents:
166
diff
changeset
|
35 | true, -- notify subscribers |
165 | 36 | function (success) -- callback |
37 | if not success then | |
38 | command:reply("Failed to update RTBL"); | |
39 | return; | |
40 | end | |
41 | command:reply("RTBL entry removed"); | |
42 | end | |
43 | ); | |
44 | end); | |
45 | end |