mod reports: autoreport spam and autoban spammers.

* Automatically generate a mod report when a comment, forum post, or
  dmail is detected as spam.
* Automatically ban users that receive too many automatic spam reports
  within a short window of time.
* Automatically mark spam dmails as deleted.
* Change ban threshold from 10 spam reports in 24 hours to 10 reports in 1 hour.
* Change ban length from 3 days to forever.
This commit is contained in:
evazion
2020-02-03 04:12:03 -06:00
parent 170a0e8a48
commit bb2022abed
7 changed files with 89 additions and 78 deletions

View File

@@ -7,6 +7,7 @@ class ModerationReport < ApplicationRecord
validates :creator, uniqueness: { scope: [:model_type, :model_id], message: "have already reported this message." }
after_create :create_forum_post!
after_create :autoban_reported_user
scope :user, -> { where(model_type: "User") }
scope :dmail, -> { where(model_type: "Dmail") }
@@ -54,6 +55,23 @@ class ModerationReport < ApplicationRecord
updater.update(forum_post_message)
end
def autoban_reported_user
if SpamDetector.is_spammer?(reported_user)
SpamDetector.ban_spammer!(reported_user)
end
end
def reported_user
case model
when Comment, ForumPost
model.creator
when Dmail
model.from
else
raise NotImplementedError
end
end
def self.visible(user = CurrentUser.user)
user.is_moderator? ? all : none
end