Skip to content

Commit d7fbd0c

Browse files
committed
Unify lookalike mappings
1 parent c22a32b commit d7fbd0c

File tree

2 files changed

+10
-20
lines changed

2 files changed

+10
-20
lines changed

Checks/ListChecks.cs

+9-17
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ namespace Cliptok.Checks
44
{
55
public class ListChecks
66
{
7-
// Map of Cyrillic to Latin characters, to catch attempted bypasses using Cyrillic lookalikes
8-
// <string, string> is <Cyrillic, Latin>
9-
public static Dictionary<string, string> cyrillicAlphabetMap = new()
7+
// Map of lookalike to Latin characters, to catch attempted bypasses using different language lookalikes
8+
public static Dictionary<string, string> lookalikeAlphabetMap = new()
109
{
10+
// <string, string> is <Cyrillic, Latin>
1111
{ "А", "A" },
1212
{ "В", "B" },
1313
{ "С", "C" },
@@ -47,13 +47,9 @@ public class ListChecks
4747
{ "ѡ", "w" },
4848
{ "х", "x" },
4949
{ "у", "y" },
50-
{ "У", "y" }
51-
};
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-
{
50+
{ "У", "y" },
51+
52+
// <string, string> is <Greek, Latin>
5753
{ "Α", "A" },
5854
{ "Β", "B" },
5955
{ "Ε", "E" },
@@ -83,17 +79,13 @@ public class ListChecks
8379
{ "υ", "y" },
8480
{ "ζ", "z" },
8581
};
86-
82+
8783
public static (bool success, string? flaggedWord) CheckForNaughtyWords(string input, WordListJson naughtyWordList)
8884
{
89-
// Replace any Cyrillic letters found in message with Latin characters, if in the dictionary
90-
foreach (var letter in cyrillicAlphabetMap)
85+
// Replace any lookalike letters found in message with Latin characters, if in the dictionary
86+
foreach (var letter in lookalikeAlphabetMap)
9187
input = input.Replace(letter.Key, letter.Value);
9288

93-
// and Greek letters
94-
foreach (var letter in greekAlphabetMap)
95-
input = input.Replace(letter.Key, letter.Value);
96-
9789
string[] naughtyWords = naughtyWordList.Words;
9890
input = input.Replace("\0", "");
9991
if (naughtyWordList.WholeWord)

Events/MessageEvent.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -646,9 +646,7 @@ 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.cyrillicAlphabetMap)
650-
msgContent = msgContent.Replace(letter.Key, letter.Value);
651-
foreach (var letter in Checks.ListChecks.greekAlphabetMap)
649+
foreach (var letter in Checks.ListChecks.lookalikeAlphabetMap)
652650
msgContent = msgContent.Replace(letter.Key, letter.Value);
653651
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")))
654652
{

0 commit comments

Comments
 (0)