Skip to content

Commit

Permalink
Run all at once
Browse files Browse the repository at this point in the history
  • Loading branch information
hhvrc committed Sep 13, 2024
1 parent c406d3b commit 9e58f5e
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions DiscordBot/MessageHandler/MessageHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,23 @@ public async Task HandleMessageAsync(SocketMessage message)
// Check if the message contains a swear word
if (ProfanityDetector.TryGetProfanityWeight(message.Content, out int count, out float weight))
{
var intensity = (byte)(weight * 100f);
float intensityPercent = weight * 100f;

List<Task> tasks = [];

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

// Trigger the shock
await SendShock(message.Author.Id, intensityPercent);
tasks.Add(SendShock(message.Author.Id, intensityPercent));

// Add shock emoji on complete
await message.AddReactionAsync(new Emoji(""));
tasks.Add(message.AddReactionAsync(new Emoji("")));

await Task.WhenAll(tasks);
}
}
}

0 comments on commit 9e58f5e

Please sign in to comment.