Merge Alerts's config

This commit is contained in:
BruceChen 2022-10-05 19:39:21 +08:00
parent 25dfcd8856
commit 642a85661f
5 changed files with 21 additions and 51 deletions

View file

@ -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<string>();
private string[] excludelist = Array.Empty<string>();
float curRainLevel = 0;
float curThunderLevel = 0;
const float threshold = 0.2f;
/// <summary>
/// Intitialize the Alerts bot
/// </summary>
public override void Initialize()
{
if (Config.Trigger_By_Words)
{
dictionary = LoadDistinctEntriesFromFile(Config.Matches_File);
excludelist = LoadDistinctEntriesFromFile(Config.Excludes_File);
}
}
/// <summary>
/// Process text received from the server to display alerts
/// </summary>
@ -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 !

View file

@ -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");

View file

@ -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()
{

View file

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

View file

@ -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,