diff --git a/AntiAntiSwearingBot.Tests/DetectTests.cs b/AntiAntiSwearingBot.Tests/DetectTests.cs deleted file mode 100644 index 7ac0d57..0000000 --- a/AntiAntiSwearingBot.Tests/DetectTests.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -using Microsoft.Extensions.Options; - -using Xunit; - -namespace AntiAntiSwearingBot.Tests -{ - public class DetectTests - { - Unbleeper ubl { get; } - SearchDictionary dict { get; } - - public DetectTests() - { - - dict = new SearchDictionary(OptionsMonitor ); - ubl = new Unbleeper(dict, cfg.Unbleeper); - } - - [Theory] - [InlineData("бл**ь", "*блядь")] - [InlineData("ж**а", "*жопа")] - public void UnbleepSimpleSwears(string word, string expected) - { - var unbleep = ubl.UnbleepSwears(word).TrimEnd(Environment.NewLine.ToCharArray()); - Assert.Equal(expected, unbleep); - } - - [Theory] - [InlineData("Просто пи**ец, как хочется кушать.", "*пиздец")] - [InlineData("Ужас на*уй!", "*нахуй")] - [InlineData("еб*ть-колотить", "*ебать")] - [InlineData("еб*ть—колотить", "*ебать")] - [InlineData("Получилась полная х**ня: даже не знаю, что и сказать, б**.", "*херня\n**бля")] - [InlineData("Сергей опять вы**нулся своим знанием тонкостей русского языка; в окно еб*шил стылый ноябрьский ветер. ", "*выебнулся\n**ебашил")] - public void DetectWordsWithPunctuation(string text, string expected) - { - var unbleep = ubl.UnbleepSwears(text).Replace("\r\n", "\n").Trim(); - Assert.Equal(expected, unbleep); - } - } -} diff --git a/AntiAntiSwearingBot.Tests/FilterTests.cs b/AntiAntiSwearingBot.Tests/FilterTests.cs deleted file mode 100644 index b512aca..0000000 --- a/AntiAntiSwearingBot.Tests/FilterTests.cs +++ /dev/null @@ -1,90 +0,0 @@ -using System; -using Xunit; - -namespace AntiAntiSwearingBot.Tests -{ - public class FilterTests - { - Unbleeper ubl { get; } - Config cfg { get; } - SearchDictionary dict { get; } - - public FilterTests() - { - cfg = Config.Load("aasb.cfg.json", "aasb.cfg.secret.json"); - dict = new SearchDictionary(cfg); - ubl = new Unbleeper(dict, cfg.Unbleeper); - } - - [Theory] - [InlineData("*")] - [InlineData("**#")] - [InlineData("@*#")] - public void IgnoreShortGrawlixesWithoutLetters(string text) - { - if (text.Length < cfg.Unbleeper.MinAmbiguousWordLength) - Assert.Null(ubl.UnbleepSwears(text)); - } - - [Theory] - [InlineData("*")] - [InlineData("*б")] - [InlineData("х#")] - public void IgnoreShortWords(string text) - { - if (text.Length < cfg.Unbleeper.MinWordLength) - Assert.Null(ubl.UnbleepSwears(text)); - } - - [Theory] - [InlineData("@pvkuznetsov https://github.com/jacksondunstan/UnityNativeScripting")] - [InlineData("@JohnnyMnemonic")] - [InlineData("@Artyom по поводу")] - [InlineData("@Laima прошу блины!")] - [InlineData("эй админ @harry0xfefecaca верни бота")] - public void IgnoreMentions(string text) => Assert.Null(ubl.UnbleepSwears(text)); - - [Theory] - [InlineData("x - floor(abs(x)) * sign(x) -- вроде такая формула для frac(x)")] - public void IgnoresWeirdShit(string text) => Assert.Null(ubl.UnbleepSwears(text)); - - [Theory] - [InlineData("/poll")] - [InlineData("/roll 2d6")] - [InlineData("/award medal")] - [InlineData("/status@MinecraftServerBot")] - [InlineData("/broadcast@MinecraftServerBot пи#*ец вы понастроили тут")] - [InlineData("/ban@MinecraftServerBot @dirty_johnny86")] - public void IgnoreCommands(string text) => Assert.Null(ubl.UnbleepSwears(text)); - - [Theory] - [InlineData("#UEeğitimKarazin")] - [InlineData("#KöksalBabaCafeTrabzonda")] - [InlineData("#ZehraHanımSüresizeKadro")] - [InlineData("#define")] - [InlineData("#ifndef")] - [InlineData("#trashtag")] - [InlineData("#MeToo")] - [InlineData("#инстаграм")] - [InlineData("#битваБлогеров")] - [InlineData("#зенитахмат")] - [InlineData("#HappyKWONJIYONGDay")] - [InlineData("#MCITOT")] - [InlineData("#ТамбовКраснодар")] - [InlineData("#JRockконвент2019")] - [InlineData("#DonaldTrumpAgain")] - [InlineData("#ZodiacKillerStrikesAgain")] - [InlineData("#ThanksObama")] - [InlineData("#BalıkBurcuKızıylaEvlenmek")] - public void IgnoreHashtags(string text) => Assert.Null(ubl.UnbleepSwears(text)); - - [Theory] - [InlineData("ipetrov@mail.ru")] - [InlineData("ipetrov@русская.mail.ru")] - [InlineData("ипетров@почта.рф")] - [InlineData("admin@local")] - [InlineData("админ@local")] - public void IgnoreEmails(string text) => Assert.Null(ubl.UnbleepSwears(text)); - - } -} diff --git a/Jetsparrow.Aasb.Tests/DefaultSettings.cs b/Jetsparrow.Aasb.Tests/DefaultSettings.cs new file mode 100644 index 0000000..dc91df3 --- /dev/null +++ b/Jetsparrow.Aasb.Tests/DefaultSettings.cs @@ -0,0 +1,22 @@ +namespace AntiAntiSwearingBot.Tests; + +public static class DefaultSettings +{ + public static SearchDictionarySettings SearchDictionary { get; } + public static UnbleeperSettings Unbleeper { get; } + + static DefaultSettings() + { + Unbleeper = new UnbleeperSettings + { + BleepedSwearsRegex = @"[а-яА-ЯёЁ@\\*#]+", + MinWordLength = 3, + MinAmbiguousWordLength = 5 + }; + + SearchDictionary = new SearchDictionarySettings + { + DictionaryPath = "dict/ObsceneDictionaryRu.txt" + }; + } +} diff --git a/Jetsparrow.Aasb.Tests/DetectTests.cs b/Jetsparrow.Aasb.Tests/DetectTests.cs new file mode 100644 index 0000000..3871496 --- /dev/null +++ b/Jetsparrow.Aasb.Tests/DetectTests.cs @@ -0,0 +1,42 @@ +using System; + +using Microsoft.Extensions.Options; + +using Xunit; + +namespace AntiAntiSwearingBot.Tests; + +public class DetectTests +{ + Unbleeper ubl { get; } + SearchDictionary dict { get; } + + public DetectTests() + { + + dict = new SearchDictionary(MockOptionsMonitor.Create(DefaultSettings.SearchDictionary)); + ubl = new Unbleeper(dict, Options.Create(DefaultSettings.Unbleeper)); + } + + [Theory] + [InlineData("бл**ь", "*блядь")] + [InlineData("ж**а", "*жопа")] + public void UnbleepSimpleSwears(string word, string expected) + { + var unbleep = ubl.UnbleepSwears(word).TrimEnd(Environment.NewLine.ToCharArray()); + Assert.Equal(expected, unbleep); + } + + [Theory] + [InlineData("Просто пи**ец, как хочется кушать.", "*пиздец")] + [InlineData("Ужас на*уй!", "*нахуй")] + [InlineData("еб*ть-колотить", "*ебать")] + [InlineData("еб*ть—колотить", "*ебать")] + [InlineData("Получилась полная х**ня: даже не знаю, что и сказать, б**.", "*херня\n**бля")] + [InlineData("Сергей опять вы**нулся своим знанием тонкостей русского языка; в окно еб*шил стылый ноябрьский ветер. ", "*выебнулся\n**ебашил")] + public void DetectWordsWithPunctuation(string text, string expected) + { + var unbleep = ubl.UnbleepSwears(text).Replace("\r\n", "\n").Trim(); + Assert.Equal(expected, unbleep); + } +} diff --git a/Jetsparrow.Aasb.Tests/FilterTests.cs b/Jetsparrow.Aasb.Tests/FilterTests.cs new file mode 100644 index 0000000..5806679 --- /dev/null +++ b/Jetsparrow.Aasb.Tests/FilterTests.cs @@ -0,0 +1,88 @@ +using Microsoft.Extensions.Options; + +using Xunit; + +namespace AntiAntiSwearingBot.Tests; + +public class FilterTests +{ + Unbleeper ubl { get; } + SearchDictionary dict { get; } + + public FilterTests() + { + dict = new SearchDictionary(MockOptionsMonitor.Create(DefaultSettings.SearchDictionary)); + ubl = new Unbleeper(dict, Options.Create(DefaultSettings.Unbleeper)); + } + + [Theory] + [InlineData("*")] + [InlineData("**#")] + [InlineData("@*#")] + public void IgnoreShortGrawlixesWithoutLetters(string text) + { + if (text.Length < DefaultSettings.Unbleeper.MinAmbiguousWordLength) + Assert.Null(ubl.UnbleepSwears(text)); + } + + [Theory] + [InlineData("*")] + [InlineData("*б")] + [InlineData("х#")] + public void IgnoreShortWords(string text) + { + if (text.Length < DefaultSettings.Unbleeper.MinWordLength) + Assert.Null(ubl.UnbleepSwears(text)); + } + + [Theory] + [InlineData("@pvkuznetsov https://github.com/jacksondunstan/UnityNativeScripting")] + [InlineData("@JohnnyMnemonic")] + [InlineData("@Artyom по поводу")] + [InlineData("@Laima прошу блины!")] + [InlineData("эй админ @harry0xfefecaca верни бота")] + public void IgnoreMentions(string text) => Assert.Null(ubl.UnbleepSwears(text)); + + [Theory] + [InlineData("x - floor(abs(x)) * sign(x) -- вроде такая формула для frac(x)")] + public void IgnoresWeirdShit(string text) => Assert.Null(ubl.UnbleepSwears(text)); + + [Theory] + [InlineData("/poll")] + [InlineData("/roll 2d6")] + [InlineData("/award medal")] + [InlineData("/status@MinecraftServerBot")] + [InlineData("/broadcast@MinecraftServerBot пи#*ец вы понастроили тут")] + [InlineData("/ban@MinecraftServerBot @dirty_johnny86")] + public void IgnoreCommands(string text) => Assert.Null(ubl.UnbleepSwears(text)); + + [Theory] + [InlineData("#UEeğitimKarazin")] + [InlineData("#KöksalBabaCafeTrabzonda")] + [InlineData("#ZehraHanımSüresizeKadro")] + [InlineData("#define")] + [InlineData("#ifndef")] + [InlineData("#trashtag")] + [InlineData("#MeToo")] + [InlineData("#инстаграм")] + [InlineData("#битваБлогеров")] + [InlineData("#зенитахмат")] + [InlineData("#HappyKWONJIYONGDay")] + [InlineData("#MCITOT")] + [InlineData("#ТамбовКраснодар")] + [InlineData("#JRockконвент2019")] + [InlineData("#DonaldTrumpAgain")] + [InlineData("#ZodiacKillerStrikesAgain")] + [InlineData("#ThanksObama")] + [InlineData("#BalıkBurcuKızıylaEvlenmek")] + public void IgnoreHashtags(string text) => Assert.Null(ubl.UnbleepSwears(text)); + + [Theory] + [InlineData("ipetrov@mail.ru")] + [InlineData("ipetrov@русская.mail.ru")] + [InlineData("ипетров@почта.рф")] + [InlineData("admin@local")] + [InlineData("админ@local")] + public void IgnoreEmails(string text) => Assert.Null(ubl.UnbleepSwears(text)); + +} diff --git a/AntiAntiSwearingBot.Tests/AntiAntiSwearingBot.Tests.csproj b/Jetsparrow.Aasb.Tests/Jetsparrow.Aasb.Tests.csproj similarity index 83% rename from AntiAntiSwearingBot.Tests/AntiAntiSwearingBot.Tests.csproj rename to Jetsparrow.Aasb.Tests/Jetsparrow.Aasb.Tests.csproj index d6bbd71..adf9ac3 100644 --- a/AntiAntiSwearingBot.Tests/AntiAntiSwearingBot.Tests.csproj +++ b/Jetsparrow.Aasb.Tests/Jetsparrow.Aasb.Tests.csproj @@ -13,7 +13,7 @@ - + diff --git a/Jetsparrow.Aasb.Tests/MockOptionsMonitor.cs b/Jetsparrow.Aasb.Tests/MockOptionsMonitor.cs new file mode 100644 index 0000000..bdffde6 --- /dev/null +++ b/Jetsparrow.Aasb.Tests/MockOptionsMonitor.cs @@ -0,0 +1,31 @@ +using System; + +using Microsoft.Extensions.Options; + +public static class MockOptionsMonitor +{ + public static IOptionsMonitor Create(T value) where T : class + => new MockOptionsMonitor(value); +} +public class MockOptionsMonitor : IOptionsMonitor where T : class +{ + public MockOptionsMonitor(T value) + { + CurrentValue = value; + } + + public T CurrentValue { get; } + + public T Get(string name) => CurrentValue; + + public IDisposable OnChange(Action listener) + { + return new DummyDisposable(); + } + + class DummyDisposable : IDisposable + { + public void Dispose() { } + } + +} diff --git a/AntiAntiSwearingBot.sln b/Jetsparrow.Aasb.sln similarity index 78% rename from AntiAntiSwearingBot.sln rename to Jetsparrow.Aasb.sln index 886cca0..38b59e8 100644 --- a/AntiAntiSwearingBot.sln +++ b/Jetsparrow.Aasb.sln @@ -3,9 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 VisualStudioVersion = 15.0.28010.2036 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AntiAntiSwearingBot", "AntiAntiSwearingBot\AntiAntiSwearingBot.csproj", "{66AFFD7B-5B2D-4C85-8523-770702255511}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Jetsparrow.Aasb", "Jetsparrow.Aasb\Jetsparrow.Aasb.csproj", "{66AFFD7B-5B2D-4C85-8523-770702255511}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AntiAntiSwearingBot.Tests", "AntiAntiSwearingBot.Tests\AntiAntiSwearingBot.Tests.csproj", "{AA3CB2CB-05F1-46C4-8710-2702BD663A8B}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jetsparrow.Aasb.Tests", "Jetsparrow.Aasb.Tests\Jetsparrow.Aasb.Tests.csproj", "{AA3CB2CB-05F1-46C4-8710-2702BD663A8B}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/AntiAntiSwearingBot/Aasb.cs b/Jetsparrow.Aasb/Aasb.cs similarity index 100% rename from AntiAntiSwearingBot/Aasb.cs rename to Jetsparrow.Aasb/Aasb.cs diff --git a/AntiAntiSwearingBot/CommandRouter.cs b/Jetsparrow.Aasb/CommandRouter.cs similarity index 100% rename from AntiAntiSwearingBot/CommandRouter.cs rename to Jetsparrow.Aasb/CommandRouter.cs diff --git a/AntiAntiSwearingBot/Commands/CommandString.cs b/Jetsparrow.Aasb/Commands/CommandString.cs similarity index 100% rename from AntiAntiSwearingBot/Commands/CommandString.cs rename to Jetsparrow.Aasb/Commands/CommandString.cs diff --git a/AntiAntiSwearingBot/Commands/LearnCommand.cs b/Jetsparrow.Aasb/Commands/LearnCommand.cs similarity index 100% rename from AntiAntiSwearingBot/Commands/LearnCommand.cs rename to Jetsparrow.Aasb/Commands/LearnCommand.cs diff --git a/AntiAntiSwearingBot/Commands/UnlearnCommand.cs b/Jetsparrow.Aasb/Commands/UnlearnCommand.cs similarity index 100% rename from AntiAntiSwearingBot/Commands/UnlearnCommand.cs rename to Jetsparrow.Aasb/Commands/UnlearnCommand.cs diff --git a/AntiAntiSwearingBot/Config.cs b/Jetsparrow.Aasb/Config.cs similarity index 100% rename from AntiAntiSwearingBot/Config.cs rename to Jetsparrow.Aasb/Config.cs diff --git a/AntiAntiSwearingBot/Extensions/IListExtensions.cs b/Jetsparrow.Aasb/Extensions/IListExtensions.cs similarity index 100% rename from AntiAntiSwearingBot/Extensions/IListExtensions.cs rename to Jetsparrow.Aasb/Extensions/IListExtensions.cs diff --git a/AntiAntiSwearingBot/Extensions/IServiceCollectionExtensions.cs b/Jetsparrow.Aasb/Extensions/IServiceCollectionExtensions.cs similarity index 100% rename from AntiAntiSwearingBot/Extensions/IServiceCollectionExtensions.cs rename to Jetsparrow.Aasb/Extensions/IServiceCollectionExtensions.cs diff --git a/AntiAntiSwearingBot/Extensions/ReaderWriterLockSlimExtensions.cs b/Jetsparrow.Aasb/Extensions/ReaderWriterLockSlimExtensions.cs similarity index 100% rename from AntiAntiSwearingBot/Extensions/ReaderWriterLockSlimExtensions.cs rename to Jetsparrow.Aasb/Extensions/ReaderWriterLockSlimExtensions.cs diff --git a/AntiAntiSwearingBot/GlobalSuppressions.cs b/Jetsparrow.Aasb/GlobalSuppressions.cs similarity index 100% rename from AntiAntiSwearingBot/GlobalSuppressions.cs rename to Jetsparrow.Aasb/GlobalSuppressions.cs diff --git a/AntiAntiSwearingBot/GlobalUsings.cs b/Jetsparrow.Aasb/GlobalUsings.cs similarity index 100% rename from AntiAntiSwearingBot/GlobalUsings.cs rename to Jetsparrow.Aasb/GlobalUsings.cs diff --git a/AntiAntiSwearingBot/AntiAntiSwearingBot.csproj b/Jetsparrow.Aasb/Jetsparrow.Aasb.csproj similarity index 100% rename from AntiAntiSwearingBot/AntiAntiSwearingBot.csproj rename to Jetsparrow.Aasb/Jetsparrow.Aasb.csproj diff --git a/AntiAntiSwearingBot/Language.cs b/Jetsparrow.Aasb/Language.cs similarity index 100% rename from AntiAntiSwearingBot/Language.cs rename to Jetsparrow.Aasb/Language.cs diff --git a/AntiAntiSwearingBot/Program.cs b/Jetsparrow.Aasb/Program.cs similarity index 100% rename from AntiAntiSwearingBot/Program.cs rename to Jetsparrow.Aasb/Program.cs diff --git a/AntiAntiSwearingBot/Properties/PublishProfiles/FolderProfile.pubxml b/Jetsparrow.Aasb/Properties/PublishProfiles/FolderProfile.pubxml similarity index 100% rename from AntiAntiSwearingBot/Properties/PublishProfiles/FolderProfile.pubxml rename to Jetsparrow.Aasb/Properties/PublishProfiles/FolderProfile.pubxml diff --git a/AntiAntiSwearingBot/Properties/launchSettings.json b/Jetsparrow.Aasb/Properties/launchSettings.json similarity index 100% rename from AntiAntiSwearingBot/Properties/launchSettings.json rename to Jetsparrow.Aasb/Properties/launchSettings.json diff --git a/AntiAntiSwearingBot/SearchDictionary.cs b/Jetsparrow.Aasb/SearchDictionary.cs similarity index 100% rename from AntiAntiSwearingBot/SearchDictionary.cs rename to Jetsparrow.Aasb/SearchDictionary.cs diff --git a/AntiAntiSwearingBot/StartupHealthCheck.cs b/Jetsparrow.Aasb/StartupHealthCheck.cs similarity index 100% rename from AntiAntiSwearingBot/StartupHealthCheck.cs rename to Jetsparrow.Aasb/StartupHealthCheck.cs diff --git a/AntiAntiSwearingBot/Unbleeper.cs b/Jetsparrow.Aasb/Unbleeper.cs similarity index 100% rename from AntiAntiSwearingBot/Unbleeper.cs rename to Jetsparrow.Aasb/Unbleeper.cs diff --git a/AntiAntiSwearingBot/appsettings.json b/Jetsparrow.Aasb/appsettings.json similarity index 100% rename from AntiAntiSwearingBot/appsettings.json rename to Jetsparrow.Aasb/appsettings.json diff --git a/AntiAntiSwearingBot/dict/ObsceneDictionaryRu.txt b/Jetsparrow.Aasb/dict/ObsceneDictionaryRu.txt similarity index 100% rename from AntiAntiSwearingBot/dict/ObsceneDictionaryRu.txt rename to Jetsparrow.Aasb/dict/ObsceneDictionaryRu.txt