Last active
February 14, 2022 09:43
-
-
Save jhass/9104029 to your computer and use it in GitHub Desktop.
Deletes spam comments, posts and local spam accounts. Place into Diasporas root, edit and run. Don't forget to set necessary environment variables.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# List of spam accounts | |
spam_accounts = %w(spamacc@podA spamacc@podB spamacc@mypod) | |
# Delete comments even if spammer isn't a local user or spam isn't on a | |
# local users account. | |
# And delete posts of users in spam_accounts that aren't local. | |
always_delete = true | |
# Keep empty (%w() or []) to retract spam comments from remote accounts | |
# for all local users | |
retract_for = %w(userA userB) | |
########################################################################### | |
# Load diaspora environment | |
ENV['RAILS_ENV'] ||= "production" | |
require_relative 'config/environment' | |
local_spammers, remote_spammers = Person.where(diaspora_handle: spam_accounts).partition(&:local?) | |
# Retract all comments of local spammers and close their accounts | |
local_spammers.each do |spammer| | |
Comment.where(author_id: spammer.id).each do |comment| | |
spammer.owner.retract(comment) | |
end | |
spammer.owner.close_account! | |
end | |
# Retract all spam comments on posts of local users and delete the rest | |
Comment.where(author_id: remote_spammers.map(&:id)).each do |comment| | |
post_author = comment.parent.author | |
if post_author.local? && (retract_for.include?(post_author.owner.username) || retract_for.empty?) | |
post_author.owner.retract(comment) | |
elsif always_delete | |
comment.destroy | |
end | |
end | |
# Destroy posts of remote users if wanted | |
if always_delete | |
Post.where(author_id: remote_spammers.map(&:id)).each(&:destroy) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The first step towards stopping my pod forever had to be disabling registrations. In the last few years I have got no observable help from anyone, this script is barely qualifying as useful and the spambots are pretty lively. There seem to be no admin-approval option, no antispam measures, hooks, whatever, and everything is slow as hell. Not providing real antispam support just doesn't cut it.
Nevertheless, here's my after-the-fact script, which calls this code above with the modification of
spam_accounts = ARGV[0]
or I often replace the SQL above with
to kill accounts older than a week and logged in only once.