Add the option to disable OpenAI moderation for Nora

This commit is contained in:
barelyprofessional
2026-03-05 21:58:24 -06:00
parent 8daaf3c304
commit 829443283f
2 changed files with 30 additions and 23 deletions

View File

@@ -110,33 +110,38 @@ public class NoraCommand : ICommand
} }
// Step 1: Moderate the content // Step 1: Moderate the content
var moderationResult = await OpenAiModeration.ModerateContentAsync(userMessage); var moderationEnabled =
(await SettingsProvider.GetValueAsync(BuiltIn.Keys.OpenAiModerationEnabled)).ToBoolean();
if (moderationResult == null) if (moderationEnabled)
{ {
Logger.Warn($"Moderation API failed for user {user.KfUsername}, blocking message as safety precaution"); var moderationResult = await OpenAiModeration.ModerateContentAsync(userMessage);
await botInstance.SendChatMessageAsync(
$"{user.FormatUsername()}, moderation service is currently unavailable. Please try again later.",
true,
autoDeleteAfter: TimeSpan.FromSeconds(15));
return;
}
if (OpenAiModeration.IsIllegalContent(moderationResult.Categories)) if (moderationResult == null)
{ {
Logger.Warn($"User {user.KfUsername} attempted to send illegal content via Nora command: {userMessage}"); Logger.Warn($"Moderation API failed for user {user.KfUsername}, blocking message as safety precaution");
await botInstance.SendChatMessageAsync( await botInstance.SendChatMessageAsync(
$"{user.FormatUsername()}, your message was blocked for containing illegal content.", $"{user.FormatUsername()}, moderation service is currently unavailable. Please try again later.",
true, true,
autoDeleteAfter: TimeSpan.FromSeconds(15)); autoDeleteAfter: TimeSpan.FromSeconds(15));
return; return;
} }
if (moderationResult.Flagged) if (OpenAiModeration.IsIllegalContent(moderationResult.Categories))
{ {
Logger.Info($"User {user.KfUsername} sent flagged but allowed content (profanity/offensive): {userMessage}"); 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 // Step 2: Build conversation context and get Grok AI response
var basePrompt = (await SettingsProvider.GetValueAsync(BuiltIn.Keys.GrokNoraPrompt)).Value; var basePrompt = (await SettingsProvider.GetValueAsync(BuiltIn.Keys.GrokNoraPrompt)).Value;
if (basePrompt == null) if (basePrompt == null)

View File

@@ -557,6 +557,8 @@ public static class BuiltIn
public static string ShuffleBmjUserId = "Shuffle.BmjUserId"; public static string ShuffleBmjUserId = "Shuffle.BmjUserId";
[BuiltInSetting("Bossman's current VIP level for reducing GraphQL hits", SettingValueType.Text, "SAPPHIRE_5")] [BuiltInSetting("Bossman's current VIP level for reducing GraphQL hits", SettingValueType.Text, "SAPPHIRE_5")]
public static string ShuffleBmjVipLevel = "Shuffle.BmjVipLevel"; public static string ShuffleBmjVipLevel = "Shuffle.BmjVipLevel";
[BuiltInSetting("Whether OpenAI moderation is enabled", SettingValueType.Boolean, "false", BooleanRegex)]
public static string OpenAiModerationEnabled = "OpenAI.ModerationEnabled";
} }
} }