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:
@@ -4,6 +4,12 @@
|
||||
class SpamDetector
|
||||
include Rakismet::Model
|
||||
|
||||
# if a person receives more than 10 automatic spam reports within a 1 hour
|
||||
# window, automatically ban them forever.
|
||||
AUTOBAN_THRESHOLD = 10
|
||||
AUTOBAN_WINDOW = 1.hours
|
||||
AUTOBAN_DURATION = 999999
|
||||
|
||||
attr_accessor :record, :user, :user_ip, :content, :comment_type
|
||||
rakismet_attrs author: proc { user.name },
|
||||
author_email: proc { user.email },
|
||||
@@ -24,6 +30,23 @@ class SpamDetector
|
||||
false
|
||||
end
|
||||
|
||||
def self.is_spammer?(user)
|
||||
return false if user.is_gold?
|
||||
|
||||
automatic_reports = ModerationReport.where("created_at > ?", AUTOBAN_WINDOW.ago).where(creator: User.system)
|
||||
|
||||
dmail_reports = automatic_reports.where(model: Dmail.sent_by(user))
|
||||
comment_reports = automatic_reports.where(model: user.comments)
|
||||
forum_post_reports = automatic_reports.where(model: user.forum_posts)
|
||||
|
||||
report_count = dmail_reports.or(comment_reports).or(forum_post_reports).count
|
||||
report_count >= AUTOBAN_THRESHOLD
|
||||
end
|
||||
|
||||
def self.ban_spammer!(spammer)
|
||||
spammer.bans.create!(banner: User.system, reason: "Spambot.", duration: AUTOBAN_DURATION)
|
||||
end
|
||||
|
||||
def initialize(record, user_ip: nil)
|
||||
case record
|
||||
when Dmail
|
||||
|
||||
Reference in New Issue
Block a user