2023-02-23 09:08:34 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-03-14 15:03:50 -04:00
|
|
|
module DiscourseAi
|
2023-02-23 09:08:34 -05:00
|
|
|
module NSFW
|
|
|
|
class EntryPoint
|
2023-02-23 13:50:10 -05:00
|
|
|
def load_files
|
2023-02-24 11:25:02 -05:00
|
|
|
require_relative "nsfw_classification"
|
2023-02-24 05:53:43 -05:00
|
|
|
require_relative "jobs/regular/evaluate_post_uploads"
|
2023-02-23 13:50:10 -05:00
|
|
|
end
|
2023-02-23 09:08:34 -05:00
|
|
|
|
2023-02-23 13:50:10 -05:00
|
|
|
def inject_into(plugin)
|
2023-02-24 05:53:43 -05:00
|
|
|
nsfw_detection_cb =
|
|
|
|
Proc.new do |post|
|
2023-02-24 11:25:02 -05:00
|
|
|
if SiteSetting.ai_nsfw_detection_enabled &&
|
2023-03-14 15:03:50 -04:00
|
|
|
DiscourseAi::NSFW::NSFWClassification.new.can_classify?(post)
|
2023-02-24 05:53:43 -05:00
|
|
|
Jobs.enqueue(:evaluate_post_uploads, post_id: post.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
plugin.on(:post_created, &nsfw_detection_cb)
|
|
|
|
plugin.on(:post_edited, &nsfw_detection_cb)
|
2023-02-23 09:08:34 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|