From 9e921d5ff90dbc26683d3eeaea29fab0c6e99a7f Mon Sep 17 00:00:00 2001 From: barelyprofessional <150058423+barelyprofessional@users.noreply.github.com> Date: Thu, 9 Apr 2026 20:32:44 -0500 Subject: [PATCH] Because apparently being retards in the chat is lol xD lmao so funny and my patch the other day made some people mad the war has now escalated --- KfChatDotNetBot/ChatBot.cs | 41 ++++++++++++++++++++++---- KfChatDotNetBot/KfChatDotNetBot.csproj | 1 + KfChatDotNetBot/Settings/BuiltIn.cs | 4 +++ 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/KfChatDotNetBot/ChatBot.cs b/KfChatDotNetBot/ChatBot.cs index d4817bc..bacd736 100644 --- a/KfChatDotNetBot/ChatBot.cs +++ b/KfChatDotNetBot/ChatBot.cs @@ -1,5 +1,6 @@ using System.Net; using System.Text.Json; +using Homoglyphic; using KfChatDotNetBot.Extensions; using KfChatDotNetBot.Models; using KfChatDotNetBot.Models.DbModels; @@ -37,6 +38,7 @@ public class ChatBot private List _scheduledDeletions = []; private Task _scheduledAutoDeleteTask; private List _currentUsersInChat = []; + private HomoglyphSearch? _homoglyphSearch; public ChatBot() { @@ -95,6 +97,13 @@ public class ChatBot _logger.Debug("Creating scheduled auto deletion task"); _scheduledAutoDeleteTask = ScheduledDeletionTask(); + _logger.Debug("Trying to load homoglyphs"); + if (File.Exists("homoglyphs.csv")) + { + var sets = HomoglyphLoader.LoadSets("homoglyphs.csv"); + _homoglyphSearch = new HomoglyphSearch(sets); + } + _logger.Debug("Blocking the main thread"); var exitEvent = new ManualResetEvent(false); exitEvent.WaitOne(); @@ -440,16 +449,36 @@ public class ChatBot // Strip weird control characters and just allow basic punctuation + whitespace var kindaSanitized = new string(message.MessageRawHtmlDecoded .Where(c => c == ' ' || char.IsPunctuation(c) || char.IsLetter(c) || char.IsDigit(c)).ToArray()); + var homoglyphFound = false; + if (_homoglyphSearch != null) + { + var searchStrings = + SettingsProvider.GetValueAsync(BuiltIn.Keys.BotDiscordImpersonationSearchStrings).Result + .JsonDeserialize>(); + var lowerStrings = searchStrings?.Select(x => x.ToLower()).ToList(); + var search = _homoglyphSearch.Search(kindaSanitized.ToLower(), lowerStrings); + if (search.Count == 0) + { + search = _homoglyphSearch.Search(kindaSanitized, searchStrings); + } + homoglyphFound = search.Count > 0; + } if ((message.MessageEditDate == null || message.MessageDate > DateTimeOffset.UtcNow.AddSeconds(-15)) && message.Author.Id != settings[BuiltIn.Keys.GambaSeshUserId].ToType() && message.Author.Username != settings[BuiltIn.Keys.KiwiFarmsUsername].Value && - settings[BuiltIn.Keys.BotRespondToDiscordImpersonation].ToBoolean() && - (kindaSanitized.Contains("discord16.png") || - (kindaSanitized.Contains("mBossmanJack:", StringComparison.CurrentCultureIgnoreCase) && - kindaSanitized.Contains("[img]", StringComparison.CurrentCultureIgnoreCase)) || - kindaSanitized.Contains("by @KenoGPT at", StringComparison.CurrentCultureIgnoreCase))) + settings[BuiltIn.Keys.BotRespondToDiscordImpersonation].ToBoolean() && kindaSanitized.Contains("[img]") + && homoglyphFound) { - SendChatMessage($"☝️ {message.Author.Username} is a nigger faggot", true); + var deleteOrNah = SettingsProvider.GetValueAsync(BuiltIn.Keys.BotDiscordImpersonationDeleteAttempt) + .Result.ToBoolean(); + if (deleteOrNah) + { + _ = KfClient.DeleteMessageAsync(message.MessageUuid); + } + else + { + SendChatMessage($"☝️ {message.Author.Username} is a nigger faggot", true); + } } } diff --git a/KfChatDotNetBot/KfChatDotNetBot.csproj b/KfChatDotNetBot/KfChatDotNetBot.csproj index 827776d..f58f7cb 100644 --- a/KfChatDotNetBot/KfChatDotNetBot.csproj +++ b/KfChatDotNetBot/KfChatDotNetBot.csproj @@ -11,6 +11,7 @@ + diff --git a/KfChatDotNetBot/Settings/BuiltIn.cs b/KfChatDotNetBot/Settings/BuiltIn.cs index 090eb03..797284f 100644 --- a/KfChatDotNetBot/Settings/BuiltIn.cs +++ b/KfChatDotNetBot/Settings/BuiltIn.cs @@ -566,6 +566,10 @@ public static class BuiltIn public static string ShuffleDotUsBmjUserId = "ShuffleDotUs.BmjUserId"; [BuiltInSetting("UUID for the current MOTD message UUID", SettingValueType.Text)] public static string KiwiFarmsMotdUuid = "KiwiFarms.MotdUuid"; + [BuiltInSetting("Whether to delete the impersonation attempt instead of just calling it out", SettingValueType.Boolean, "false", BooleanRegex)] + public static string BotDiscordImpersonationDeleteAttempt = "Bot.DiscordImpersonation.DeleteAttempt"; + [BuiltInSetting("What search strings the Homoglyphic searcher should look for", SettingValueType.Array, "[\"discord16.png\", \"mBossmanJack:\", \"mBossnanJack:\", \"mBosmanJack:\", \"by @KenoGPT at\"]")] + public static string BotDiscordImpersonationSearchStrings = "Bot.DiscordImpersonation.SearchStrings"; } }