# HG changeset patch # User Matthew Wild # Date 1678882289 0 # Node ID 7362add76bcd61b548a521e0f4e885592c6a080a # Parent eae589a33624f8fec52cc3b439c18e74aca3efeb rtbl_admin: Allow reason and text annotations when adding/updated an entry diff -r eae589a33624 -r 7362add76bcd plugins/rtbl_admin.lua --- a/plugins/rtbl_admin.lua Wed Mar 15 12:11:01 2023 +0000 +++ b/plugins/rtbl_admin.lua Wed Mar 15 12:11:29 2023 +0000 @@ -6,6 +6,7 @@ bot.stream:add_plugin("pubsub"); local config = bot.config.rtbl_admin; + if not config then return; end local permitted_affiliations = config.permitted_affiliations or { admin = true, owner = true }; @@ -15,15 +16,37 @@ elseif not permitted_affiliations[command.sender.affiliation] then return "You have insufficient permissions to use this command"; end - local reported_jid = command.param and jid.prep(command.param:match("^%S+")); + + local reported_jid, comment = command.param:match("^(%S+)%s*(.*)$"); + if not command.param or not reported_jid then + return "rtbl-add JID [spam|abuse] [COMMENT]"; + end + + reported_jid = jid.prep(reported_jid); + if not reported_jid then + return "Invalid JID"; + end + + -- + -- OPTIONAL + -- + local report = verse.stanza("report", { xmlns = "urn:xmpp:reporting:1", reason = "urn:xmpp:reporting:abuse" }); + if comment and comment ~= "" then + local tag = comment:lower():match("^%w+"); + if tag == "spam" or tag == "abuse" then + report.attr.reason = "urn:xmpp:reporting:"..tag; + comment = comment:match("^%w+%s+(.+)$"); + end + if comment then + report:tag("text"):text(comment):up(); + end + end + 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:abuse"; }), + report, function (success) -- callback if not success then command:reply("Failed to update RTBL");