Skip to content

Commit 682fbbc

Browse files
Merge pull request #33 from nullinside-development-group/feature/DiscordScams
Adding discord scam detection
2 parents 6c0db48 + 4d99433 commit 682fbbc

File tree

7 files changed

+50
-9
lines changed

7 files changed

+50
-9
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace Nullinside.Api.TwitchBot.Tests.ChatRules;
2+
3+
public class DiscordTests
4+
{
5+
[Test]
6+
[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")]
7+
[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")]
8+
[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")]
9+
[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")]
10+
[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")]
11+
public void TestKnownStrings(string badString)
12+
{
13+
// Need to put interfaces in front of the classes before we can do this.
14+
Assert.Pass();
15+
}
16+
}

src/Nullinside.Api.TwitchBot/ChatRules/BestCheapViewers.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ public override bool ShouldRun(TwitchUserConfig config) {
2323
/// <inheritdoc />
2424
public override async Task<bool> Handle(string channelId, TwitchApiProxy botProxy, ChatMessage message,
2525
NullinsideContext db, CancellationToken stoppingToken = new()) {
26+
if (!message.IsFirstMessage) {
27+
return true;
28+
}
29+
2630
// The number of spaces per message may chance, so normalize that and lowercase it for comparison.
2731
string normalized = string.Join(' ', message.Message.Split(" ").Where(s => !string.IsNullOrWhiteSpace(s)))
2832
.ToLowerInvariant();

src/Nullinside.Api.TwitchBot/ChatRules/Discord.cs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ namespace Nullinside.Api.TwitchBot.ChatRules;
1010
/// Handles the add me on discord bots.
1111
/// </summary>
1212
public class Discord : AChatRule {
13-
private const string _spam = "I would like to be on of your fans if you don't mind kindly add me up on discord";
13+
private readonly string[] KNOWN_PHRASES = [
14+
"add me on discord",
15+
"my username is",
16+
"my discord username is"
17+
];
1418

1519
/// <inheritdoc />
1620
public override bool ShouldRun(TwitchUserConfig config) {
@@ -20,11 +24,24 @@ public override bool ShouldRun(TwitchUserConfig config) {
2024
/// <inheritdoc />
2125
public override async Task<bool> Handle(string channelId, TwitchApiProxy botProxy, ChatMessage message,
2226
NullinsideContext db, CancellationToken stoppingToken = new()) {
23-
if (message.IsFirstMessage &&
24-
message.Message.Contains(_spam, StringComparison.InvariantCultureIgnoreCase)) {
25-
await BanAndLog(channelId, botProxy, new[] { (message.UserId, message.Username) },
26-
"[Bot] Spam (Discord Freaks)", db, stoppingToken);
27-
return false;
27+
if (!message.IsFirstMessage) {
28+
return true;
29+
}
30+
31+
// The number of spaces per message may chance, so normalize that and lowercase it for comparison.
32+
string normalized = string.Join(' ', message.Message.Split(" ").Where(s => !string.IsNullOrWhiteSpace(s)))
33+
.ToLowerInvariant();
34+
35+
if (!normalized.Contains("discord", StringComparison.InvariantCultureIgnoreCase)) {
36+
return true;
37+
}
38+
39+
foreach (var phrase in KNOWN_PHRASES) {
40+
if (normalized.Contains(phrase, StringComparison.InvariantCultureIgnoreCase)) {
41+
await BanAndLog(channelId, botProxy, new[] { (message.UserId, message.Username) },
42+
"[Bot] Spam (Discord Scammers)", db, stoppingToken);
43+
return false;
44+
}
2845
}
2946

3047
return true;

src/Nullinside.Api.TwitchBot/ChatRules/Dogehype.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public override async Task<bool> Handle(string channelId, TwitchApiProxy botProx
2323
.ToLowerInvariant();
2424

2525
// Message will start with any of these variations.
26-
if (normalized.Contains("dogehype")) {
26+
if (message.IsFirstMessage && normalized.Contains("dogehype")) {
2727
await BanAndLog(channelId, botProxy, new[] { (message.UserId, message.Username) },
2828
"[Bot] Spam (Dogehype)", db, stoppingToken);
2929
return false;

src/Nullinside.Api.TwitchBot/ChatRules/StreamRise.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public override bool ShouldRun(TwitchUserConfig config) {
2424
/// <inheritdoc />
2525
public override async Task<bool> Handle(string channelId, TwitchApiProxy botProxy, ChatMessage message,
2626
NullinsideContext db, CancellationToken stoppingToken = new()) {
27-
if (_spam.Equals(message.Message, StringComparison.InvariantCultureIgnoreCase)) {
27+
if (message.IsFirstMessage && _spam.Equals(message.Message, StringComparison.InvariantCultureIgnoreCase)) {
2828
await BanAndLog(channelId, botProxy, new[] { (message.UserId, message.Username) },
2929
"[Bot] Spam (StreamRise)", db, stoppingToken);
3030
return false;

src/Nullinside.Api.TwitchBot/ChatRules/StreamViewers.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ public override bool ShouldRun(TwitchUserConfig config) {
2323
/// <inheritdoc />
2424
public override async Task<bool> Handle(string channelId, TwitchApiProxy botProxy, ChatMessage message,
2525
NullinsideContext db, CancellationToken stoppingToken = new()) {
26+
if (!message.IsFirstMessage) {
27+
return true;
28+
}
29+
2630
List<string> parts = message.Message
2731
.Split(" ")
2832
.Where(s => !string.IsNullOrWhiteSpace(s))

src/Nullinside.Api.TwitchBot/Services/MainService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ protected override Task ExecuteAsync(CancellationToken stoppingToken) {
117117
}
118118
catch (Exception ex) {
119119
_log.LogError(ex, "Main Failed");
120-
await Task.Delay(TimeSpan.FromSeconds(10));
120+
await Task.Delay(TimeSpan.FromSeconds(10), stoppingToken);
121121
}
122122
}
123123
}, stoppingToken);

0 commit comments

Comments
 (0)