Fixed bug where bot crashes if the config is empty
This commit is contained in:
@@ -28,7 +28,7 @@ namespace DiscordBotCore
|
||||
private static readonly string _MaxParallelDownloads = "3";
|
||||
|
||||
public string ServerID => ApplicationEnvironmentVariables["ServerID"];
|
||||
public string PluginDatabase => ApplicationEnvironmentVariables["PluginDatabase"];
|
||||
public string PluginDatabase => ApplicationEnvironmentVariables["PluginDatabase"] ?? _PluginsDatabaseFile;
|
||||
public string LogFile => $"{ApplicationEnvironmentVariables["LogFolder"]}/{DateTime.Now.ToLongDateString().Replace(" / ", "")}.log";
|
||||
public string DataFolder => _ResourcesFolder;
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user