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/PeakPyTests.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="Dogehype" /> class.
/// </summary>
public class PeakPyTests : AChatRuleUnitTestBase<PeakPy> {
/// <summary>
/// Tests the strings typed in chats.
/// </summary>
/// <param name="badString">The string that should fail.</param>
[Test]
[TestCase("@blackysing Sup, your stream could use some hype PeakPy .com fills it quick (remove the space) @4KB,")]
[TestCase("@ethuins Yo dude, saw your stream's kinda dead rn PeakPy .com can pump some real eyes in there quick (remove the space) @cMr,")]
[TestCase("@floridean Sup, your stream could use some hype PeakPy .com can pump some real followers in there quick (remove the space) @sR4n35hG,")]
[TestCase("@floridean Yo, chat's quiet, PeakPy .com brings real viewers instantly (remove the space) @sN3ZZtgF,")]
public async Task TestKnownStrings(string badString) {
var rule = new PeakPy();
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).ConfigureAwait(false);
Assert.That(result, Is.False);
}
}
34 changes: 34 additions & 0 deletions src/Nullinside.Api.TwitchBot/ChatRules/PeakPy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Nullinside.Api.Common.Twitch;
using Nullinside.Api.Model;
using Nullinside.Api.TwitchBot.Model;

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

namespace Nullinside.Api.TwitchBot.ChatRules;

/// <summary>
/// Handles "PeakPy" spam.
/// </summary>
public class PeakPy : 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("peakpy")) {
await BanAndLog(channelId, botProxy, new[] { (message.UserId, message.Username) },
"[Bot] Spam (PeakPy)", db, stoppingToken).ConfigureAwait(false);
return false;
}

return true;
}
}
Loading