From 1a743ad0a140bbe67620aefd54f83bb3a427bc38 Mon Sep 17 00:00:00 2001 From: Aleteoryx Date: Sat, 23 Nov 2024 03:31:17 -0500 Subject: [PATCH] improved moderation tools --- bin/rmpost.tcl | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/bin/rmpost.tcl b/bin/rmpost.tcl index 7ea0130..869fef6 100755 --- a/bin/rmpost.tcl +++ b/bin/rmpost.tcl @@ -1,20 +1,32 @@ #!/bin/env tclsh -lassign $argv db feed uri +if {$argc < 3} { return -code error "Usage: bin/rmpost.tcl DB FEED URI ?URI ...?" } +set uris [lassign $argv db feed] cd [file dirname [file dirname [dict get [info frame [info frame]] file]]] -switch -regexp -matchvar matches -- $uri { - {^at://.+} {} - {^(?:(?:(?:(?:(?:https://)?bsky.app)?/)?profile)?/)?([^/]+)/post/(.+)$} { - lassign $matches pub mkey - set uri at://$pub/app.bsky.feed.post/$mkey - } - default {return -code error "unknown URI format!"} -} - package require sqlite3 +package require json +package require http +package require tls +::http::register https 443 ::tls::socket sqlite3 db $db -db eval "DELETE FROM $feed WHERE uri = :uri;" +foreach uri $uris { + switch -regexp -matchvar matches -- $uri { + {^at://.+} {} + {^(?:(?:(?:(?:(?:https://)?bsky.app)?/)?profile)?/)?([^/]+)/post/(.+)$} { + lassign $matches _ pub rkey + + set endpoint {https://public.api.bsky.app/xrpc/com.atproto.repo.getRecord} + + set http_state [http::geturl "$endpoint?repo=$pub&collection=app.bsky.feed.post&rkey=$rkey"] + if {[::http::ncode $http_state] != 200} { return -code error "couldn't resolve bsky.app URI!\n[::http::data $http_state]" } + set uri [dict get [::json::json2dict [::http::data $http_state]] uri] + } + default { return -code error "unknown URI format!" } + } + + db eval "DELETE FROM $feed WHERE uri = :uri;" +} -- 2.45.2