Mastodon垃圾账户帖子删除脚本
大家好,我是无能。
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用户进行操作。
此外,请务必备份您的数据库和Mastodon。
使用wget或复制&粘贴脚本。
将路径更改为正在使用的Mastodon目录中包含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个@符号也会被删除。请通过更改判断条件来处理。