diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index eaa0bfcc..4a71b0db 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -56,6 +56,8 @@ en: ai_nsfw_flag_threshold_sexy: "Threshold for an image classified as sexy to be considered NSFW." ai_nsfw_models: "Models to use for NSFW inference." + ai_spam_detection_enabled: "Enable the AI spam detection module" + ai_openai_api_key: "API key for OpenAI API. ONLY used for Image creation and edits. For GPT use the LLM config tab" ai_openai_image_generation_url: "URL for OpenAI image generation API" ai_openai_image_edit_url: "URL for OpenAI image edit API" @@ -275,6 +277,7 @@ en: invalid_error_type: "Invalid error type provided" unexpected: "An unexpected error occured" bot_user_update_failed: "Failed to update the spam scanning bot user" + configuration_missing: "The AI spam detection configuration is missing. Add configuration in the 'Admin > Plugins > Discourse AI > Spam' before enabling." ai_bot: reply_error: "Sorry, it looks like our system encountered an unexpected issue while trying to reply.\n\n[details='Error details']\n%{details}\n[/details]" diff --git a/config/settings.yml b/config/settings.yml index c2b62d59..0dde98de 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -374,7 +374,7 @@ discourse_ai: ai_spam_detection_enabled: default: false - hidden: true + validator: "DiscourseAi::Configuration::SpamDetectionValidator" ai_spam_detection_user_id: default: "" hidden: true diff --git a/lib/configuration/spam_detection_validator.rb b/lib/configuration/spam_detection_validator.rb new file mode 100644 index 00000000..4201dcc4 --- /dev/null +++ b/lib/configuration/spam_detection_validator.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +module DiscourseAi + module Configuration + class SpamDetectionValidator + def initialize(opts = {}) + @opts = opts + end + + def valid_value?(val) + return true if Rails.env.test? + return true if AiModerationSetting.spam + + false + end + + def error_message + I18n.t("discourse_ai.spam_detection.configuration_missing") + end + end + end +end