diff --git a/MinecraftClient/ChatBots/AntiAFK.cs b/MinecraftClient/ChatBots/AntiAFK.cs index e166a432..5f9234a6 100644 --- a/MinecraftClient/ChatBots/AntiAFK.cs +++ b/MinecraftClient/ChatBots/AntiAFK.cs @@ -43,6 +43,9 @@ namespace MinecraftClient.ChatBots LogToConsole(BotName, Translations.TryGet("bot.antiafk.invalid_walk_range")); } + Delay.min = Math.Max(10, Delay.min); + Delay.max = Math.Max(10, Delay.max); + if (Delay.min > Delay.max) { (Delay.min, Delay.max) = (Delay.max, Delay.min); @@ -58,14 +61,11 @@ namespace MinecraftClient.ChatBots public Range(int value) { - value = Math.Max(value, 10); min = max = value; } public Range(int min, int max) { - min = Math.Max(min, 10); - max = Math.Max(max, 10); this.min = min; this.max = max; } diff --git a/MinecraftClient/ChatBots/AutoRelog.cs b/MinecraftClient/ChatBots/AutoRelog.cs index f48288a9..a5f03bd6 100644 --- a/MinecraftClient/ChatBots/AutoRelog.cs +++ b/MinecraftClient/ChatBots/AutoRelog.cs @@ -28,18 +28,22 @@ namespace MinecraftClient.ChatBots [TomlInlineComment("$config.ChatBot.AutoRelog.Ignore_Kick_Message$")] public bool Ignore_Kick_Message = false; - [TomlInlineComment("$config.ChatBot.AutoRelog.Kick_Messages_File$")] - public string Kick_Messages_File = @"kickmessages.txt"; + [TomlInlineComment("$config.ChatBot.AutoRelog.Kick_Messages$")] + public string[] Kick_Messages = new string[] { "Reason1", "Reason2" }; public void OnSettingUpdate() { - Kick_Messages_File ??= string.Empty; - + Delay.min = Math.Max(1, Delay.min); + Delay.max = Math.Max(1, Delay.max); if (Delay.min > Delay.max) (Delay.min, Delay.max) = (Delay.max, Delay.min); if (Retries == -1) Retries = int.MaxValue; + + if (Enabled) + for (int i = 0; i < Kick_Messages.Length; i++) + Kick_Messages[i] = Kick_Messages[i].ToLower(); } public struct Range @@ -48,14 +52,11 @@ namespace MinecraftClient.ChatBots public Range(int value) { - value = Math.Max(value, 1); min = max = value; } public Range(int min, int max) { - min = Math.Max(min, 1); - max = Math.Max(max, 1); this.min = min; this.max = max; } @@ -63,7 +64,6 @@ namespace MinecraftClient.ChatBots } private static readonly Random random = new(); - private string[] dictionary = Array.Empty(); /// /// This bot automatically re-join the server if kick message contains predefined string @@ -83,27 +83,6 @@ namespace MinecraftClient.ChatBots { LogDebugToConsoleTranslated("bot.autoRelog.no_kick_msg"); } - else - { - if (System.IO.File.Exists(Config.Kick_Messages_File)) - { - LogDebugToConsoleTranslated("bot.autoRelog.loading", System.IO.Path.GetFullPath(Config.Kick_Messages_File)); - - dictionary = System.IO.File.ReadAllLines(Config.Kick_Messages_File, Encoding.UTF8); - - for (int i = 0; i < dictionary.Length; i++) - { - LogDebugToConsoleTranslated("bot.autoRelog.loaded", dictionary[i]); - dictionary[i] = dictionary[i].ToLower(); - } - } - else - { - LogToConsoleTranslated("bot.autoRelog.not_found", System.IO.Path.GetFullPath(Config.Kick_Messages_File)); - - LogDebugToConsoleTranslated("bot.autoRelog.curr_dir", System.IO.Directory.GetCurrentDirectory()); - } - } } public override bool OnDisconnect(DisconnectReason reason, string message) @@ -125,7 +104,7 @@ namespace MinecraftClient.ChatBots return true; } - foreach (string msg in dictionary) + foreach (string msg in Config.Kick_Messages) { if (comp.Contains(msg)) { diff --git a/MinecraftClient/ChatBots/ScriptScheduler.cs b/MinecraftClient/ChatBots/ScriptScheduler.cs index a502c3a4..ca5bc001 100644 --- a/MinecraftClient/ChatBots/ScriptScheduler.cs +++ b/MinecraftClient/ChatBots/ScriptScheduler.cs @@ -31,6 +31,11 @@ namespace MinecraftClient.ChatBots { foreach (TaskConfig task in TaskList) { + task.Trigger_On_Interval.MinTime = Math.Max(1, task.Trigger_On_Interval.MinTime); + task.Trigger_On_Interval.MaxTime = Math.Max(1, task.Trigger_On_Interval.MaxTime); + if (task.Trigger_On_Interval.MinTime > task.Trigger_On_Interval.MaxTime) + (task.Trigger_On_Interval.MinTime, task.Trigger_On_Interval.MaxTime) = (task.Trigger_On_Interval.MaxTime, task.Trigger_On_Interval.MinTime); + //Look for a valid action if (!String.IsNullOrWhiteSpace(task.Action)) { @@ -106,21 +111,17 @@ namespace MinecraftClient.ChatBots public TriggerOnIntervalConfig(int value) { this.Enable = true; - value = Math.Max(value, 10); MinTime = MaxTime = value; } public TriggerOnIntervalConfig(bool Enable, int value) { this.Enable = Enable; - value = Math.Max(value, 10); MinTime = MaxTime = value; } public TriggerOnIntervalConfig(int min, int max) { - min = Math.Max(min, 10); - max = Math.Max(max, 10); this.MinTime = min; this.MaxTime = max; } @@ -128,8 +129,6 @@ namespace MinecraftClient.ChatBots public TriggerOnIntervalConfig(bool Enable, int min, int max) { this.Enable = Enable; - min = Math.Max(min, 10); - max = Math.Max(max, 10); this.MinTime = min; this.MaxTime = max; } diff --git a/MinecraftClient/Resources/lang/en.ini b/MinecraftClient/Resources/lang/en.ini index 7694728e..58dc2248 100644 --- a/MinecraftClient/Resources/lang/en.ini +++ b/MinecraftClient/Resources/lang/en.ini @@ -817,7 +817,7 @@ config.ChatBot.AutoRelog=Automatically relog when disconnected by server, for ex config.ChatBot.AutoRelog.Delay=use 10 for 10 seconds, 10-60 for a random delay between 10 and 60 seconds config.ChatBot.AutoRelog.Retries=retries when failing to relog to the server. use -1 for unlimited retries config.ChatBot.AutoRelog.Ignore_Kick_Message=when set to true, autorelog will reconnect regardless of kick messages -config.ChatBot.AutoRelog.Kick_Messages_File=file with list of matches in kick messages that will trigger autorelog +config.ChatBot.AutoRelog.Kick_Messages=If the kickout message matches any of the strings, then autorelog will be triggered. # ChatBot.AutoRespond config.ChatBot.AutoRespond=Run commands or send messages automatically when a specified pattern is detected in chat\n# /!\ Server admins can spoof chat messages (/nick, /tellraw) so keep this in mind when implementing AutoRespond rules\n# /!\ This bot may get spammy depending on your rules, although the global messagecooldown setting can help you avoiding accidental spam