Skip to content

Commit

Permalink
Merge pull request #1942 from best-friends/reject-spammer-with-enviro…
Browse files Browse the repository at this point in the history
…nment

Make configurational with environment vars for Reject spammer
  • Loading branch information
rosylilly committed Feb 18, 2024
2 parents 145ad9d + 06c4308 commit 0addadf
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions app/lib/activitypub/activity/create.rb
Expand Up @@ -84,7 +84,6 @@ def process_status
@status = Status.create!(@params)
attach_tags(@status)

# Delete status on zero follower user and nearly created account with include some replies
if like_a_spam?
@status = nil
raise ActiveRecord::Rollback
Expand Down Expand Up @@ -435,12 +434,15 @@ def increment_voters_count!
retry
end

SPAM_FILTER_MINIMUM_FOLLOWERS = ENV.fetch('SPAM_FILTER_MINIMUM_FOLLOWERS', 0).to_i
SPAM_FILTER_MINIMUM_CREATE_DAYS = ENV.fetch('SPAM_FILTER_MINIMUM_CREATE_DAYS', 1).to_i
SPAM_FILTER_MINIMUM_MENTIONS = ENV.fetch('SPAM_FILTER_MINIMUM_MENTIONS', 1).to_i
def like_a_spam?
(
!@status.account.local? &&
@status.account.followers_count.zero? &&
@status.account.created_at > 1.day.ago &&
@mentions.count >= 2
@status.account.followers_count > SPAM_FILTER_MINIMUM_FOLLOWERS &&
@status.account.created_at > SPAM_FILTER_MINIMUM_CREATE_DAYS.day.ago &&
@mentions.count > SPAM_FILTER_MINIMUM_MENTIONS
)
end
end

0 comments on commit 0addadf

Please sign in to comment.