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

public class DiscordTests
{
[Test]
[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")]
[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")]
[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")]
[TestCase("Hi! Just wanted to say that I absolutely love your gameplay and content.l'd love to connect better with you on Discord if that's possible. Looking forward to more awesome streams from you! My username is 👉👉👉 edisonpires")]
[TestCase("What's up Friend, great stream! I'm having a blast watching you stream. Let's move the conversation to Discord, where we can discuss more about streaming in more detail and get to know each other better. See you there! My discord username is 👉john_6029")]
public void TestKnownStrings(string badString)
{
// Need to put interfaces in front of the classes before we can do this.
Assert.Pass();
}
}
4 changes: 4 additions & 0 deletions src/Nullinside.Api.TwitchBot/ChatRules/BestCheapViewers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public override bool ShouldRun(TwitchUserConfig config) {
/// <inheritdoc />
public override async Task<bool> Handle(string channelId, TwitchApiProxy botProxy, ChatMessage message,
NullinsideContext 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();
Expand Down
29 changes: 23 additions & 6 deletions src/Nullinside.Api.TwitchBot/ChatRules/Discord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ namespace Nullinside.Api.TwitchBot.ChatRules;
/// Handles the add me on discord bots.
/// </summary>
public class Discord : AChatRule {
private const string _spam = "I would like to be on of your fans if you don't mind kindly add me up on discord";
private readonly string[] KNOWN_PHRASES = [
"add me on discord",
"my username is",
"my discord username is"
];

/// <inheritdoc />
public override bool ShouldRun(TwitchUserConfig config) {
Expand All @@ -20,11 +24,24 @@ public override bool ShouldRun(TwitchUserConfig config) {
/// <inheritdoc />
public override async Task<bool> Handle(string channelId, TwitchApiProxy botProxy, ChatMessage message,
NullinsideContext db, CancellationToken stoppingToken = new()) {
if (message.IsFirstMessage &&
message.Message.Contains(_spam, StringComparison.InvariantCultureIgnoreCase)) {
await BanAndLog(channelId, botProxy, new[] { (message.UserId, message.Username) },
"[Bot] Spam (Discord Freaks)", db, stoppingToken);
return false;
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.Contains("discord", StringComparison.InvariantCultureIgnoreCase)) {
return true;
}

foreach (var phrase in KNOWN_PHRASES) {
if (normalized.Contains(phrase, StringComparison.InvariantCultureIgnoreCase)) {
await BanAndLog(channelId, botProxy, new[] { (message.UserId, message.Username) },
"[Bot] Spam (Discord Scammers)", db, stoppingToken);
return false;
}
}

return true;
Expand Down
2 changes: 1 addition & 1 deletion src/Nullinside.Api.TwitchBot/ChatRules/Dogehype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public override async Task<bool> Handle(string channelId, TwitchApiProxy botProx
.ToLowerInvariant();

// Message will start with any of these variations.
if (normalized.Contains("dogehype")) {
if (message.IsFirstMessage && normalized.Contains("dogehype")) {
await BanAndLog(channelId, botProxy, new[] { (message.UserId, message.Username) },
"[Bot] Spam (Dogehype)", db, stoppingToken);
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/Nullinside.Api.TwitchBot/ChatRules/StreamRise.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public override bool ShouldRun(TwitchUserConfig config) {
/// <inheritdoc />
public override async Task<bool> Handle(string channelId, TwitchApiProxy botProxy, ChatMessage message,
NullinsideContext db, CancellationToken stoppingToken = new()) {
if (_spam.Equals(message.Message, StringComparison.InvariantCultureIgnoreCase)) {
if (message.IsFirstMessage && _spam.Equals(message.Message, StringComparison.InvariantCultureIgnoreCase)) {
await BanAndLog(channelId, botProxy, new[] { (message.UserId, message.Username) },
"[Bot] Spam (StreamRise)", db, stoppingToken);
return false;
Expand Down
4 changes: 4 additions & 0 deletions src/Nullinside.Api.TwitchBot/ChatRules/StreamViewers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public override bool ShouldRun(TwitchUserConfig config) {
/// <inheritdoc />
public override async Task<bool> Handle(string channelId, TwitchApiProxy botProxy, ChatMessage message,
NullinsideContext db, CancellationToken stoppingToken = new()) {
if (!message.IsFirstMessage) {
return true;
}

List<string> parts = message.Message
.Split(" ")
.Where(s => !string.IsNullOrWhiteSpace(s))
Expand Down
2 changes: 1 addition & 1 deletion src/Nullinside.Api.TwitchBot/Services/MainService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ protected override Task ExecuteAsync(CancellationToken stoppingToken) {
}
catch (Exception ex) {
_log.LogError(ex, "Main Failed");
await Task.Delay(TimeSpan.FromSeconds(10));
await Task.Delay(TimeSpan.FromSeconds(10), stoppingToken);
}
}
}, stoppingToken);
Expand Down
Loading