dmails: factor out spam detector service.

This commit is contained in:
evazion
2019-08-23 18:59:28 -05:00
parent 7ab701c19a
commit 06ff249530
6 changed files with 79 additions and 14 deletions

View File

@@ -6,8 +6,6 @@ class Dmail < ApplicationRecord
AUTOBAN_WINDOW = 24.hours
AUTOBAN_DURATION = 3
include Rakismet::Model
validates_presence_of :title, :body, on: :create
validate :validate_sender_is_not_banned, on: :create
@@ -20,8 +18,6 @@ class Dmail < ApplicationRecord
after_create :update_recipient
after_commit :send_email, on: :create
rakismet_attrs author: proc { from.name }, author_email: proc { from.email }, content: proc { title + "\n\n" + body }, user_ip: proc { creator_ip_addr.to_s }
concerning :SpamMethods do
class_methods do
def is_spammer?(user)
@@ -41,9 +37,7 @@ class Dmail < ApplicationRecord
end
def spam?
return false if Danbooru.config.rakismet_key.blank?
return false if from.is_gold?
super()
SpamDetector.new(self).spam?
end
end