Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/Nullinside.Api.TwitchBot.Tests/ChatRules/StreamBooTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Moq;

using Nullinside.Api.Common.Twitch;
using Nullinside.Api.TwitchBot.ChatRules;
using Nullinside.Api.TwitchBot.Model;

namespace Nullinside.Api.TwitchBot.Tests.ChatRules;

/// <summary>
/// Tests the <see cref="Streamboo" /> class.
/// </summary>
public class StreambooTests : AChatRuleUnitTestBase<Dogehype> {
/// <summary>
/// Tests the strings typed in chats.
/// </summary>
/// <param name="badString">The string that should fail.</param>
[Test]
[TestCase("streamboo .com ( remove the space ) @anohXiot")]
[TestCase("streamboo .com ( remove the space ) @C2apJWT9")]
[TestCase("streamboo .com ( remove the space ) @NpFQHupB")]
[TestCase("streamboo .com ( remove the space ) @tGYF1O11")]
public async Task TestKnownStrings(string badString) {
var rule = new Streamboo();
var botProxy = new Mock<ITwitchApiProxy>();
var chat = new TwitchChatMessage(true, badString, "123", "456");

// Process the message and assert that we fail the message.
bool result = await rule.Handle("123", botProxy.Object, chat, _db);
Assert.That(result, Is.False);
}
}
36 changes: 36 additions & 0 deletions src/Nullinside.Api.TwitchBot/ChatRules/Streamboo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Nullinside.Api.Common.Twitch;
using Nullinside.Api.Model;
using Nullinside.Api.TwitchBot.Model;

using TwitchLib.Client.Models;

using TwitchUserConfig = Nullinside.Api.Model.Ddl.TwitchUserConfig;

namespace Nullinside.Api.TwitchBot.ChatRules;

/// <summary>
/// Handles "Streamboo" spam.
/// </summary>
public class Streamboo : AChatRule {
/// <inheritdoc />
public override bool ShouldRun(TwitchUserConfig config) {
return config is { Enabled: true, BanKnownBots: true };
}

/// <inheritdoc />
public override async Task<bool> Handle(string channelId, ITwitchApiProxy botProxy, TwitchChatMessage message,
INullinsideContext db, CancellationToken stoppingToken = new()) {
// The number of spaces per message may chance, so normalize that and lowercase it for comparison.
string normalized = string.Concat(message.Message.Split(" ").Where(s => !string.IsNullOrWhiteSpace(s)))
.ToLowerInvariant();

// Message will start with any of these variations.
if (message.IsFirstMessage && normalized.Contains("streamboo")) {
await BanAndLog(channelId, botProxy, new[] { (message.UserId, message.Username) },
"[Bot] Spam (Streamboo)", db, stoppingToken);
return false;
}

return true;
}
}