Fix #4125: Detect forum and comment spam.

This commit is contained in:
evazion
2019-08-23 22:07:04 -05:00
parent 06ff249530
commit a9b0362fc7
5 changed files with 107 additions and 6 deletions

View File

@@ -2,6 +2,7 @@ class Comment < ApplicationRecord
include Mentionable
validate :validate_creator_is_not_limited, :on => :create
validate :validate_comment_is_not_spam, on: :create
validates_presence_of :body, :message => "has no content"
belongs_to :post
belongs_to_creator
@@ -124,6 +125,10 @@ class Comment < ApplicationRecord
end
end
def validate_comment_is_not_spam
errors[:base] << "Failed to create comment" if SpamDetector.new(self).spam?
end
def update_last_commented_at_on_create
Post.where(:id => post_id).update_all(:last_commented_at => created_at)
if Comment.where("post_id = ?", post_id).count <= Danbooru.config.comment_threshold && !do_not_bump_post?