From 82db7e54a4b82eb3116c32611940171997c9e2bb Mon Sep 17 00:00:00 2001 From: Madpeter <57852827+Madpeterz@users.noreply.github.com> Date: Sun, 30 Jun 2024 01:01:56 +0100 Subject: [PATCH] fix issues with json configs --- SecondBotEvents/Config/OnEventConfig.cs | 28 ---------------------- SecondBotEvents/Config/RelayConfig.cs | 10 -------- SecondBotEvents/Config/config.cs | 31 ++++++++++++++----------- 3 files changed, 18 insertions(+), 51 deletions(-) diff --git a/SecondBotEvents/Config/OnEventConfig.cs b/SecondBotEvents/Config/OnEventConfig.cs index ee6c89d..775a6dd 100644 --- a/SecondBotEvents/Config/OnEventConfig.cs +++ b/SecondBotEvents/Config/OnEventConfig.cs @@ -14,35 +14,7 @@ namespace SecondBotEvents.Config filename = "onevent"; settings.Add("Enabled"); settings.Add("Count"); - int loop = 1; - while (loop <= GetCount()) - { - settings.Add("Event" + loop.ToString() + "Enabled"); - if(GetEventEnabled(loop) == false) - { - loop++; - continue; - } - settings.Add("Event" + loop.ToString() + "Source"); - settings.Add("Event" + loop.ToString() + "Monitor"); - settings.Add("Event" + loop.ToString() + "WhereCount"); - int loop2 = 1; - while (loop2 <= GetWhereCount(loop)) - { - settings.Add("Event" + loop.ToString() + "Where" + loop2.ToString()); - loop2++; - } - settings.Add("Event" + loop.ToString() + "ActionCount"); - loop2 = 1; - while (loop2 <= GetActionCount(loop)) - { - settings.Add("Event" + loop.ToString() + "Action" + loop2.ToString()); - loop2++; - } - loop++; - } settings.Add("HideStatusOutput"); - return; } public void unloadEvents() diff --git a/SecondBotEvents/Config/RelayConfig.cs b/SecondBotEvents/Config/RelayConfig.cs index 7a6d390..0202f03 100644 --- a/SecondBotEvents/Config/RelayConfig.cs +++ b/SecondBotEvents/Config/RelayConfig.cs @@ -13,16 +13,6 @@ namespace SecondBotEvents.Config filename = "relay"; settings.Add("count"); settings.Add("HideStatusOutput"); - int loop = 1; - while(loop <= GetRelayCount()) - { - settings.Add(loop.ToString() + "_enabled"); - settings.Add(loop.ToString() + "_source_type"); - settings.Add(loop.ToString() + "_source_option"); - settings.Add(loop.ToString() + "_target_type"); - settings.Add(loop.ToString() + "_target_option"); - loop++; - } } public int GetRelayCount() diff --git a/SecondBotEvents/Config/config.cs b/SecondBotEvents/Config/config.cs index 4825d33..119e502 100644 --- a/SecondBotEvents/Config/config.cs +++ b/SecondBotEvents/Config/config.cs @@ -79,22 +79,26 @@ namespace SecondBotEvents.Config MakeSettingsFile(fromFolder); return; } - JObject result = JObject.Parse(IO.ReadFile(readfile)); - foreach (string setting in settings) + try { - if(result.ContainsKey(setting) == false) + JObject result = JObject.Parse(IO.ReadFile(readfile)); + foreach (var x in result) { - continue; + settings.Add(x.Key); + string value = x.Value.ToString(); + if (SecondbotHelpers.notempty(value) == false) + { + mysettings.Add(x.Key, ""); + continue; + } + mysettings.Add(x.Key, value); } - string value = result[setting].ToString(); - if (SecondbotHelpers.notempty(value) == false) - { - mysettings.Add(setting, ""); - continue; - } - mysettings.Add(setting, value); + loaded = true; + } + catch (Exception ex) + { + LogFormater.Warn("Json format for " + readfile + " is broken: " + ex.Message); } - loaded = true; } protected void LoadSettingsFromEnv() @@ -152,7 +156,8 @@ namespace SecondBotEvents.Config protected int ReadSettingAsInt(string key, int defaultValue = 30) { - bool result = int.TryParse(ReadSettingAsString(key, defaultValue.ToString()), out int value); + string read = ReadSettingAsString(key, defaultValue.ToString()); + bool result = int.TryParse(read, out int value); if (result == false) { return defaultValue;