Merge AutoRelog's configs

This commit is contained in:
BruceChen 2022-10-05 17:33:21 +08:00
parent e0678ea7a5
commit a118dc96e9
4 changed files with 18 additions and 40 deletions

View file

@ -43,6 +43,9 @@ namespace MinecraftClient.ChatBots
LogToConsole(BotName, Translations.TryGet("bot.antiafk.invalid_walk_range")); 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) if (Delay.min > Delay.max)
{ {
(Delay.min, Delay.max) = (Delay.max, Delay.min); (Delay.min, Delay.max) = (Delay.max, Delay.min);
@ -58,14 +61,11 @@ namespace MinecraftClient.ChatBots
public Range(int value) public Range(int value)
{ {
value = Math.Max(value, 10);
min = max = value; min = max = value;
} }
public Range(int min, int max) public Range(int min, int max)
{ {
min = Math.Max(min, 10);
max = Math.Max(max, 10);
this.min = min; this.min = min;
this.max = max; this.max = max;
} }

View file

@ -28,18 +28,22 @@ namespace MinecraftClient.ChatBots
[TomlInlineComment("$config.ChatBot.AutoRelog.Ignore_Kick_Message$")] [TomlInlineComment("$config.ChatBot.AutoRelog.Ignore_Kick_Message$")]
public bool Ignore_Kick_Message = false; public bool Ignore_Kick_Message = false;
[TomlInlineComment("$config.ChatBot.AutoRelog.Kick_Messages_File$")] [TomlInlineComment("$config.ChatBot.AutoRelog.Kick_Messages$")]
public string Kick_Messages_File = @"kickmessages.txt"; public string[] Kick_Messages = new string[] { "Reason1", "Reason2" };
public void OnSettingUpdate() 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) if (Delay.min > Delay.max)
(Delay.min, Delay.max) = (Delay.max, Delay.min); (Delay.min, Delay.max) = (Delay.max, Delay.min);
if (Retries == -1) if (Retries == -1)
Retries = int.MaxValue; Retries = int.MaxValue;
if (Enabled)
for (int i = 0; i < Kick_Messages.Length; i++)
Kick_Messages[i] = Kick_Messages[i].ToLower();
} }
public struct Range public struct Range
@ -48,14 +52,11 @@ namespace MinecraftClient.ChatBots
public Range(int value) public Range(int value)
{ {
value = Math.Max(value, 1);
min = max = value; min = max = value;
} }
public Range(int min, int max) public Range(int min, int max)
{ {
min = Math.Max(min, 1);
max = Math.Max(max, 1);
this.min = min; this.min = min;
this.max = max; this.max = max;
} }
@ -63,7 +64,6 @@ namespace MinecraftClient.ChatBots
} }
private static readonly Random random = new(); private static readonly Random random = new();
private string[] dictionary = Array.Empty<string>();
/// <summary> /// <summary>
/// This bot automatically re-join the server if kick message contains predefined string /// 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"); 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) public override bool OnDisconnect(DisconnectReason reason, string message)
@ -125,7 +104,7 @@ namespace MinecraftClient.ChatBots
return true; return true;
} }
foreach (string msg in dictionary) foreach (string msg in Config.Kick_Messages)
{ {
if (comp.Contains(msg)) if (comp.Contains(msg))
{ {

View file

@ -31,6 +31,11 @@ namespace MinecraftClient.ChatBots
{ {
foreach (TaskConfig task in TaskList) 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 //Look for a valid action
if (!String.IsNullOrWhiteSpace(task.Action)) if (!String.IsNullOrWhiteSpace(task.Action))
{ {
@ -106,21 +111,17 @@ namespace MinecraftClient.ChatBots
public TriggerOnIntervalConfig(int value) public TriggerOnIntervalConfig(int value)
{ {
this.Enable = true; this.Enable = true;
value = Math.Max(value, 10);
MinTime = MaxTime = value; MinTime = MaxTime = value;
} }
public TriggerOnIntervalConfig(bool Enable, int value) public TriggerOnIntervalConfig(bool Enable, int value)
{ {
this.Enable = Enable; this.Enable = Enable;
value = Math.Max(value, 10);
MinTime = MaxTime = value; MinTime = MaxTime = value;
} }
public TriggerOnIntervalConfig(int min, int max) public TriggerOnIntervalConfig(int min, int max)
{ {
min = Math.Max(min, 10);
max = Math.Max(max, 10);
this.MinTime = min; this.MinTime = min;
this.MaxTime = max; this.MaxTime = max;
} }
@ -128,8 +129,6 @@ namespace MinecraftClient.ChatBots
public TriggerOnIntervalConfig(bool Enable, int min, int max) public TriggerOnIntervalConfig(bool Enable, int min, int max)
{ {
this.Enable = Enable; this.Enable = Enable;
min = Math.Max(min, 10);
max = Math.Max(max, 10);
this.MinTime = min; this.MinTime = min;
this.MaxTime = max; this.MaxTime = max;
} }

View file

@ -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.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.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.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 # 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 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