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
27 changes: 27 additions & 0 deletions src/Nullinside.Api.TwitchBot.Tests/ChatRules/NezhnaTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Moq;

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

namespace Nullinside.Api.TwitchBot.Tests.ChatRules;

/// <summary>
/// Tests the <see cref="StreamViewers" /> class.
/// </summary>
public class NezhnaTests : AChatRuleUnitTestBase<Nezhna> {
/// <summary>
/// Tests the strings typed in chats.
/// </summary>
/// <param name="badString">The string that should fail.</param>
[Test]
[TestCase("Visit nezhna dot com com to boost your viewers and climb the Twitch rankings. Join thousands of successful streamers now! @7xgkq3EK")]
public async Task TestKnownStrings(string badString) {
var rule = new Nezhna();
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);
}
}
39 changes: 39 additions & 0 deletions src/Nullinside.Api.TwitchBot/ChatRules/Nezhna.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Nullinside.Api.Common.Twitch;
using Nullinside.Api.Model;
using Nullinside.Api.Model.Ddl;

using TwitchLib.Client.Models;

namespace Nullinside.Api.TwitchBot.ChatRules;

/// <summary>
/// Handles the "nezhna dot com" bots.
/// </summary>
public class Nezhna : AChatRule {
private const string SPAM = "Visit nezhna dot com com to boost your viewers and climb the Twitch rankings. Join thousands of successful streamers now!";

/// <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()) {
if (!message.IsFirstMessage) {
return true;
}

// The number of spaces per message may chance, so normalize that and lowercase it for comparison.
string normalized = string.Join(' ', message.Message.Split(" ").Where(s => !string.IsNullOrWhiteSpace(s)))
.ToLowerInvariant();

if (normalized.StartsWith(SPAM, StringComparison.InvariantCultureIgnoreCase)) {
await BanAndLog(channelId, botProxy, new[] { (message.UserId, message.Username) },
"[Bot] Spam (Nezhna)", db, stoppingToken);
return false;
}

return true;
}
}
Loading