# HG changeset patch # User Matthew Wild # Date 1638729339 0 # Node ID ec0567256b11c937da380cd28e9b076fca25f2d9 # Parent 69b508f132b59353668035949801f73d93c86fd7 Add rtbl_admin plugin diff -r 69b508f132b5 -r ec0567256b11 plugins/rtbl_admin.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/rtbl_admin.lua Sun Dec 05 18:35:39 2021 +0000 @@ -0,0 +1,44 @@ +local verse = require "verse"; +local jid = require "util.jid"; +local sha256 = require "util.hashes".sha256; + +function riddim.plugins.rtbl_admin(bot) + bot.stream:add_plugin("pubsub"); + + local config = bot.config.rtbl_admin; + + bot:hook("commands/rtbl-add", function (command) + local reported_jid = command.param and jid.prep(command.param:match("^%S+")); + local hash = sha256(reported_jid, true); + bot.stream.pubsub(config.host, config.node):publish( + hash, -- item id + nil, -- options (not implemented anyway) + -- + verse.stanza("report", { + xmlns = "urn:xmpp:reporting:1"; + reason = "urn:xmpp:reporting:spam"; }), + function (success) -- callback + if not success then + command:reply("Failed to update RTBL"); + return; + end + command:reply("RTBL entry added"); + end + ); + end); + + bot:hook("commands/rtbl-remove", function (command) + local reported_jid = command.param and jid.prep(command.param:match("^%S+")); + local hash = sha256(reported_jid, true); + bot.stream.pubsub(config.host, config.node):retract( + hash, -- item id + function (success) -- callback + if not success then + command:reply("Failed to update RTBL"); + return; + end + command:reply("RTBL entry removed"); + end + ); + end); +end diff -r 69b508f132b5 -r ec0567256b11 squishy --- a/squishy Sun Dec 05 18:35:18 2021 +0000 +++ b/squishy Sun Dec 05 18:35:39 2021 +0000 @@ -18,6 +18,7 @@ "msgforward", "opdown", "pubsub2room", + "rtbl_admin", "simple_commands", "slap", "topic",