Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit af986be

Browse files
committed
start building scanning infra
1 parent 071f635 commit af986be

File tree

5 files changed

+47
-3
lines changed

5 files changed

+47
-3
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# frozen_string_literal: true
2+
class AddAiSpamLogs < ActiveRecord::Migration[7.2]
3+
def change
4+
create_table :ai_spam_logs do |t|
5+
t.bigint :post_id, null: false
6+
t.bigint :llm_model_id, null: false
7+
t.bigint :last_ai_api_audit_log_id, null: false
8+
t.integer :scan_count, null: false, default: 1
9+
t.boolean :is_spam, null: false
10+
end
11+
end
12+
end

lib/ai_moderation/entry_point.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# frozen_string_literal: true
2+
3+
module DiscourseAi
4+
module AiModeration
5+
class EntryPoint
6+
def inject_into(plugin)
7+
plugin.on(:post_created) do |post|
8+
SpamScanner.new_post(post)
9+
end
10+
11+
plugin.on(:post_edited) do |post|
12+
SpamScanner.edited_post(post)
13+
end
14+
end
15+
end
16+
end
17+
end

lib/ai_moderation/spam_scanner.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module DiscourseAi
2+
module AiModeration
3+
class SpamScanner
4+
def self.new_post(post)
5+
return if !enabled?
6+
end
7+
8+
def self.edited_post(post)
9+
return if !enabled?
10+
end
11+
12+
def self.enabled?
13+
SiteSetting.ai_spam_detection_enabled && SiteSetting.discourse_ai_enabled
14+
end
15+
end
16+
end
17+
end

plugin.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def self.public_asset_path(name)
7272
DiscourseAi::AiHelper::EntryPoint.new,
7373
DiscourseAi::Summarization::EntryPoint.new,
7474
DiscourseAi::AiBot::EntryPoint.new,
75+
DiscourseAi::AiModeration::EntryPoint.new,
7576
].each { |a_module| a_module.inject_into(self) }
7677

7778
register_reviewable_type ReviewableAiChatMessage

spec/requests/admin/ai_spam_controller_spec.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
context "when logged in as admin" do
1313
before { sign_in(admin) }
1414

15-
it "allows properly for partial updates" do
16-
end
17-
1815
it "can update settings from scratch" do
1916
put "/admin/plugins/discourse-ai/ai-spam.json",
2017
params: {

0 commit comments

Comments
 (0)