Mastodonのスパムアカウント投稿を削除するスクリプト – Delete spam account posts on Mastodon

こんにちは、無能です。

マストドンのスパムが酷いので削除スクリプトを置いておきます。

あくまでスパムユーザを削除するものではありません。投稿やすでに届いた通知を消すものです。
なお、使用に関する保証は出来ないので自己責任でお願い致します。

https://github.com/haturatu/mastodon-spam-remove/blob/master/spam_remove.rb

私の環境

Devuan + Mastodon 4.2.7 + Ruby 3.2.0

使い方

※安全の為にMastodonユーザにスイッチするか、sudo -u mastodonで作業するか、最後にchown mastodon:mastodn spam_remove.rbで所有者権限を常にMastodonユーザで作業を行ってください。
また、DBやMastodonのバックアップを忘れずに行ってください。

スクリプトをwgetまたはコピー&ペーストする。

以下を使っているマストドンのディレクトリにあるenvironmentがあるパスに変更する。

require_relative ‘/your/mastodon/live/config/environment

判定は以下だけで行っています。
現状でメンションの@メンションの数で判定しています。

def spam_detected?(message)
message.scan(/@/).size >= 5
end

保存して実行権限を与えます。

chmod +x spam_remove.rb

実行します。

./spam_remove.rb

投稿が多ければかなりの時間を要するので、気をつけてください。

正常に動作するのであればcrontab -eで定期的に実行させましょう。
rootユーザのcrontabの場合

0 */4 * * * sudo -u mastodon /your/which/ruby/path/shims/ruby /your/file/path/spam_block.rb

Mastodonユーザの場合

0 */4 * * * /your/which/ruby/path/shims/ruby /your/file/path/spam_block.rb

上記では4時間起きにスクリプトが実行されます。

投稿等に@マークが5個以上あるものが消されるので、過去の通常の投稿で@が5個である場合でも削除されます。判定条件を変更することで対処してください。


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.

コメントを残す

管理人が承認後コメントが公開されます。
の項目は必須項目となります。