From 832d325cab87a98864dd89b5d9a4df3139db792e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=E2=96=88=E2=96=88=E2=96=88=E2=96=88=E2=96=88?= Date: Thu, 13 Feb 2025 20:24:56 -0500 Subject: [PATCH] feat: New streamboo spam --- .../ChatRules/StreamBooTests.cs | 31 ++++++++++++++++ .../ChatRules/Streamboo.cs | 36 +++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 src/Nullinside.Api.TwitchBot.Tests/ChatRules/StreamBooTests.cs create mode 100644 src/Nullinside.Api.TwitchBot/ChatRules/Streamboo.cs diff --git a/src/Nullinside.Api.TwitchBot.Tests/ChatRules/StreamBooTests.cs b/src/Nullinside.Api.TwitchBot.Tests/ChatRules/StreamBooTests.cs new file mode 100644 index 0000000..472b219 --- /dev/null +++ b/src/Nullinside.Api.TwitchBot.Tests/ChatRules/StreamBooTests.cs @@ -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; + +/// +/// Tests the class. +/// +public class StreambooTests : AChatRuleUnitTestBase { + /// + /// Tests the strings typed in chats. + /// + /// The string that should fail. + [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(); + 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); + } +} \ No newline at end of file diff --git a/src/Nullinside.Api.TwitchBot/ChatRules/Streamboo.cs b/src/Nullinside.Api.TwitchBot/ChatRules/Streamboo.cs new file mode 100644 index 0000000..9a5e13c --- /dev/null +++ b/src/Nullinside.Api.TwitchBot/ChatRules/Streamboo.cs @@ -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; + +/// +/// Handles "Streamboo" spam. +/// +public class Streamboo : AChatRule { + /// + public override bool ShouldRun(TwitchUserConfig config) { + return config is { Enabled: true, BanKnownBots: true }; + } + + /// + public override async Task 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; + } +} \ No newline at end of file