diff options
Diffstat (limited to 'rmspam')
-rw-r--r-- | rmspam/delid.rb | 25 | ||||
-rw-r--r-- | rmspam/rmspam.sh | 19 | ||||
-rw-r--r-- | rmspam/spam_block.rb | 33 |
3 files changed, 77 insertions, 0 deletions
diff --git a/rmspam/delid.rb b/rmspam/delid.rb new file mode 100644 index 0000000..cba42a9 --- /dev/null +++ b/rmspam/delid.rb @@ -0,0 +1,25 @@ +#!/usr/bin/env ruby +# RAILS_ENVを設定 +ENV['RAILS_ENV'] = 'production' +require_relative '/your/dir/mastodon/config/environment' + +# ユーザーIDによってアカウントを削除するメソッド +def delete_account_by_id(mastodon_id) + # Mastodon IDからユーザー名を抽出 + username = mastodon_id.split('@')[0].delete('@') + account = Account.find_by(username: username) + if account + account.delete + puts "IDが#{mastodon_id}のアカウントを削除しました" + else + puts "IDが#{mastodon_id}のアカウントが見つかりませんでした" + end +end + +# ユーザーIDの書かれたファイルを読み込む +file_path = 'tmp.txt' +File.readlines(file_path).each do |line| + mastodon_id = line.strip + delete_account_by_id(mastodon_id) +end + diff --git a/rmspam/rmspam.sh b/rmspam/rmspam.sh new file mode 100644 index 0000000..8c7ba7e --- /dev/null +++ b/rmspam/rmspam.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +# Mastodonユーザで実行してください +# rmspamディレクトリのフォルダの所有権限をmastodon:mastodonに変更してください +# spam_block.rbの17行目も変更してください +# delid.rbの4行目を変更してください。 + +# あなたのフォルダとドメインに変更 +execdir=/your/dir/rmspam +your_domain= + +echo "$your_domain" +$execdir/spam_block.rb +grep "$your_domain" spam.txt > delid.txt +sed -i "s/($your_domain)//g" delid.txt +sort delid.txt | uniq > tmp.txt +$execdir/delid.rb + +rm delid.txt spam.txt tmp.txt # SPAM IDのテキストファイルを残すならこの行をコメントアウトする 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 + |