Skip to content

Commit

Permalink
Add and adjust triggerwords, improve word seperation
Browse files Browse the repository at this point in the history
  • Loading branch information
hhvrc committed Sep 13, 2024
1 parent b463bab commit beb58a4
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions DiscordBot/Utils/ProfanityDetector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ public static class ProfanityDetector
{ "cock", 0.5f },
{ "crap", 0.3f },
{ "cum", 0.4f },
{ "damn", 0.3f },
{ "damn", 0.15f },
{ "micropython", 0.5f },
{ "piss", 0.3f },
{ "ass", 0.2f },
{ "wtf", 0.15f },
};

private static float CalculateWeight(float accumulated, float weight) => accumulated == 0 ? weight : MathF.Max(accumulated, weight) + 0.1f;
Expand All @@ -54,7 +55,7 @@ private static void GetContainedWordsCountAndWeight(ReadOnlySpan<char> lowerCase
}

private readonly record struct WordRange(int Start, int End);
private static readonly SearchValues<char> _whiteSpaceSearchValues = SearchValues.Create([' ', '\t', '\r', '\n']);
private static readonly SearchValues<char> _seperationValues = SearchValues.Create([' ', '\t', '\r', '\n', '?', '!', ',', '.']);
private static List<WordRange> GetWordRanges(ReadOnlySpan<char> span)
{
List<WordRange> wordRanges = [];
Expand All @@ -63,7 +64,7 @@ private static List<WordRange> GetWordRanges(ReadOnlySpan<char> span)
while (true)
{
// Find the next white space character
int index = span.IndexOfAny(_whiteSpaceSearchValues);
int index = span.IndexOfAny(_seperationValues);
if (index < 0)
{
// Add the remaining word range if the word is not empty
Expand Down

0 comments on commit beb58a4

Please sign in to comment.