Delete spam account posts on Mastodon
Hello, this is Munou.
Mastodon spam is severe, so I'm providing a deletion script.
This is not intended to delete spam users themselves. It is for deleting posts and notifications that have already arrived.
Please note that I cannot guarantee its use, so please use it at your own risk.
https://github.com/haturatu/mastodon-spam-remove/blob/master/spam_remove.rb
My environment
Devuan + Mastodon 4.2.7 + Ruby 3.2.0
How to use
* For safety, please switch to the Mastodon user, work with sudo -u mastodon, or finally, always perform operations with Mastodon user ownership by running chown mastodon:mastodn spam_remove.rb.
Also, don't forget to back up your DB and Mastodon.
Download the script using wget or copy & paste it.
Change the path to where environment is located in the Mastodon directory you are using.
require_relative '/your/mastodon/live/config/environment’
Detection is performed only by the following criteria.
Currently, it is determined by the number of @ mentions.
def spam_detected?(message)
message.scan(/@/).size >= 5
end
Save and grant execution permissions.
chmod +x spam_remove.rb
Execute it.
./spam_remove.rb
Be careful, as it may take a considerable amount of time if there are many posts.
If it operates correctly, let's schedule it to run periodically with crontab -e.
For root user's crontab:
0 */4 * * * sudo -u mastodon /your/which/ruby/path/shims/ruby /your/file/path/spam_block.rb
For Mastodon user:
0 */4 * * * /your/which/ruby/path/shims/ruby /your/file/path/spam_block.rb
In the above, the script will be executed every 4 hours.
Posts with 5 or more "@" marks will be deleted, even if they are regular past posts with 5 "@" marks. Please deal with this by changing the detection conditions.
AI Translate
For safety, please ensure that you switch to the Mastodon user or use sudo -u mastodon to perform the operation. Lastly, ensure that you always perform the operation with the ownership permissions set to the Mastodon user by running chown mastodon:mastodon spam_remove.rb. Also, remember to backup your DB and Mastodon before proceeding.
Fetch the script using wget or copy & paste it.
Change the path to the environment located in the Mastodon directory you are using.
require_relative '/your/mastodon/live/config/environment'
The detection is based solely on the number of mentions in a message.
def spam_detected?(message) message.scan(/@/).size >= 5 end
Save and grant execution permissions.
chmod +x spam_remove.rb
Execute the script.
./spam_remove.rb
Be cautious as it may take considerable time if there are many posts.
If it operates correctly, schedule it to run periodically with crontab -e.(root crontab)
0 */4 * * * sudo -u mastodon /your/which/ruby/path/shims/ruby /your/file/path/spam_block.rb
For mastodon user crontab
0 */4 * * * /your/which/ruby/path/shims/ruby /your/file/path/spam_block.rb
In the above example, the script will run every 4 hours.
Posts with five or more @ marks will be deleted, even if they are regular posts with five @ marks in the past. Adjust the detection criteria accordingly.