Skip to content

Commit c63d188

Browse files
feat: New bot rules
1 parent 04e3d6b commit c63d188

File tree

5 files changed

+69
-1
lines changed

5 files changed

+69
-1
lines changed

src/Nullinside.Api.TwitchBot.Tests/ChatRules/BestCheapViewersTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ public class BestCheapViewersTests : AChatRuleUnitTestBase<BestCheapViewers> {
1515
/// </summary>
1616
/// <param name="badString">The string that should fail.</param>
1717
[Test]
18+
[TestCase("B\u0366est vie\u031fwers on streamboo .com ( remove the space ) @IBjZQcD1")]
19+
[TestCase("Cheap \u0314Viewers on streamboo .com ( remove the space ) @kX9lOgg1")]
1820
[TestCase("B͐est vi̯ewers o͎n on streamboo .com ( remove the space ) @9F3Wnft0")]
1921
[TestCase("Ch̚eͅap viewers on *** @STGPMoLg")]
2022
[TestCase("C̭heap viewe͌rs on̆ *** @R1QXrXPM")]
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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="Botsister" /> class.
11+
/// </summary>
12+
public class BotsisterTests : AChatRuleUnitTestBase<Botsister> {
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("Your chat’s so empty, it’s giving ‘no signal’ vibes. Fix it with botsister .com @uFi5gGov")]
19+
public async Task TestKnownStrings(string badString) {
20+
var rule = new Botsister();
21+
var botProxy = new Mock<ITwitchApiProxy>();
22+
var chat = new TwitchChatMessage(true, badString, "123", "456");
23+
24+
// Process the message and assert that we fail the message.
25+
bool result = await rule.Handle("123", botProxy.Object, chat, _db);
26+
Assert.That(result, Is.False);
27+
}
28+
}

src/Nullinside.Api.TwitchBot.Tests/ChatRules/DiscordTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public class DiscordTests : AChatRuleUnitTestBase<Discord> {
1515
/// </summary>
1616
/// <param name="badString">The string that should fail.</param>
1717
[Test]
18+
[TestCase("Yo bruh \u2764\ufe0f let's sometimes play together and share tips add up on discord \ud83d\udc49 willam0340")]
1819
[TestCase("Hello mate you stream pretty cool that's why I follow I would love to be a fan of yours if you don't mind kindly add me on Discord: 👉👉lacaster5")]
1920
[TestCase("Hello, I just recently found your channel and can already tell that your content is great, and I would love to stick with you long term. If you're open to it, I'd be willing to connect with you on Discord. My username is teecash1000")]
2021
[TestCase("Hey there 👋 You stream pretty cool that’s why I followed you. I will like to make you a friend and be a fan, if you don’t mind Kindly chat me on Discord, my Discord username is tuckzay")]
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 "botsister" spam.
13+
/// </summary>
14+
public class Botsister : 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("botsister")) {
29+
await BanAndLog(channelId, botProxy, new[] { (message.UserId, message.Username) },
30+
"[Bot] Spam (Botsister)", db, stoppingToken);
31+
return false;
32+
}
33+
34+
return true;
35+
}
36+
}

src/Nullinside.Api.TwitchBot/ChatRules/Discord.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ public class Discord : AChatRule {
1818
"chat with me",
1919
"my discord username",
2020
"my username",
21-
"connect on discord"
21+
"connect on discord",
22+
"add up"
2223
];
2324

2425
/// <inheritdoc />

0 commit comments

Comments
 (0)