summaryrefslogtreecommitdiff
path: root/spam_remove_dump.rb
diff options
context:
space:
mode:
authorhaturatu <haturatu>2024-02-19 22:26:43 +0900
committerhaturatu <haturatu>2024-02-19 22:26:43 +0900
commit498cd11c2347f038a6b6e3167ca5052c66a0f2f4 (patch)
treeef346a03810480d9901d4d1b973ab49843996354 /spam_remove_dump.rb
parent02f502942c5180e81d2b8ca2ab691c3bbd29d31c (diff)
spam id dump
Diffstat (limited to 'spam_remove_dump.rb')
-rw-r--r--spam_remove_dump.rb37
1 files changed, 37 insertions, 0 deletions
diff --git a/spam_remove_dump.rb b/spam_remove_dump.rb
new file mode 100644
index 0000000..d797d0a
--- /dev/null
+++ b/spam_remove_dump.rb
@@ -0,0 +1,37 @@
+#!/usr/bin/env ruby
+# RAILS_ENVを設定
+ENV['RAILS_ENV'] = 'production'
+# あなたのMastodonインストール先パス
+require_relative '/your/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|
+ # あなたのMastodonドメイン
+ your_domain = 'eyes4you.org'
+
+ 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
+