@@ -11,20 +11,17 @@ namespace TwitchStreamingTools.Tts.TtsFilter;
11
11
/// </summary>
12
12
public class WordSpamFilter : ITtsFilter {
13
13
/// <summary>
14
- /// The maximum number of emotes to allow.
14
+ /// The maximum number of duplicate letters to allow.
15
15
/// </summary>
16
+ /// <remarks>Very few words have a single letter repeated 3+ times in a row.</remarks>
16
17
private const int MAXIMUM_LETTER_OCCURANCES = 2 ;
17
18
18
19
/// <summary>
19
- /// The maximum number of emotes to allow .
20
+ /// The maximum number of consecutive words that are the same .
20
21
/// </summary>
22
+ /// <remarks>Very few sentences require the use of the same word more than twice in a row.</remarks>
21
23
private const int MAXIMUM_CONSECUTIVE_SAME_WORDS = 2 ;
22
24
23
- /// <summary>
24
- /// Replacement text so I know something was said that Cathy didn't like.
25
- /// </summary>
26
- private const string SPAM_REPLACEMENT = "I am a fucking moron that spams the chat" ;
27
-
28
25
/// <summary>
29
26
/// Removes duplicate emotes from a message.
30
27
/// </summary>
@@ -35,8 +32,8 @@ public class WordSpamFilter : ITtsFilter {
35
32
/// <returns>The new TTS message and username.</returns>
36
33
public Tuple < string , string > Filter ( IConfiguration configuration , OnMessageReceivedArgs twitchInfo , string username , string currentMessage ) {
37
34
// See if a letter is being spammed over and over again in a single word
38
- string [ ] parts = currentMessage . Split ( ' ' , StringSplitOptions . RemoveEmptyEntries | StringSplitOptions . TrimEntries ) ;
39
- for ( int i = 0 ; i < parts . Length ; i ++ ) {
35
+ List < string > parts = currentMessage . Split ( ' ' , StringSplitOptions . RemoveEmptyEntries | StringSplitOptions . TrimEntries ) . ToList ( ) ;
36
+ for ( int i = 0 ; i < parts . Count ; i ++ ) {
40
37
List < char > part = parts [ i ] . ToList ( ) ;
41
38
char previousLetter = ' ' ;
42
39
uint consecutiveLetterCount = 1 ;
@@ -62,12 +59,13 @@ public Tuple<string, string> Filter(IConfiguration configuration, OnMessageRecei
62
59
// Check the words in order and see if they spammed the same word more than once.
63
60
uint wordRun = 0 ;
64
61
string previous = string . Empty ;
65
- foreach ( string part in parts ) {
62
+ for ( int i = parts . Count - 1 ; i >= 0 ; i -- ) {
63
+ string part = parts [ i ] ;
66
64
if ( part . Equals ( previous ) ) {
67
65
++ wordRun ;
68
66
69
- if ( wordRun > MAXIMUM_CONSECUTIVE_SAME_WORDS ) {
70
- return new Tuple < string , string > ( username , SPAM_REPLACEMENT ) ;
67
+ if ( wordRun >= MAXIMUM_CONSECUTIVE_SAME_WORDS ) {
68
+ parts . RemoveAt ( i ) ;
71
69
}
72
70
}
73
71
else {
@@ -77,30 +75,6 @@ public Tuple<string, string> Filter(IConfiguration configuration, OnMessageRecei
77
75
previous = part ;
78
76
}
79
77
80
- //// Check for phrases that are repeated
81
- //var allEmotes = new List<string>();
82
- //allEmotes.AddRange(EmoteLookup.GetBetterTtvEmotes(twitchInfo.ChatMessage.Channel));
83
- //allEmotes.AddRange(EmoteLookup.GetFrankerzFaceEmotes(twitchInfo.ChatMessage.Channel));
84
-
85
- //foreach (var emote in allEmotes) {
86
- // currentMessage = currentMessage.Replace(emote, "");
87
- //}
88
-
89
- //for (int i = 0; i < parts.Length; i++) {
90
- // var startingWord = parts[i];
91
- // var currentPhrase = parts[i];
92
-
93
- // int x;
94
- // for (x = i; x < parts.Length; x++) {
95
- // var nextWord = parts[x];
96
- // if (startingWord.Equals(nextWord)) {
97
- // currentPhrase.Count()
98
- // }
99
-
100
- // currentPhrase += $" {nextWord}";
101
- // }
102
- //}
103
-
104
78
return new Tuple < string , string > ( username , string . Join ( " " , parts ) ) ;
105
79
}
106
80
}
0 commit comments