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
20 changes: 10 additions & 10 deletions src/Nullinside.Api.TwitchBot.Tests/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,13 @@ end_of_line = lf
insert_final_newline = false

#### .NET Coding Conventions ####
[*.{cs,vb}]

# Organize usings
dotnet_separate_import_directive_groups = true
dotnet_sort_system_directives_first = true
file_header_template = # this. and Me. preferences


file_header_template = unset

# this. and Me. preferences
dotnet_style_qualification_for_event = false:silent
dotnet_style_qualification_for_field = false:silent
dotnet_style_qualification_for_method = false:silent
Expand Down Expand Up @@ -79,7 +77,6 @@ dotnet_code_quality_unused_parameters = all:suggestion
dotnet_remove_unnecessary_suppression_exclusions = none

#### C# Coding Conventions ####
[*.cs]

# var preferences
csharp_style_var_elsewhere = false:silent
Expand Down Expand Up @@ -176,7 +173,6 @@ csharp_preserve_single_line_blocks = true
csharp_preserve_single_line_statements = true

#### Naming styles ####
[*.{cs,vb}]

# Naming rules

Expand Down Expand Up @@ -230,19 +226,19 @@ dotnet_naming_rule.private_static_fields_should_be_s_camelcase.style = s_camelca

dotnet_naming_rule.public_constant_fields_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.public_constant_fields_should_be_pascalcase.symbols = public_constant_fields
dotnet_naming_rule.public_constant_fields_should_be_pascalcase.style = pascalcase
dotnet_naming_rule.public_constant_fields_should_be_pascalcase.style = all_upper

dotnet_naming_rule.private_constant_fields_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.private_constant_fields_should_be_pascalcase.symbols = private_constant_fields
dotnet_naming_rule.private_constant_fields_should_be_pascalcase.style = pascalcase
dotnet_naming_rule.private_constant_fields_should_be_pascalcase.style = all_upper

dotnet_naming_rule.public_static_readonly_fields_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.public_static_readonly_fields_should_be_pascalcase.symbols = public_static_readonly_fields
dotnet_naming_rule.public_static_readonly_fields_should_be_pascalcase.style = pascalcase
dotnet_naming_rule.public_static_readonly_fields_should_be_pascalcase.style = all_upper

dotnet_naming_rule.private_static_readonly_fields_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.private_static_readonly_fields_should_be_pascalcase.symbols = private_static_readonly_fields
dotnet_naming_rule.private_static_readonly_fields_should_be_pascalcase.style = pascalcase
dotnet_naming_rule.private_static_readonly_fields_should_be_pascalcase.style = all_upper

dotnet_naming_rule.enums_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.enums_should_be_pascalcase.symbols = enums
Expand Down Expand Up @@ -366,3 +362,7 @@ dotnet_naming_style.s_camelcase.required_suffix =
dotnet_naming_style.s_camelcase.word_separator =
dotnet_naming_style.s_camelcase.capitalization = camel_case

