Skip to content

Commit c22a32b

Browse files
Add support for Greek lookalikes to list checks
1 parent d57cd57 commit c22a32b

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

Checks/ListChecks.cs

+40-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public class ListChecks
66
{
77
// Map of Cyrillic to Latin characters, to catch attempted bypasses using Cyrillic lookalikes
88
// <string, string> is <Cyrillic, Latin>
9-
public static Dictionary<string, string> alphabetMap = new()
9+
public static Dictionary<string, string> cyrillicAlphabetMap = new()
1010
{
1111
{ "А", "A" },
1212
{ "В", "B" },
@@ -49,11 +49,49 @@ public class ListChecks
4949
{ "у", "y" },
5050
{ "У", "y" }
5151
};
52+
53+
// Map of Greek to Latin characters, to catch attempted bypasses using Greek lookalikes
54+
// <string, string> is <Greek, Latin>
55+
public static Dictionary<string, string> greekAlphabetMap = new()
56+
{
57+
{ "Α", "A" },
58+
{ "Β", "B" },
59+
{ "Ε", "E" },
60+
{ "Η", "H" },
61+
{ "Ι", "I" },
62+
{ "Κ", "K" },
63+
{ "Μ", "M" },
64+
{ "Ν", "N" },
65+
{ "Ο", "O" },
66+
{ "Ρ", "P" },
67+
{ "Τ", "T" },
68+
{ "Χ", "X" },
69+
{ "Υ", "Y" },
70+
{ "Ζ", "Z" },
71+
{ "α", "a" },
72+
{ "β", "b" },
73+
{ "ε", "e" },
74+
{ "η", "h" },
75+
{ "ι", "i" },
76+
{ "κ", "k" },
77+
{ "μ", "m" },
78+
{ "ν", "n" },
79+
{ "ο", "o" },
80+
{ "ρ", "p" },
81+
{ "τ", "t" },
82+
{ "χ", "x" },
83+
{ "υ", "y" },
84+
{ "ζ", "z" },
85+
};
5286

5387
public static (bool success, string? flaggedWord) CheckForNaughtyWords(string input, WordListJson naughtyWordList)
5488
{
5589
// Replace any Cyrillic letters found in message with Latin characters, if in the dictionary
56-
foreach (var letter in alphabetMap)
90+
foreach (var letter in cyrillicAlphabetMap)
91+
input = input.Replace(letter.Key, letter.Value);
92+
93+
// and Greek letters
94+
foreach (var letter in greekAlphabetMap)
5795
input = input.Replace(letter.Key, letter.Value);
5896

5997
string[] naughtyWords = naughtyWordList.Words;

Events/MessageEvent.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,9 @@ public static async Task MessageHandlerAsync(DiscordClient client, MockDiscordMe
646646

647647
// attempted to ping @everyone/@here
648648
var msgContent = message.Content;
649-
foreach (var letter in Checks.ListChecks.alphabetMap)
649+
foreach (var letter in Checks.ListChecks.cyrillicAlphabetMap)
650+
msgContent = msgContent.Replace(letter.Key, letter.Value);
651+
foreach (var letter in Checks.ListChecks.greekAlphabetMap)
650652
msgContent = msgContent.Replace(letter.Key, letter.Value);
651653
if (Program.cfgjson.EveryoneFilter && !member.Roles.Any(role => Program.cfgjson.EveryoneExcludedRoles.Contains(role.Id)) && !Program.cfgjson.EveryoneExcludedChannels.Contains(channel.Id) && (msgContent.Contains("@everyone") || msgContent.Contains("@here")))
652654
{

0 commit comments

Comments
 (0)