diff options
author | haturatu <haturatu> | 2024-02-20 00:44:03 +0900 |
---|---|---|
committer | haturatu <haturatu> | 2024-02-20 00:44:03 +0900 |
commit | c6e85b79cb5d6b1f98c480d918ccfff3f4636e70 (patch) | |
tree | e1a939e06eaa5e167718ac980755b1a875e139e4 /rmspam/spam_block.rb | |
parent | 498cd11c2347f038a6b6e3167ca5052c66a0f2f4 (diff) |
spam account removemaster
Diffstat (limited to 'rmspam/spam_block.rb')
-rw-r--r-- | rmspam/spam_block.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/rmspam/spam_block.rb b/rmspam/spam_block.rb new file mode 100644 index 0000000..e60f64a --- /dev/null +++ b/rmspam/spam_block.rb @@ -0,0 +1,33 @@ +# RAILS_ENVを設定 +ENV['RAILS_ENV'] = 'production' +require_relative '/home/sns/mastodon/config/environment' + +require 'uri' + +# メッセージ内に@マークが5個以上あるかをチェックするメソッド +def spam_detected?(message) + message.scan(/@/).size >= 5 +end + + +def block_spam_messages + spam_accounts = [] + # 全ての投稿を取得 + Status.all.each do |status| + your_domain = 'eyes4you.org' # your_domain + if spam_detected?(status.content) + status.destroy + if status.account.url + domain = URI.parse(status.account.url).host + spam_accounts << "#{status.account.username} (#{domain})" + else + spam_accounts << "#{status.account.username} (#{your_domain})" + end + end + end + # スパムと判定されたアカウントをファイルに出力 + File.open('spam.txt', 'a') { |file| file.puts(spam_accounts) } unless spam_accounts.empty? +end + +block_spam_messages + |