dotnet_naming_style.all_upper.required_prefix =
dotnet_naming_style.all_upper.required_suffix =
dotnet_naming_style.all_upper.word_separator = _
dotnet_naming_style.all_upper.capitalization = all_upper
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class BestCheapViewersTests : AChatRuleUnitTestBase<BestCheapViewers> {
[TestCase("Cheaͧp v̫iewers on *** ")]
[TestCase("Cheap viewers ͚on followersboosters.ru @U8y0GrKS")]
[TestCase("Chea̓p viewers on streamboo. com (remove the space) @ND80DOGe")]
[TestCase("Bestͮ vie͐wers ̷on cutt.ly/EeK6Anda")]
[TestCase("Bestͮ vie͐wers ̷on cutt.ly/EeK6Anda")]
[TestCase("Bestͮ vie͐wers ̷on viewerszone.online")]
[TestCase("Best viěw\u0310e\u0329rs \u0333o\u032bno\u034en streamboo .com ( remove the space ) @WSZ7tPNI")]
public async Task TestKnownStrings(string badString) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="9.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="9.0.6" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="9.0.6"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="9.0.6"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1"/>
<PackageReference Include="Moq" Version="4.20.72"/>
<PackageReference Include="NUnit" Version="4.3.2" />
<PackageReference Include="NUnit" Version="4.3.2"/>
<PackageReference Include="NUnit.Analyzers" Version="4.8.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="NUnit3TestAdapter" Version="5.0.0" />
<PackageReference Include="NUnit3TestAdapter" Version="5.0.0"/>
</ItemGroup>

<ItemGroup>
Expand Down
15 changes: 8 additions & 7 deletions src/Nullinside.Api.TwitchBot/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ end_of_line = lf
insert_final_newline = false

#### .NET Coding Conventions ####
[*.{cs,vb}]

# Organize usings
dotnet_separate_import_directive_groups = true
Expand Down Expand Up @@ -78,7 +77,6 @@ dotnet_code_quality_unused_parameters = all:suggestion
dotnet_remove_unnecessary_suppression_exclusions = none

#### C# Coding Conventions ####
[*.cs]

# var preferences
csharp_style_var_elsewhere = false:silent
Expand Down Expand Up @@ -175,7 +173,6 @@ csharp_preserve_single_line_blocks = true
csharp_preserve_single_line_statements = true

#### Naming styles ####
[*.{cs,vb}]

# Naming rules

Expand Down Expand Up @@ -229,19 +226,19 @@ dotnet_naming_rule.private_static_fields_should_be_s_camelcase.style = s_camelca

dotnet_naming_rule.public_constant_fields_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.public_constant_fields_should_be_pascalcase.symbols = public_constant_fields
dotnet_naming_rule.public_constant_fields_should_be_pascalcase.style = pascalcase
dotnet_naming_rule.public_constant_fields_should_be_pascalcase.style = all_upper

dotnet_naming_rule.private_constant_fields_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.private_constant_fields_should_be_pascalcase.symbols = private_constant_fields
dotnet_naming_rule.private_constant_fields_should_be_pascalcase.style = pascalcase
dotnet_naming_rule.private_constant_fields_should_be_pascalcase.style = all_upper

dotnet_naming_rule.public_static_readonly_fields_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.public_static_readonly_fields_should_be_pascalcase.symbols = public_static_readonly_fields
dotnet_naming_rule.public_static_readonly_fields_should_be_pascalcase.style = pascalcase
dotnet_naming_rule.public_static_readonly_fields_should_be_pascalcase.style = all_upper

dotnet_naming_rule.private_static_readonly_fields_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.private_static_readonly_fields_should_be_pascalcase.symbols = private_static_readonly_fields
dotnet_naming_rule.private_static_readonly_fields_should_be_pascalcase.style = pascalcase
dotnet_naming_rule.private_static_readonly_fields_should_be_pascalcase.style = all_upper

dotnet_naming_rule.enums_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.enums_should_be_pascalcase.symbols = enums
Expand Down Expand Up @@ -365,3 +362,7 @@ dotnet_naming_style.s_camelcase.required_suffix =
dotnet_naming_style.s_camelcase.word_separator =
dotnet_naming_style.s_camelcase.capitalization = camel_case

dotnet_naming_style.all_upper.required_prefix =
dotnet_naming_style.all_upper.required_suffix =
dotnet_naming_style.all_upper.word_separator = _
dotnet_naming_style.all_upper.capitalization = all_upper
2 changes: 1 addition & 1 deletion src/Nullinside.Api.TwitchBot/Bots/ABotRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ where string.Equals(bannedUsers.ChannelId, channelId) &&

// Perform the ban and get the list of people actually banned
IEnumerable<BannedUser> confirmedBans =
await botProxy.BanChannelUsers(channelId, Constants.BotId, bansToTry, reason, stoppingToken);
await botProxy.BanChannelUsers(channelId, Constants.BOT_ID, bansToTry, reason, stoppingToken);

await db.SaveTwitchBans(channelId, users, reason, stoppingToken);
return confirmedBans;
Expand Down
3 changes: 2 additions & 1 deletion src/Nullinside.Api.TwitchBot/Bots/BanKnownBots.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,5 @@
// jsonString = null;
// return allBots;
// }
// }
// }

4 changes: 1 addition & 3 deletions src/Nullinside.Api.TwitchBot/ChatRules/AChatRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
using Nullinside.Api.Model;
using Nullinside.Api.TwitchBot.Model;

using TwitchLib.Client.Models;

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

namespace Nullinside.Api.TwitchBot.ChatRules;
Expand Down Expand Up @@ -31,7 +29,7 @@ public abstract Task<bool> Handle(string channelId, ITwitchApiProxy botProxy, Tw
public async Task BanAndLog(string channelId, ITwitchApiProxy botProxy,
IEnumerable<(string Id, string Username)> users, string reason, INullinsideContext db,
CancellationToken stoppingToken = new()) {
await botProxy.BanChannelUsers(channelId, Constants.BotId, users, reason, stoppingToken);
await botProxy.BanChannelUsers(channelId, Constants.BOT_ID, users, reason, stoppingToken);
await db.SaveTwitchBans(channelId, users, reason, stoppingToken);
}
}
16 changes: 7 additions & 9 deletions src/Nullinside.Api.TwitchBot/ChatRules/BestCheapViewers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
using Nullinside.Api.Model;
using Nullinside.Api.TwitchBot.Model;

using TwitchLib.Client.Models;

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

namespace Nullinside.Api.TwitchBot.ChatRules;
Expand All @@ -13,15 +11,15 @@ namespace Nullinside.Api.TwitchBot.ChatRules;
/// </summary>
public class BestCheapViewers : AChatRule {
/// <summary>
/// The strings that we expect to receive if this is a bot.
/// The strings that we expect to receive if this is a bot.
/// </summary>
public readonly string[] EXPECTED = [
"best viewers on",
public readonly string[] Expected = [
"best viewers on",
"cheap viewers on",
"cheap folloewrs on",
"do you want more viewers and to rank higher on the twitch list? you can visit the website"
];

/// <inheritdoc />
public override bool ShouldRun(TwitchUserConfig config) {
return config is { Enabled: true, BanKnownBots: true };
Expand All @@ -33,23 +31,23 @@ public override async Task<bool> Handle(string channelId, ITwitchApiProxy botPro
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();

// Messages will be one of two variations with random special characters mixed in. Some of those special characters
// will be accent marks. When we receive an accent mark it'll take the position of a real character, hence why we
// need an offset applied only to the incoming string.
foreach (var expected in EXPECTED) {
foreach (string expected in Expected) {
if (normalized.Length > expected.Length) {
int matches = 0;
int offset = 0;
for (int i = 0; i < expected.Length; i++) {
// If this is a normal character it should be in the correct position.
if (i + offset < normalized.Length && normalized[i + offset] == expected[i]) {
++matches;
}
}
// If this is an accent mark then the next character should match and the whole string we're evalutating
// will be off by 1 more position.
else if (i + offset + 1 < normalized.Length && normalized[i + offset + 1] == expected[i]) {
Expand Down
2 changes: 0 additions & 2 deletions src/Nullinside.Api.TwitchBot/ChatRules/Botsister.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
using Nullinside.Api.Model;
using Nullinside.Api.TwitchBot.Model;

using TwitchLib.Client.Models;

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

namespace Nullinside.Api.TwitchBot.ChatRules;
Expand Down
8 changes: 3 additions & 5 deletions src/Nullinside.Api.TwitchBot/ChatRules/Discord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
using Nullinside.Api.Model;
using Nullinside.Api.TwitchBot.Model;

using TwitchLib.Client.Models;

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

namespace Nullinside.Api.TwitchBot.ChatRules;
Expand All @@ -12,7 +10,7 @@ namespace Nullinside.Api.TwitchBot.ChatRules;
/// Handles the add me on discord bots.
/// </summary>
public class Discord : AChatRule {
private readonly string[] KNOWN_PHRASES = [
private readonly string[] _knownPhrases = [
"add me",
"add my",
"add up",
Expand All @@ -38,7 +36,7 @@ public override async Task<bool> Handle(string channelId, ITwitchApiProxy botPro
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 All @@ -47,7 +45,7 @@ public override async Task<bool> Handle(string channelId, ITwitchApiProxy botPro
return true;
}

foreach (var phrase in KNOWN_PHRASES) {
foreach (string phrase in _knownPhrases) {
if (normalized.Contains(phrase, StringComparison.InvariantCultureIgnoreCase)) {
await BanAndLog(channelId, botProxy, new[] { (message.UserId, message.Username) },
"[Bot] Spam (Discord Scammers)", db, stoppingToken);
Expand Down
2 changes: 0 additions & 2 deletions src/Nullinside.Api.TwitchBot/ChatRules/Dogehype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
using Nullinside.Api.Model;
using Nullinside.Api.TwitchBot.Model;

using TwitchLib.Client.Models;

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

namespace Nullinside.Api.TwitchBot.ChatRules;
Expand Down
2 changes: 0 additions & 2 deletions src/Nullinside.Api.TwitchBot/ChatRules/HostHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
using Nullinside.Api.Model;
using Nullinside.Api.TwitchBot.Model;

using TwitchLib.Client.Models;

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

namespace Nullinside.Api.TwitchBot.ChatRules;
Expand Down
2 changes: 0 additions & 2 deletions src/Nullinside.Api.TwitchBot/ChatRules/IChatRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
using Nullinside.Api.Model;
using Nullinside.Api.TwitchBot.Model;

using TwitchLib.Client.Models;

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

namespace Nullinside.Api.TwitchBot.ChatRules;
Expand Down
14 changes: 6 additions & 8 deletions src/Nullinside.Api.TwitchBot/ChatRules/IfYouWantViewers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,21 @@
using Nullinside.Api.Model;
using Nullinside.Api.TwitchBot.Model;

using TwitchLib.Client.Models;

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

namespace Nullinside.Api.TwitchBot.ChatRules;

/// <summary>
/// "if you want viewers, go to [link]" scam.
/// "if you want viewers, go to [link]" scam.
/// </summary>
public class IfYouWantViewers : AChatRule {
/// <summary>
/// The strings that we expect to receive if this is a bot.
/// The strings that we expect to receive if this is a bot.
/// </summary>
public readonly string[] EXPECTED = [
public readonly string[] Expected = [
"if you want more viewers for your stream, go to"
];

/// <inheritdoc />
public override bool ShouldRun(TwitchUserConfig config) {
return config is { Enabled: true, BanKnownBots: true };
Expand All @@ -30,12 +28,12 @@ public override async Task<bool> Handle(string channelId, ITwitchApiProxy botPro
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();

foreach (var expected in EXPECTED) {
foreach (string expected in Expected) {
if (normalized.Contains(expected, StringComparison.InvariantCultureIgnoreCase)) {
await BanAndLog(channelId, botProxy, new[] { (message.UserId, message.Username) },
"[Bot] Spam (If You Want Viewers)", db, stoppingToken);
Expand Down
10 changes: 4 additions & 6 deletions src/Nullinside.Api.TwitchBot/ChatRules/Naked.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
using Nullinside.Api.Model;
using Nullinside.Api.TwitchBot.Model;

using TwitchLib.Client.Models;

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

namespace Nullinside.Api.TwitchBot.ChatRules;
Expand All @@ -12,8 +10,8 @@ namespace Nullinside.Api.TwitchBot.ChatRules;
/// Handles the want to see her naked porn bots.
/// </summary>
public class Naked : AChatRule {
private const string _spam = "Want to see her naked?";
private const string _spam2 = "Want to see me naked?";
private const string SPAM = "Want to see her naked?";
private const string SPAM2 = "Want to see me naked?";

/// <inheritdoc />
public override bool ShouldRun(TwitchUserConfig config) {
Expand All @@ -24,8 +22,8 @@ public override bool ShouldRun(TwitchUserConfig config) {
public override async Task<bool> Handle(string channelId, ITwitchApiProxy botProxy, TwitchChatMessage message,
INullinsideContext db, CancellationToken stoppingToken = new()) {
if (message.IsFirstMessage &&
(message.Message.TrimStart().StartsWith(_spam, StringComparison.InvariantCultureIgnoreCase) ||
message.Message.TrimStart().StartsWith(_spam2, StringComparison.InvariantCultureIgnoreCase))) {
(message.Message.TrimStart().StartsWith(SPAM, StringComparison.InvariantCultureIgnoreCase) ||
message.Message.TrimStart().StartsWith(SPAM2, StringComparison.InvariantCultureIgnoreCase))) {
await BanAndLog(channelId, botProxy, new[] { (message.UserId, message.Username) },
"[Bot] Spam (Naked)", db, stoppingToken);
return false;
Expand Down
Loading