For every Mastodon Admin, that wants to ban a big wave of users. (f. ex. spam wave).
Here a dump of commands for you.
Modify it for your need and execute in your DB
SELECT DISTINCT ON (a.domain, a.username) a.domain, a.username, s.uri, s.text, s.created_at, a.suspended_at
FROM statuses_tags t
JOIN statuses s on s.id = t.status_id
JOIN tags on t.tag_id = tags.id
JOIN public.accounts a on s.account_id = a.id
WHERE tags.display_name IN('as215935', '鈴木哲哉', '唐澤貴洋')
AND length(a.username) = 10
AND a.suspended_at is null
ORDER BY a.domain, a.username
DB_PORT=5432 RAILS_ENV=production bundle exec rails c
Define yourself the ban method:
def ban_csv(csv_data)
CSV.parse(csv_data, headers: true) do |row|
account_name = row['account']
domain_name = row['domain']
full_account = "#{account_name}@#{domain_name}"
puts "Suspending account: #{full_account}"
user_account = Account.find_by username: account_name, domain: domain_name
if user_account
if user_account.suspended?
puts "Account #{full_account} ist bereits suspendiert"
else
# Benutzer suspendieren, falls vorhanden
user_account.suspend!
puts "Account #{full_account} wurde erfolgreich suspendiert."
end
else
puts "Account #{full_account} wurde nicht gefunden."
end
end
end
Now grab the first two columns, build a list and suspend them
csv_data = <<ENO
domain,account
some.domain,vol9ktomk2
some.other.domain,wgcssayzhs
ENO
ban_csv csv_data
Quick nooby note: I'd prefer to directly parse from psql output, so I've changed the following:
Copy (spamquery) To '/tmp/spamusers.csv' With CSV DELIMITER ',' HEADER;
(this seems not to work in the mastodon postgres user directly, unless permissions are elevated)account_name = row['account']
->account_name = row['username']
csv_data = <<ENO ...
is skipped and replaced by:file = File.open("/tmp/spamusers.csv", "r")
ban_csv file
Other than that, thank you, thats quite some help. Need something like this for other federated services^^