diff --git a/MinecraftClient/ChatBots/Alerts.cs b/MinecraftClient/ChatBots/Alerts.cs index 0682f6f6..42274ebb 100644 --- a/MinecraftClient/ChatBots/Alerts.cs +++ b/MinecraftClient/ChatBots/Alerts.cs @@ -31,22 +31,20 @@ namespace MinecraftClient.ChatBots [TomlInlineComment("$config.ChatBot.Alerts.Trigger_By_Thunderstorm$")] public bool Trigger_By_Thunderstorm = false; - [TomlInlineComment("$config.ChatBot.Alerts.Matches_File$")] - public string Matches_File = @"alerts.txt"; - - [TomlInlineComment("$config.ChatBot.Alerts.Excludes_File$")] - public string Excludes_File = @"alerts-exclude.txt"; - [TomlInlineComment("$config.ChatBot.Alerts.Log_To_File$")] public bool Log_To_File = false; [TomlInlineComment("$config.ChatBot.Alerts.Log_File$")] public string Log_File = @"alerts-log.txt"; + [TomlPrecedingComment("$config.ChatBot.Alerts.Matches_File$")] + public string[] Matches = new string[] { "Yourname", " whispers ", "-> me", "admin", ".com" }; + + [TomlPrecedingComment("$config.ChatBot.Alerts.Excludes_File$")] + public string[] Excludes = new string[] { "myserver.com", "Yourname>:", "Player Yourname", "Yourname joined", "Yourname left", "[Lockette] (Admin)", " Yourname:", "Yourname is" }; + public void OnSettingUpdate() { - Matches_File ??= string.Empty; - Excludes_File ??= string.Empty; Log_File ??= string.Empty; if (!Enabled) return; @@ -55,18 +53,6 @@ namespace MinecraftClient.ChatBots if (Trigger_By_Words) { - if (!System.IO.File.Exists(Matches_File)) - { - checkSuccessed = false; - LogToConsole(BotName, "File not found: " + System.IO.Path.GetFullPath(Matches_File)); - } - - if (!System.IO.File.Exists(Excludes_File)) - { - checkSuccessed = false; - LogToConsole(BotName, "File not found: " + System.IO.Path.GetFullPath(Excludes_File)); - } - if (Log_To_File) { try @@ -76,7 +62,7 @@ namespace MinecraftClient.ChatBots catch { checkSuccessed = false; - LogToConsole(BotName, "Can't write logs to " + System.IO.Path.GetFullPath(Excludes_File)); + LogToConsole(BotName, "Can't write logs to " + System.IO.Path.GetFullPath(Log_File)); } } } @@ -89,25 +75,10 @@ namespace MinecraftClient.ChatBots } } - private string[] dictionary = Array.Empty(); - private string[] excludelist = Array.Empty(); - float curRainLevel = 0; float curThunderLevel = 0; const float threshold = 0.2f; - /// - /// Intitialize the Alerts bot - /// - public override void Initialize() - { - if (Config.Trigger_By_Words) - { - dictionary = LoadDistinctEntriesFromFile(Config.Matches_File); - excludelist = LoadDistinctEntriesFromFile(Config.Excludes_File); - } - } - /// /// Process text received from the server to display alerts /// @@ -120,10 +91,10 @@ namespace MinecraftClient.ChatBots text = GetVerbatim(text).ToLower(); //Proceed only if no exclusions are found in text - if (!excludelist.Any(exclusion => text.Contains(exclusion))) + if (!Config.Excludes.Any(exclusion => text.Contains(exclusion))) { //Show an alert for each alert item found in text, if any - foreach (string alert in dictionary.Where(alert => text.Contains(alert))) + foreach (string alert in Config.Matches.Where(alert => text.Contains(alert))) { if (Config.Beep_Enabled) Console.Beep(); //Text found ! diff --git a/MinecraftClient/ChatBots/AutoCraft.cs b/MinecraftClient/ChatBots/AutoCraft.cs index 173f1394..7a74cd4d 100644 --- a/MinecraftClient/ChatBots/AutoCraft.cs +++ b/MinecraftClient/ChatBots/AutoCraft.cs @@ -21,11 +21,11 @@ namespace MinecraftClient.ChatBots public bool Enabled = false; - [TomlInlineComment("$config.ChatBot.AutoCraft.Table_Location$")] - public LocationConfig Table_Location = new(123, 65, 456); + [TomlInlineComment("$config.ChatBot.AutoCraft.CraftingTable$")] + public LocationConfig CraftingTable = new(123, 65, 456); - [TomlInlineComment("$config.ChatBot.AutoCraft.On_Failure$")] - public OnFailConfig On_Failure = OnFailConfig.abort; + [TomlInlineComment("$config.ChatBot.AutoCraft.OnFailure$")] + public OnFailConfig OnFailure = OnFailConfig.abort; [TomlPrecedingComment("$config.ChatBot.AutoCraft.Recipes$")] public RecipeConfig[] Recipes = new RecipeConfig[] @@ -53,7 +53,7 @@ namespace MinecraftClient.ChatBots public void OnSettingUpdate() { - _Table_Location = new Location(Table_Location.X, Table_Location.Y, Table_Location.Z).ToFloor(); + _Table_Location = new Location(CraftingTable.X, CraftingTable.Y, CraftingTable.Z).ToFloor(); foreach (RecipeConfig recipe in Recipes) { recipe.Name ??= string.Empty; @@ -599,7 +599,7 @@ namespace MinecraftClient.ChatBots // Inform user the missing meterial name LogToConsoleTranslated("bot.autoCraft.missing_material", actionSteps[index - 1].ItemType.ToString()); } - if (Config.On_Failure == OnFailConfig.abort) + if (Config.OnFailure == OnFailConfig.abort) { StopCrafting(); LogToConsoleTranslated("bot.autoCraft.aborted"); diff --git a/MinecraftClient/ChatBots/AutoRelog.cs b/MinecraftClient/ChatBots/AutoRelog.cs index a5f03bd6..dd4473e5 100644 --- a/MinecraftClient/ChatBots/AutoRelog.cs +++ b/MinecraftClient/ChatBots/AutoRelog.cs @@ -29,7 +29,7 @@ namespace MinecraftClient.ChatBots public bool Ignore_Kick_Message = false; [TomlInlineComment("$config.ChatBot.AutoRelog.Kick_Messages$")] - public string[] Kick_Messages = new string[] { "Reason1", "Reason2" }; + public string[] Kick_Messages = new string[] { "Connection has been lost", "Server is restarting", "Server is full", "Too Many people" }; public void OnSettingUpdate() { diff --git a/MinecraftClient/Resources/lang/en.ini b/MinecraftClient/Resources/lang/en.ini index 52ee50c4..a560c077 100644 --- a/MinecraftClient/Resources/lang/en.ini +++ b/MinecraftClient/Resources/lang/en.ini @@ -789,8 +789,8 @@ config.ChatBot.AutoAttack.Entites_List=All entity types can be found here: https # ChatBot.AutoCraft config.ChatBot.AutoCraft=Automatically craft items in your inventory\n# See README > 'Using the AutoCraft bot' for how to use\n# You need to enable Inventory Handling to use this bot\n# You should also enable Terrain and Movements if you need to use a crafting table -config.ChatBot.AutoCraft.Table_Location=Location of the crafting table if you intended to use it. Terrain and movements must be enabled. -config.ChatBot.AutoCraft.On_Failure=What to do on crafting failure, "abort" or "wait". +config.ChatBot.AutoCraft.CraftingTable=Location of the crafting table if you intended to use it. Terrain and movements must be enabled. +config.ChatBot.AutoCraft.OnFailure=What to do on crafting failure, "abort" or "wait". config.ChatBot.AutoCraft.Recipes=Recipes.Name: The name can be whatever you like and it is used to represent the recipe.\n# Recipes.Type: crafting table type: player or table\n# Recipes.Result: the resulting item\n# Recipes.Slots: All slots, counting from left to right, top to bottom. Please fill in "Null" for empty slots.\n# For the naming of the items, please see:\n# https://github.com/MCCTeam/Minecraft-Console-Client/blob/master/MinecraftClient/Inventory/ItemType.cs # ChatBot.AutoDrop diff --git a/MinecraftClient/Settings.cs b/MinecraftClient/Settings.cs index c68c9ad0..c3525b2b 100644 --- a/MinecraftClient/Settings.cs +++ b/MinecraftClient/Settings.cs @@ -26,8 +26,7 @@ namespace MinecraftClient { public static class Settings { - // Minecraft Console Client client information used for BrandInfo setting - public const string MCCBrandInfo = "Minecraft-Console-Client/" + Program.Version; + private const int CommentsAlignPosition = 45; //Other Settings public static string TranslationsFile_FromMCDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\.minecraft\assets\objects\48\482e0dae05abfa35ab5cb076e41fda77b4fb9a08"; //MC 1.19 en_GB.lang @@ -165,7 +164,7 @@ namespace MinecraftClient { string config = match.Groups[1].Value, comment = match.Groups[2].Value; if (config.Length > 0) - newConfig.Append(config).Append(' ', Math.Max(1, 45 - config.Length) - 1); + newConfig.Append(config).Append(' ', Math.Max(1, CommentsAlignPosition - config.Length) - 1); newConfig.Append("# ").AppendLine(Translations.TryGet(comment).ReplaceLineEndings()); } else @@ -1103,7 +1102,7 @@ namespace MinecraftClient { return info switch { - BrandInfoType.mcc => Settings.MCCBrandInfo, + BrandInfoType.mcc => "Minecraft-Console-Client/" + Program.Version, BrandInfoType.vanilla => "vanilla", BrandInfoType.empty => null, _ => null,