mirror of
https://github.com/Jetsparrow/antiantiswearingbot.git
synced 2026-04-26 05:55:05 +03:00
Compare commits
No commits in common. "0effb60e58a15c8e0022028b13e0c0335e58f563" and "253a05ae313c4b58a0e3076a088a6a9638c513ac" have entirely different histories.
0effb60e58
...
253a05ae31
@ -18,7 +18,7 @@ public class DetectTests : BleepTestsBase
|
||||
[InlineData("еб*ть—колотить", "*ебать")]
|
||||
[InlineData("Получилась полная х**ня: даже не знаю, что и сказать, б**.", "*херня\n**бля")]
|
||||
[InlineData("Сергей опять вы**нулся своим знанием тонкостей русского языка; в окно еб*шил стылый ноябрьский ветер. ", "*выебнулся\n**ебашил")]
|
||||
public async Task DetectWordsWithPunctuation(string text, string expected)
|
||||
public async void DetectWordsWithPunctuation(string text, string expected)
|
||||
{
|
||||
var unbleep = (await ubl.UnbleepSwears(text)).Replace("\r\n", "\n").Trim();
|
||||
Assert.Equal(expected, unbleep);
|
||||
|
||||
@ -5,20 +5,20 @@ public class FilterTests : BleepTestsBase
|
||||
[InlineData("*")]
|
||||
[InlineData("**#")]
|
||||
[InlineData("@*#")]
|
||||
public async Task IgnoreShortGrawlixesWithoutLetters(string text)
|
||||
public void IgnoreShortGrawlixesWithoutLetters(string text)
|
||||
{
|
||||
if (text.Length < DefaultSettings.Unbleeper.MinAmbiguousWordLength)
|
||||
Assert.Null(await ubl.UnbleepSwears(text));
|
||||
Assert.Null(ubl.UnbleepSwears(text));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("*")]
|
||||
[InlineData("*б")]
|
||||
[InlineData("х#")]
|
||||
public async Task IgnoreShortWords(string text)
|
||||
public void IgnoreShortWords(string text)
|
||||
{
|
||||
if (text.Length < DefaultSettings.Unbleeper.MinWordLength)
|
||||
Assert.Null(await ubl.UnbleepSwears(text));
|
||||
Assert.Null(ubl.UnbleepSwears(text));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@ -27,11 +27,11 @@ public class FilterTests : BleepTestsBase
|
||||
[InlineData("@Artyom по поводу")]
|
||||
[InlineData("@Laima прошу блины!")]
|
||||
[InlineData("эй админ @harry0xfefecaca верни бота")]
|
||||
public async Task IgnoreMentions(string text) => Assert.Null(await ubl.UnbleepSwears(text));
|
||||
public void IgnoreMentions(string text) => Assert.Null(ubl.UnbleepSwears(text));
|
||||
|
||||
[Theory]
|
||||
[InlineData("x - floor(abs(x)) * sign(x) -- вроде такая формула для frac(x)")]
|
||||
public async Task IgnoresWeirdShit(string text) => Assert.Null(await ubl.UnbleepSwears(text));
|
||||
public void IgnoresWeirdShit(string text) => Assert.Null(ubl.UnbleepSwears(text));
|
||||
|
||||
[Theory]
|
||||
[InlineData("/poll")]
|
||||
@ -40,7 +40,7 @@ public class FilterTests : BleepTestsBase
|
||||
[InlineData("/status@MinecraftServerBot")]
|
||||
[InlineData("/broadcast@MinecraftServerBot пи#*ец вы понастроили тут")]
|
||||
[InlineData("/ban@MinecraftServerBot @dirty_johnny86")]
|
||||
public async Task IgnoreCommands(string text) => Assert.Null(await ubl.UnbleepSwears(text));
|
||||
public void IgnoreCommands(string text) => Assert.Null(ubl.UnbleepSwears(text));
|
||||
|
||||
[Theory]
|
||||
[InlineData("#UEeğitimKarazin")]
|
||||
@ -61,7 +61,7 @@ public class FilterTests : BleepTestsBase
|
||||
[InlineData("#ZodiacKillerStrikesAgain")]
|
||||
[InlineData("#ThanksObama")]
|
||||
[InlineData("#BalıkBurcuKızıylaEvlenmek")]
|
||||
public async Task IgnoreHashtags(string text) => Assert.Null(await ubl.UnbleepSwears(text));
|
||||
public void IgnoreHashtags(string text) => Assert.Null(ubl.UnbleepSwears(text));
|
||||
|
||||
[Theory]
|
||||
[InlineData("ipetrov@mail.ru")]
|
||||
@ -69,6 +69,6 @@ public class FilterTests : BleepTestsBase
|
||||
[InlineData("ипетров@почта.рф")]
|
||||
[InlineData("admin@local")]
|
||||
[InlineData("админ@local")]
|
||||
public async Task IgnoreEmails(string text) => Assert.Null(await ubl.UnbleepSwears(text));
|
||||
public void IgnoreEmails(string text) => Assert.Null(ubl.UnbleepSwears(text));
|
||||
|
||||
}
|
||||
|
||||
@ -1,18 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.3.0" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="xunit.v3" Version="3.2.2" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
|
||||
<PackageReference Include="xunit" Version="2.4.0" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
|
||||
<UseAppHost>False</UseAppHost>
|
||||
</PropertyGroup>
|
||||
@ -11,16 +11,25 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Telegram.Bot" Version="22.9.6" />
|
||||
<PackageReference Include="Telegram.Bot" Version="19.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Update="appsettings.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Update="secrets.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="aasb.cfg.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="aasb.cfg.secret.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="dict\ObsceneDictionaryRu.txt">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
|
||||
@ -52,13 +52,11 @@ public static class StringEx
|
||||
=> a == b || !char.IsLetterOrDigit(a) || !char.IsLetterOrDigit(b);
|
||||
|
||||
static readonly Regex MentionRegex = new Regex("^@[a-zA-Z0-9_]+$", RegexOptions.Compiled);
|
||||
static readonly Regex TelegramCommandRegex = new Regex("^/[a-zA-Z0-9_]+@?[a-zA-Z0-9_]*", RegexOptions.Compiled);
|
||||
static readonly Regex EmailPartRegex = new Regex("^\\w+@\\w+$", RegexOptions.Compiled);
|
||||
|
||||
static readonly Regex HashTagRegex = new Regex("^#\\w+$", RegexOptions.Compiled);
|
||||
|
||||
public static bool IsTelegramMention(string word) => MentionRegex.IsMatch(word);
|
||||
public static bool IsTelegramCommand(string word) => TelegramCommandRegex.IsMatch(word);
|
||||
|
||||
public static bool IsEmailPart(string word) => EmailPartRegex.IsMatch(word);
|
||||
|
||||
|
||||
@ -54,7 +54,7 @@ public class AntiAntiSwearingBot : IHostedService
|
||||
TelegramBot = new TelegramBotClient(TelegramSettings.ApiKey, httpClient);
|
||||
|
||||
Log.LogInformation("Connecting to Telegram...");
|
||||
Me = await TelegramBot.GetMe(cancellationToken);
|
||||
Me = await TelegramBot.GetMeAsync();
|
||||
Log.LogInformation("Connected to Telegram as @{Username}", Me.Username);
|
||||
Router = new ChatCommandRouter(Me.Username, AccessCfg);
|
||||
Router.Register(new LearnCommand(Dict), "learn");
|
||||
@ -74,7 +74,7 @@ public class AntiAntiSwearingBot : IHostedService
|
||||
|
||||
public async Task StopAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
await TelegramBot.Close();
|
||||
await TelegramBot.CloseAsync();
|
||||
}
|
||||
|
||||
Task HandleErrorAsync(ITelegramBotClient botClient, Exception exception, CancellationToken cancellationToken)
|
||||
@ -97,26 +97,23 @@ public class AntiAntiSwearingBot : IHostedService
|
||||
|
||||
if (cmdResponse != null)
|
||||
{
|
||||
await TelegramBot.SendMessage(
|
||||
msg.Chat,
|
||||
await TelegramBot.SendTextMessageAsync(
|
||||
msg.Chat.Id,
|
||||
cmdResponse,
|
||||
replyParameters: new ReplyParameters { MessageId = msg.MessageId },
|
||||
replyToMessageId: msg.MessageId,
|
||||
parseMode: ParseMode.MarkdownV2,
|
||||
disableNotification: true,
|
||||
cancellationToken: cancellationToken);
|
||||
disableNotification: true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var unbleepResponse = await Unbleeper.UnbleepSwears(msg.Text);
|
||||
if (unbleepResponse != null)
|
||||
await TelegramBot.SendMessage(
|
||||
msg.Chat,
|
||||
await TelegramBot.SendTextMessageAsync(
|
||||
msg.Chat.Id,
|
||||
unbleepResponse,
|
||||
replyParameters: new ReplyParameters { MessageId = msg.MessageId },
|
||||
disableNotification: true,
|
||||
cancellationToken: cancellationToken);
|
||||
|
||||
replyToMessageId: msg.MessageId,
|
||||
disableNotification: true);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
|
||||
@ -26,9 +26,6 @@ public class Unbleeper
|
||||
if (string.IsNullOrWhiteSpace(text))
|
||||
return null;
|
||||
|
||||
if (StringEx.IsTelegramCommand(text))
|
||||
return null;
|
||||
|
||||
text = text.Trim();
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user