Skip to content

Commit d98efa2

Browse files
Merge pull request #52 from nullinside-development-group/feature/Nezhna
Nezhna spam
2 parents 56783ee + 805086a commit d98efa2

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using Moq;
2+
3+
using Nullinside.Api.Common.Twitch;
4+
using Nullinside.Api.TwitchBot.ChatRules;
5+
6+
namespace Nullinside.Api.TwitchBot.Tests.ChatRules;
7+
8+
/// <summary>
9+
/// Tests the <see cref="StreamViewers" /> class.
10+
/// </summary>
11+
public class NezhnaTests : AChatRuleUnitTestBase<Nezhna> {
12+
/// <summary>
13+
/// Tests the strings typed in chats.
14+
/// </summary>
15+
/// <param name="badString">The string that should fail.</param>
16+
[Test]
17+
[TestCase("Visit nezhna dot com com to boost your viewers and climb the Twitch rankings. Join thousands of successful streamers now! @7xgkq3EK")]
18+
public async Task TestKnownStrings(string badString) {
19+
var rule = new Nezhna();
20+
var botProxy = new Mock<ITwitchApiProxy>();
21+
var chat = new TwitchChatMessage(true, badString, "123", "456");
22+
23+
// Process the message and assert that we fail the message.
24+
bool result = await rule.Handle("123", botProxy.Object, chat, _db);
25+
Assert.That(result, Is.False);
26+
}
27+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using Nullinside.Api.Common.Twitch;
2+
using Nullinside.Api.Model;
3+
using Nullinside.Api.Model.Ddl;
4+
5+
using TwitchLib.Client.Models;
6+
7+
namespace Nullinside.Api.TwitchBot.ChatRules;
8+
9+
/// <summary>
10+
/// Handles the "nezhna dot com" bots.
11+
/// </summary>
12+
public class Nezhna : AChatRule {
13+
private const string SPAM = "Visit nezhna dot com com to boost your viewers and climb the Twitch rankings. Join thousands of successful streamers now!";
14+
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+
if (!message.IsFirstMessage) {
24+
return true;
25+
}
26+
27+
// The number of spaces per message may chance, so normalize that and lowercase it for comparison.
28+
string normalized = string.Join(' ', message.Message.Split(" ").Where(s => !string.IsNullOrWhiteSpace(s)))
29+
.ToLowerInvariant();
30+
31+
if (normalized.StartsWith(SPAM, StringComparison.InvariantCultureIgnoreCase)) {
32+
await BanAndLog(channelId, botProxy, new[] { (message.UserId, message.Username) },
33+
"[Bot] Spam (Nezhna)", db, stoppingToken);
34+
return false;
35+
}
36+
37+
return true;
38+
}
39+
}

0 commit comments

Comments
 (0)