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
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)

View File

@@ -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";
}
}