mirror of
https://github.com/Jetsparrow/antiantiswearingbot.git
synced 2026-01-20 23:16:08 +03:00
ignore email parts
This commit is contained in:
parent
ed5be399da
commit
a66d5d733c
@ -78,5 +78,13 @@ namespace AntiAntiSwearingBot.Tests
|
||||
[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));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -57,11 +57,14 @@ namespace AntiAntiSwearingBot
|
||||
=> a == b || !char.IsLetterOrDigit(a) || !char.IsLetterOrDigit(b);
|
||||
|
||||
static readonly Regex MentionRegex = new Regex("^@[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 IsEmailPart(string word) => EmailPartRegex.IsMatch(word);
|
||||
|
||||
public static bool IsHashTag(string word) => HashTagRegex.IsMatch(word);
|
||||
|
||||
public static bool HasNonWordChars(string arg) => arg.Any(c => !char.IsLetterOrDigit(c));
|
||||
|
||||
@ -36,6 +36,7 @@ namespace AntiAntiSwearingBot
|
||||
var candidates = words
|
||||
.Where(w =>
|
||||
!Language.IsTelegramMention(w)
|
||||
&& !Language.IsEmailPart(w)
|
||||
&& Language.HasNonWordChars(w)
|
||||
&& !Language.IsHashTag(w)
|
||||
&& (Language.HasWordChars(w) || w.Length >= Cfg.MinAmbiguousWordLength)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user