Skip to content

Commit 0df3c27

Browse files
Merge pull request #126 from nullinside-development-group/feat/peakpy
feat: remove peakpy bots
2 parents 322de57 + e4b7e88 commit 0df3c27

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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="Dogehype" /> class.
11+
/// </summary>
12+
public class PeakPyTests : AChatRuleUnitTestBase<PeakPy> {
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("@blackysing Sup, your stream could use some hype PeakPy .com fills it quick (remove the space) @4KB,")]
19+
[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,")]
20+
[TestCase("@floridean Sup, your stream could use some hype PeakPy .com can pump some real followers in there quick (remove the space) @sR4n35hG,")]
21+
[TestCase("@floridean Yo, chat's quiet, PeakPy .com brings real viewers instantly (remove the space) @sN3ZZtgF,")]
22+
public async Task TestKnownStrings(string badString) {
23+
var rule = new PeakPy();
24+
var botProxy = new Mock<ITwitchApiProxy>();
25+
var chat = new TwitchChatMessage(true, badString, "123", "456");
26+
27+
// Process the message and assert that we fail the message.
28+
bool result = await rule.Handle("123", botProxy.Object, chat, _db).ConfigureAwait(false);
29+
Assert.That(result, Is.False);
30+
}
31+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using Nullinside.Api.Common.Twitch;
2+
using Nullinside.Api.Model;
3+
using Nullinside.Api.TwitchBot.Model;
4+
5+
using TwitchUserConfig = Nullinside.Api.Model.Ddl.TwitchUserConfig;
6+
7+
namespace Nullinside.Api.TwitchBot.ChatRules;
8+
9+
/// <summary>
10+
/// Handles "PeakPy" spam.
11+
/// </summary>
12+
public class PeakPy : AChatRule {
13+
/// <inheritdoc />
14+
public override bool ShouldRun(TwitchUserConfig config) {
15+
return config is { Enabled: true, BanKnownBots: true };
16+
}
17+
18+
/// <inheritdoc />
19+
public override async Task<bool> Handle(string channelId, ITwitchApiProxy botProxy, TwitchChatMessage message,
20+
INullinsideContext db, CancellationToken stoppingToken = new()) {
21+
// The number of spaces per message may chance, so normalize that and lowercase it for comparison.
22+
string normalized = string.Concat(message.Message.Split(" ").Where(s => !string.IsNullOrWhiteSpace(s)))
23+
.ToLowerInvariant();
24+
25+
// Message will start with any of these variations.
26+
if (message.IsFirstMessage && normalized.Contains("peakpy")) {
27+
await BanAndLog(channelId, botProxy, new[] { (message.UserId, message.Username) },
28+
"[Bot] Spam (PeakPy)", db, stoppingToken).ConfigureAwait(false);
29+
return false;
30+
}
31+
32+
return true;
33+
}
34+
}

0 commit comments

Comments
 (0)