Skip to content

Commit

Permalink
Merge branch 'main' into floatingmilkshake/dsp-command-migration
Browse files Browse the repository at this point in the history
  • Loading branch information
Erisa committed Jan 12, 2025
2 parents da3d4a2 + d7fbd0c commit e2070ee
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
46 changes: 38 additions & 8 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> alphabetMap = 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,15 +47,45 @@ public class ListChecks
{ "ѡ", "w" },
{ "х", "x" },
{ "у", "y" },
{ "У", "y" }
};
{ "У", "y" },

// <string, string> is <Greek, Latin>
{ "Α", "A" },
{ "Β", "B" },
{ "Ε", "E" },
{ "Η", "H" },
{ "Ι", "I" },
{ "Κ", "K" },
{ "Μ", "M" },
{ "Ν", "N" },
{ "Ο", "O" },
{ "Ρ", "P" },
{ "Τ", "T" },
{ "Χ", "X" },
{ "Υ", "Y" },
{ "Ζ", "Z" },
{ "α", "a" },
{ "β", "b" },
{ "ε", "e" },
{ "η", "h" },
{ "ι", "i" },
{ "κ", "k" },
{ "μ", "m" },
{ "ν", "n" },
{ "ο", "o" },
{ "ρ", "p" },
{ "τ", "t" },
{ "χ", "x" },
{ "υ", "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 alphabetMap)
// 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);

string[] naughtyWords = naughtyWordList.Words;
input = input.Replace("\0", "");
if (naughtyWordList.WholeWord)
Expand Down
2 changes: 1 addition & 1 deletion Events/MessageEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +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.alphabetMap)
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 e2070ee

Please sign in to comment.