Skip to content

Commit

Permalink
Reject spammer
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirishima21 committed Feb 23, 2024
1 parent bfa88c8 commit b8aa535
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions app/lib/activitypub/activity/create.rb
Expand Up @@ -85,8 +85,16 @@ def process_status
ApplicationRecord.transaction do
@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
end
end

return if @status.nil?

resolve_thread(@status)
fetch_replies(@status)
distribute
Expand Down Expand Up @@ -429,4 +437,17 @@ def increment_voters_count!
poll.reload
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?
(

Check failure on line 445 in app/lib/activitypub/activity/create.rb

View workflow job for this annotation

GitHub Actions / lint

[Correctable] Style/RedundantParentheses: Don't use parentheses around a logical expression.
!@status.account.local? &&
@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

Check failure on line 452 in app/lib/activitypub/activity/create.rb

View workflow job for this annotation

GitHub Actions / lint

[Correctable] Layout/EmptyLinesAroundClassBody: Extra empty line detected at class body end. (https://rubystyle.guide#empty-lines-around-bodies)
end

0 comments on commit b8aa535

Please sign in to comment.