From cc476bce1af569ccd0af361bd9ef8bb67c53d728 Mon Sep 17 00:00:00 2001 From: takayamaki / fusagiko <24884114+takayamaki@users.noreply.github.com> Date: Mon, 19 Feb 2024 21:54:00 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=AA=E3=83=A2=E3=83=BC=E3=83=88=E3=82=A4?= =?UTF-8?q?=E3=83=B3=E3=82=B9=E3=82=BF=E3=83=B3=E3=82=B9=E3=81=8B=E3=82=89?= =?UTF-8?q?=E3=81=AE=E3=82=B9=E3=83=91=E3=83=A0=E3=81=A3=E3=81=BD=E3=81=84?= =?UTF-8?q?activity=E3=82=92=E7=84=A1=E8=A6=96=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Sho Kusano --- app/lib/activitypub/activity/create.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/lib/activitypub/activity/create.rb b/app/lib/activitypub/activity/create.rb index 73882e1348f2ab..40680ef4b7f29c 100644 --- a/app/lib/activitypub/activity/create.rb +++ b/app/lib/activitypub/activity/create.rb @@ -83,8 +83,15 @@ def process_status ApplicationRecord.transaction do @status = Status.create!(@params) attach_tags(@status) + + if seems_spam? + @status = nil + raise ActiveRecord::Rollback + end end + return if @status.nil? + resolve_thread(@status) fetch_replies(@status) distribute @@ -426,4 +433,14 @@ def increment_voters_count! poll.reload retry end + + SPAM_FILTER_MINIMUM_FOLLOWERS = ENV.fetch('SPAM_FILTER_MINIMUM_FOLLOWERS', 2).to_i + SPAM_FILTER_MINIMUM_CREATE_DAYS = ENV.fetch('SPAM_FILTER_MINIMUM_CREATE_DAYS', 2).to_i + SPAM_FILTER_MINIMUM_MENTIONS = ENV.fetch('SPAM_FILTER_MINIMUM_MENTIONS', 2).to_i + def seems_spam? + !@status.account.local? && + @status.account.followers_count <= SPAM_FILTER_MINIMUM_FOLLOWERS && + SPAM_FILTER_MINIMUM_CREATE_DAYS.day.ago <= @status.account.created_at && + SPAM_FILTER_MINIMUM_MENTIONS <= @mentions.count + end end