Skip to content

Commit

Permalink
Update MessageHandler.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
hhvrc authored Sep 13, 2024
1 parent 3b980b6 commit b463bab
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions DiscordBot/MessageHandler/MessageHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,27 @@ public async Task HandleMessageAsync(SocketMessage message)
{
if (message.Author.IsBot || string.IsNullOrEmpty(message.Content)) return;

bool isInBotChannel = message.Channel.Id == 1114123393567047730;

// Check if the message contains a swear word
if (ProfanityDetector.TryGetProfanityWeight(message.Content, out int count, out float weight))
{
float intensityPercent = weight * 100f;

// If the channel is a bot channel, respond with debug message
if (message.Channel.Id == 1114123393567047730)
{
await message.Channel.SendMessageAsync($"Profanity detected! {count} bad {(count > 1 ? "words" : "word")}, shocking at {intensityPercent:F0}%");
}

var authorDiscordId = message.Author.Id;

await using var scope = _serviceProvider.CreateAsyncScope();

// Verify user has opted in for profanity shocking
if (!await CheckUserProfanityShockingOptIn(scope, authorDiscordId))
{
// If the channel is a bot channel, respond with debug message
if (isInBotChannel) await message.Channel.SendMessageAsync("Profanity detected, but cant shock you, register and/or enable it");
return;
}

// If the channel is a bot channel, respond with debug message
if (isInBotChannel) await message.Channel.SendMessageAsync($"Profanity detected! {count} bad {(count > 1 ? "words" : "word")}, shocking at {intensityPercent:F0}%");

// Send reaction and trigger shock
await Task.WhenAll([
Expand Down

0 comments on commit b463bab

Please sign in to comment.