mirror of
https://github.com/discourse/discourse-ai.git
synced 2025-04-26 17:14:54 +00:00
When spam scanner is enabled and code is reloaded, developer experience this error: ``` NameError at /posts =================== uninitialized constant DiscourseAi::AiModeration::EntryPoint::SpamScanner > To access an interactive console with this error, point your browser to: /__better_errors plugins/discourse-ai/lib/ai_moderation/entry_point.rb, line 7 ``` It is because when we call `SpamScanner` it is searched within parent `DiscourseAi::AiModeration::EntryPoint` namespace. We can help a bit Zeitwerk by calling SpamScanner more explicitly.
43 lines
1.2 KiB
Ruby
43 lines
1.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module DiscourseAi
|
|
module AiModeration
|
|
class EntryPoint
|
|
def inject_into(plugin)
|
|
plugin.on(:post_created) { |post| ::DiscourseAi::AiModeration::SpamScanner.new_post(post) }
|
|
plugin.on(:post_edited) do |post|
|
|
::DiscourseAi::AiModeration::SpamScanner.edited_post(post)
|
|
end
|
|
plugin.on(:post_process_cooked) do |_doc, post|
|
|
::DiscourseAi::AiModeration::SpamScanner.after_cooked_post(post)
|
|
end
|
|
|
|
plugin.on(:site_setting_changed) do |name, _old_value, new_value|
|
|
if name == :ai_spam_detection_enabled && new_value
|
|
::DiscourseAi::AiModeration::SpamScanner.ensure_flagging_user!
|
|
end
|
|
end
|
|
|
|
custom_filter = [
|
|
:ai_spam_false_negative,
|
|
Proc.new do |results, value|
|
|
if value
|
|
results.where(<<~SQL)
|
|
EXISTS (
|
|
SELECT 1 FROM ai_spam_logs
|
|
WHERE NOT is_spam
|
|
AND post_id = target_id AND target_type = 'Post'
|
|
)
|
|
SQL
|
|
else
|
|
results
|
|
end
|
|
end,
|
|
]
|
|
|
|
Reviewable.add_custom_filter(custom_filter)
|
|
end
|
|
end
|
|
end
|
|
end
|