Fixed bug where bot crashes if the config is empty

This commit is contained in:
2024-06-03 19:52:39 +03:00
parent 83115d72a4
commit cdd426b03c
2 changed files with 6 additions and 2 deletions

View File

@@ -36,18 +36,22 @@ public class SettingsDictionary<TKey, TValue>
{
_Dictionary = new Dictionary<TKey, TValue>();
await SaveToFile();
return true;
return false;
}
string fileAsText = await File.ReadAllTextAsync(_File);
if(string.IsNullOrEmpty(fileAsText) || string.IsNullOrWhiteSpace(fileAsText))
{
_Dictionary = new Dictionary<TKey, TValue>();
await SaveToFile();
return false;
}
_Dictionary = await JsonManager.ConvertFromJson<IDictionary<TKey,TValue>>(fileAsText);
if (_Dictionary.Keys.Count == 0)
return false;
return true;
}