Skip to content

Commit e571e8c

Browse files
Merge pull request #66 from nullinside-development-group/feature/Streamboo
feat: New streamboo spam
2 parents 4b832cc + 832d325 commit e571e8c

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using Moq;
2+
3+
using Nullinside.Api.Common.Twitch;
4+
using Nullinside.Api.TwitchBot.ChatRules;
5+
using Nullinside.Api.TwitchBot.Model;
6+
7+
namespace Nullinside.Api.TwitchBot.Tests.ChatRules;
8+
9+
/// <summary>
10+
/// Tests the <see cref="Streamboo" /> class.
11+
/// </summary>
12+
public class StreambooTests : AChatRuleUnitTestBase<Dogehype> {
13+
/// <summary>
14+
/// Tests the strings typed in chats.
15+
/// </summary>
16+
/// <param name="badString">The string that should fail.</param>
17+
[Test]
18+
[TestCase("streamboo .com ( remove the space ) @anohXiot")]
19+
[TestCase("streamboo .com ( remove the space ) @C2apJWT9")]
20+
[TestCase("streamboo .com ( remove the space ) @NpFQHupB")]
21+
[TestCase("streamboo .com ( remove the space ) @tGYF1O11")]
22+
public async Task TestKnownStrings(string badString) {
23+
var rule = new Streamboo();
24+
var botProxy = new Mock<ITwitchApiProxy>();
25+
var chat = new TwitchChatMessage(true, badString, "123", "456");
26+
27+
// Process the message and assert that we fail the message.
28+
bool result = await rule.Handle("123", botProxy.Object, chat, _db);
29+
Assert.That(result, Is.False);
30+
}
31+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using Nullinside.Api.Common.Twitch;
2+
using Nullinside.Api.Model;
3+
using Nullinside.Api.TwitchBot.Model;
4+
5+
using TwitchLib.Client.Models;
6+
7+
using TwitchUserConfig = Nullinside.Api.Model.Ddl.TwitchUserConfig;
8+
9+
namespace Nullinside.Api.TwitchBot.ChatRules;
10+
11+
/// <summary>
12+
/// Handles "Streamboo" spam.
13+
/// </summary>
14+
public class Streamboo : AChatRule {
15+
/// <inheritdoc />
16+
public override bool ShouldRun(TwitchUserConfig config) {
17+
return config is { Enabled: true, BanKnownBots: true };
18+
}
19+
20+
/// <inheritdoc />
21+
public override async Task<bool> Handle(string channelId, ITwitchApiProxy botProxy, TwitchChatMessage message,
22+
INullinsideContext db, CancellationToken stoppingToken = new()) {
23+
// The number of spaces per message may chance, so normalize that and lowercase it for comparison.
24+
string normalized = string.Concat(message.Message.Split(" ").Where(s => !string.IsNullOrWhiteSpace(s)))
25+
.ToLowerInvariant();
26+
27+
// Message will start with any of these variations.
28+
if (message.IsFirstMessage && normalized.Contains("streamboo")) {
29+
await BanAndLog(channelId, botProxy, new[] { (message.UserId, message.Username) },
30+
"[Bot] Spam (Streamboo)", db, stoppingToken);
31+
return false;
32+
}
33+
34+
return true;
35+
}
36+
}

0 commit comments

Comments
 (0)