Skip to content

Commit

Permalink
Unify lookalike mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
Erisa committed Jan 12, 2025
1 parent c22a32b commit d7fbd0c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 20 deletions.
26 changes: 9 additions & 17 deletions Checks/ListChecks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ namespace Cliptok.Checks
{
public class ListChecks
{
// Map of Cyrillic to Latin characters, to catch attempted bypasses using Cyrillic lookalikes
// <string, string> is <Cyrillic, Latin>
public static Dictionary<string, string> cyrillicAlphabetMap = new()
// Map of lookalike to Latin characters, to catch attempted bypasses using different language lookalikes
public static Dictionary<string, string> lookalikeAlphabetMap = new()
{
// <string, string> is <Cyrillic, Latin>
{ "А", "A" },
{ "В", "B" },
{ "С", "C" },
Expand Down Expand Up @@ -47,13 +47,9 @@ public class ListChecks
{ "ѡ", "w" },
{ "х", "x" },
{ "у", "y" },
{ "У", "y" }
};

// Map of Greek to Latin characters, to catch attempted bypasses using Greek lookalikes
// <string, string> is <Greek, Latin>
public static Dictionary<string, string> greekAlphabetMap = new()
{
{ "У", "y" },

// <string, string> is <Greek, Latin>
{ "Α", "A" },
{ "Β", "B" },
{ "Ε", "E" },
Expand Down Expand Up @@ -83,17 +79,13 @@ public class ListChecks
{ "υ", "y" },
{ "ζ", "z" },
};

public static (bool success, string? flaggedWord) CheckForNaughtyWords(string input, WordListJson naughtyWordList)
{
// Replace any Cyrillic letters found in message with Latin characters, if in the dictionary
foreach (var letter in cyrillicAlphabetMap)
// Replace any lookalike letters found in message with Latin characters, if in the dictionary
foreach (var letter in lookalikeAlphabetMap)
input = input.Replace(letter.Key, letter.Value);

// and Greek letters
foreach (var letter in greekAlphabetMap)
input = input.Replace(letter.Key, letter.Value);

string[] naughtyWords = naughtyWordList.Words;
input = input.Replace("\0", "");
if (naughtyWordList.WholeWord)
Expand Down
4 changes: 1 addition & 3 deletions Events/MessageEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -646,9 +646,7 @@ public static async Task MessageHandlerAsync(DiscordClient client, MockDiscordMe

// attempted to ping @everyone/@here
var msgContent = message.Content;
foreach (var letter in Checks.ListChecks.cyrillicAlphabetMap)
msgContent = msgContent.Replace(letter.Key, letter.Value);
foreach (var letter in Checks.ListChecks.greekAlphabetMap)
foreach (var letter in Checks.ListChecks.lookalikeAlphabetMap)
msgContent = msgContent.Replace(letter.Key, letter.Value);
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")))
{
Expand Down

0 comments on commit d7fbd0c

Please sign in to comment.