Skip to content

Commit

Permalink
Convert Cyrillic lookalikes to Latin chars for word filter
Browse files Browse the repository at this point in the history
  • Loading branch information
FloatingMilkshake committed Jun 18, 2024
1 parent 9088004 commit 563bd81
Showing 1 changed file with 52 additions and 1 deletion.
53 changes: 52 additions & 1 deletion Events/MessageEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,58 @@ public static async Task MessageHandlerAsync(DiscordClient client, DiscordMessag
}
else
{
(bool success, string flaggedWord) = Checks.ListChecks.CheckForNaughtyWords(message.Content.ToLower(), listItem);
// Map of Cyrillic to Latin characters, to catch attempted bypasses using Cyrillic lookalikes
// <string, string> is <Cyrillic, Latin>
Dictionary<string, string> alphabetMap = new()
{
{ "А", "A" },
{ "В", "B" },
{ "С", "C" },
{ "Е", "E" },
{ "Ԍ", "G" },
{ "Н", "H" },
{ "І", "I" },
{ "Ӏ", "I" },
{ "ӏ", "I" },
{ "Ј", "J" },
{ "К", "K" },
{ "М", "M" },
{ "О", "O" },
{ "Р", "P" },
{ "Ѕ", "S" },
{ "Т", "T" },
{ "Ѵ", "V" },
{ "Ԝ", "W" },
{ "Х", "X" },
{ "Ү", "Y" },
{ "ү", "Y" },
{ "а", "a" },
{ "Ь", "b" },
{ "с", "c" },
{ "ԁ", "d" },
{ "е", "e" },
{ "ҽ", "e" },
{ "һ", "h" },
{ "і", "i" },
{ "ј", "j" },
{ "о", "o" },
{ "р", "p" },
{ "ԛ", "q" },
{ "г", "r" },
{ "ѕ", "s" },
{ "ѵ", "v" },
{ "ѡ", "w" },
{ "х", "x" },
{ "у", "y" },
{ "У", "y" }
};

// Replace any Cyrillic letters found in message with Latin characters, if in the dictionary
string msgContent = message.Content;
foreach (var letter in alphabetMap)
msgContent = msgContent.Replace(letter.Key, letter.Value);

(bool success, string flaggedWord) = Checks.ListChecks.CheckForNaughtyWords(msgContent.ToLower(), listItem);
if (success)
{
string reason = listItem.Reason;
Expand Down

0 comments on commit 563bd81

Please sign in to comment.