diff --git a/KfChatDotNetBot/Commands/NoraCommand.cs b/KfChatDotNetBot/Commands/NoraCommand.cs index ca9d351..13981b8 100644 --- a/KfChatDotNetBot/Commands/NoraCommand.cs +++ b/KfChatDotNetBot/Commands/NoraCommand.cs @@ -110,33 +110,38 @@ public class NoraCommand : ICommand } // Step 1: Moderate the content - var moderationResult = await OpenAiModeration.ModerateContentAsync(userMessage); - - if (moderationResult == null) + var moderationEnabled = + (await SettingsProvider.GetValueAsync(BuiltIn.Keys.OpenAiModerationEnabled)).ToBoolean(); + if (moderationEnabled) { - Logger.Warn($"Moderation API failed for user {user.KfUsername}, blocking message as safety precaution"); - await botInstance.SendChatMessageAsync( - $"{user.FormatUsername()}, moderation service is currently unavailable. Please try again later.", - true, - autoDeleteAfter: TimeSpan.FromSeconds(15)); - return; - } + var moderationResult = await OpenAiModeration.ModerateContentAsync(userMessage); - if (OpenAiModeration.IsIllegalContent(moderationResult.Categories)) - { - Logger.Warn($"User {user.KfUsername} attempted to send illegal content via Nora command: {userMessage}"); - await botInstance.SendChatMessageAsync( - $"{user.FormatUsername()}, your message was blocked for containing illegal content.", - true, - autoDeleteAfter: TimeSpan.FromSeconds(15)); - return; - } + if (moderationResult == null) + { + Logger.Warn($"Moderation API failed for user {user.KfUsername}, blocking message as safety precaution"); + await botInstance.SendChatMessageAsync( + $"{user.FormatUsername()}, moderation service is currently unavailable. Please try again later.", + true, + autoDeleteAfter: TimeSpan.FromSeconds(15)); + return; + } - if (moderationResult.Flagged) - { - Logger.Info($"User {user.KfUsername} sent flagged but allowed content (profanity/offensive): {userMessage}"); - } + if (OpenAiModeration.IsIllegalContent(moderationResult.Categories)) + { + Logger.Warn($"User {user.KfUsername} attempted to send illegal content via Nora command: {userMessage}"); + await botInstance.SendChatMessageAsync( + $"{user.FormatUsername()}, your message was blocked for containing illegal content.", + true, + autoDeleteAfter: TimeSpan.FromSeconds(15)); + return; + } + if (moderationResult.Flagged) + { + Logger.Info($"User {user.KfUsername} sent flagged but allowed content (profanity/offensive): {userMessage}"); + } + } + // Step 2: Build conversation context and get Grok AI response var basePrompt = (await SettingsProvider.GetValueAsync(BuiltIn.Keys.GrokNoraPrompt)).Value; if (basePrompt == null) diff --git a/KfChatDotNetBot/Settings/BuiltIn.cs b/KfChatDotNetBot/Settings/BuiltIn.cs index b10fecb..441483e 100644 --- a/KfChatDotNetBot/Settings/BuiltIn.cs +++ b/KfChatDotNetBot/Settings/BuiltIn.cs @@ -557,6 +557,8 @@ public static class BuiltIn public static string ShuffleBmjUserId = "Shuffle.BmjUserId"; [BuiltInSetting("Bossman's current VIP level for reducing GraphQL hits", SettingValueType.Text, "SAPPHIRE_5")] public static string ShuffleBmjVipLevel = "Shuffle.BmjVipLevel"; + [BuiltInSetting("Whether OpenAI moderation is enabled", SettingValueType.Boolean, "false", BooleanRegex)] + public static string OpenAiModerationEnabled = "OpenAI.ModerationEnabled"; } }