mirror of
https://github.com/barelyprofessional/KfChatDotNet.git
synced 2026-04-30 03:22:04 -04:00
Add the option to disable OpenAI moderation for Nora
This commit is contained in:
@@ -110,31 +110,36 @@ 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
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user