discourse-ai/lib/ai_moderation/entry_point.rb
Sam fae2d5ff2c
FEATURE: link correctly to filters to assist in debugging spam (#1031)
- Add spam_score_type to AiSpamSerializer for better integration with reviewables.
- Introduce a custom filter for detecting AI spam false negatives in moderation workflows.
- Refactor spam report generation to improve identification of false negatives.
- Add tests to verify the custom filter and its behavior.
- Introduce links for all spam counts in report
2024-12-17 11:02:18 +11:00

37 lines
1.0 KiB
Ruby

# frozen_string_literal: true
module DiscourseAi
module AiModeration
class EntryPoint
def inject_into(plugin)
plugin.on(:post_created) { |post| SpamScanner.new_post(post) }
plugin.on(:post_edited) { |post| SpamScanner.edited_post(post) }
plugin.on(:post_process_cooked) { |_doc, post| SpamScanner.after_cooked_post(post) }
plugin.on(:site_setting_changed) do |name, _old_value, new_value|
SpamScanner.ensure_flagging_user! if name == :ai_spam_detection_enabled && new_value
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