Skip to content

Commit 511a60b

Browse files
Merge pull request #84 from nullinside-development-group/feat/spam
feat: fixing up duplicate word filter
2 parents a6335dd + 5bbdda9 commit 511a60b

File tree

3 files changed

+18
-44
lines changed

3 files changed

+18
-44
lines changed

src/TwitchStreamingTools/IConfiguration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public interface IConfiguration {
4646
SoundStretchArgs? SoundStretchArgs { get; set; }
4747

4848
/// <summary>
49-
/// True if "username says message" should be used as the template for TTS messages, false to read just the message.
49+
/// True if "username says message" should be used as the template for TTS messages, false to read just the message.
5050
/// </summary>
5151
bool SayUsernameWithMessage { get; set; }
5252

src/TwitchStreamingTools/Tts/TtsFilter/WordSpamFilter.cs

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,17 @@ namespace TwitchStreamingTools.Tts.TtsFilter;
1111
/// </summary>
1212
public class WordSpamFilter : ITtsFilter {
1313
/// <summary>
14-
/// The maximum number of emotes to allow.
14+
/// The maximum number of duplicate letters to allow.
1515
/// </summary>
16+
/// <remarks>Very few words have a single letter repeated 3+ times in a row.</remarks>
1617
private const int MAXIMUM_LETTER_OCCURANCES = 2;
1718

1819
/// <summary>
19-
/// The maximum number of emotes to allow.
20+
/// The maximum number of consecutive words that are the same.
2021
/// </summary>
22+
/// <remarks>Very few sentences require the use of the same word more than twice in a row.</remarks>
2123
private const int MAXIMUM_CONSECUTIVE_SAME_WORDS = 2;
2224

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-
2825
/// <summary>
2926
/// Removes duplicate emotes from a message.
3027
/// </summary>
@@ -35,8 +32,8 @@ public class WordSpamFilter : ITtsFilter {
3532
/// <returns>The new TTS message and username.</returns>
3633
public Tuple<string, string> Filter(IConfiguration configuration, OnMessageReceivedArgs twitchInfo, string username, string currentMessage) {
3734
// 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++) {
4037
List<char> part = parts[i].ToList();
4138
char previousLetter = ' ';
4239
uint consecutiveLetterCount = 1;
@@ -62,12 +59,13 @@ public Tuple<string, string> Filter(IConfiguration configuration, OnMessageRecei
6259
// Check the words in order and see if they spammed the same word more than once.
6360
uint wordRun = 0;
6461
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];
6664
if (part.Equals(previous)) {
6765
++wordRun;
6866

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);
7169
}
7270
}
7371
else {
@@ -77,30 +75,6 @@ public Tuple<string, string> Filter(IConfiguration configuration, OnMessageRecei
7775
previous = part;
7876
}
7977

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-
10478
return new Tuple<string, string>(username, string.Join(" ", parts));
10579
}
10680
}

src/TwitchStreamingTools/Views/MainWindow.axaml.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
using System;
2+
using System.Linq;
3+
using System.Threading.Tasks;
4+
5+
using Avalonia.Controls;
6+
7+
using Nullinside.Api.Common.Desktop;
18
#if !DEBUG
29
using Microsoft.Extensions.DependencyInjection;
310

@@ -7,13 +14,6 @@
714
#else
815
using Avalonia;
916
#endif
10-
using System;
11-
using System.Linq;
12-
using System.Threading.Tasks;
13-
14-
using Avalonia.Controls;
15-
16-
using Nullinside.Api.Common.Desktop;
1717

1818
namespace TwitchStreamingTools.Views;
1919

0 commit comments

Comments
 (0)