From 6cb8a96336f904d4e0cadb74b2b597e0b55c535f Mon Sep 17 00:00:00 2001 From: Aleteoryx Date: Sat, 23 Nov 2024 14:51:36 -0500 Subject: [PATCH] marginally better moderation tooling --- bin/rmrepo.tcl | 46 ++++++++++++++++++++++++++++++++++++++++++++++ main.tcl | 3 ++- src/jetstream.tcl | 3 +++ 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100755 bin/rmrepo.tcl diff --git a/bin/rmrepo.tcl b/bin/rmrepo.tcl new file mode 100755 index 0000000..b32006b --- /dev/null +++ b/bin/rmrepo.tcl @@ -0,0 +1,46 @@ +#!/bin/env tclsh + +if {$argc < 2} { return -code error "Usage: bin/rmrepo.tcl DB ?-pds PDS? ?-feed FEED? REPO ?REPO ...?\n-feed may be passed repeatedly." } + +cd [file dirname [file dirname [dict get [info frame [info frame]] file]]] + +package require sqlite3 +package require json +package require http +package require tls +::http::register https 443 ::tls::socket + +set repos [lassign $argv db] +sqlite3 db $db + +set pds "bsky.social" +if {[lindex $repos 0] == "-pds"} { + set repos [lassign $repos _ pds] +} +while {[lindex $repos 0] == "-feed"} { + set repos [lassign $repos _ feed] + lappend feeds $feed +} + +if ![info exists feeds] { + set feeds [db eval {SELECT name FROM sqlite_master WHERE type = 'table' AND sql LIKE '%uri TEXT%'}] +} + +foreach repo $repos { + switch -regexp -- $repo { + {^did:plc:.+} {} + default { + set endpoint "https://$pds/xrpc/com.atproto.repo.describeRepo" + + set http_state [http::geturl "$endpoint?repo=$repo"] + if {[::http::ncode $http_state] != 200} { return -code error "couldn't resolve handle $repo!\n[::http::data $http_state]" } + set repo [dict get [::json::json2dict [::http::data $http_state]] did] + } + } + + db eval {INSERT OR IGNORE INTO blocked_repos VALUES (:repo);} + set repo_pat "%${repo}%" + foreach table $feeds { + db eval "DELETE FROM $table WHERE uri LIKE :repo_pat;" + } +} diff --git a/main.tcl b/main.tcl index 5c45c12..848a775 100755 --- a/main.tcl +++ b/main.tcl @@ -26,7 +26,8 @@ ${log}::info "tclfeed v0.0.1" ### DB STUFF ### sqlite3 db [::ini::value $config database path] -foreach algo $::algos::list { +db eval {CREATE TABLE IF NOT EXISTS blocked_repos (repo TEXT NOT NULL PRIMARY KEY);} +foreach algo [concat $::algos::list] { db eval {SELECT count(*) as n FROM sqlite_master WHERE name=$algo;} values { if ![set values(n)] { ${log}::info "Creating table \"$algo\"!" diff --git a/src/jetstream.tcl b/src/jetstream.tcl index c85df00..3d116a5 100644 --- a/src/jetstream.tcl +++ b/src/jetstream.tcl @@ -22,6 +22,9 @@ namespace eval ::jetstream { set data [json::json2dict $data] if {[dict get $data kind] != "commit"} return + set did [dict get $data did] + if [db eval {SELECT count(*) FROM blocked_repos WHERE repo = :did}] return + set uri at://[dict get $data did]/[dict get $data commit collection]/[dict get $data commit rkey] switch -- [dict get $data commit operation] { -- 2.45.2