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";
|
private static readonly string _MaxParallelDownloads = "3";
|
||||||
|
|
||||||
public string ServerID => ApplicationEnvironmentVariables["ServerID"];
|
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 LogFile => $"{ApplicationEnvironmentVariables["LogFolder"]}/{DateTime.Now.ToLongDateString().Replace(" / ", "")}.log";
|
||||||
public string DataFolder => _ResourcesFolder;
|
public string DataFolder => _ResourcesFolder;
|
||||||
|
|
||||||
|
|||||||
@@ -36,18 +36,22 @@ public class SettingsDictionary<TKey, TValue>
|
|||||||
{
|
{
|
||||||
_Dictionary = new Dictionary<TKey, TValue>();
|
_Dictionary = new Dictionary<TKey, TValue>();
|
||||||
await SaveToFile();
|
await SaveToFile();
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
string fileAsText = await File.ReadAllTextAsync(_File);
|
string fileAsText = await File.ReadAllTextAsync(_File);
|
||||||
if(string.IsNullOrEmpty(fileAsText) || string.IsNullOrWhiteSpace(fileAsText))
|
if(string.IsNullOrEmpty(fileAsText) || string.IsNullOrWhiteSpace(fileAsText))
|
||||||
{
|
{
|
||||||
_Dictionary = new Dictionary<TKey, TValue>();
|
_Dictionary = new Dictionary<TKey, TValue>();
|
||||||
|
await SaveToFile();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
_Dictionary = await JsonManager.ConvertFromJson<IDictionary<TKey,TValue>>(fileAsText);
|
_Dictionary = await JsonManager.ConvertFromJson<IDictionary<TKey,TValue>>(fileAsText);
|
||||||
|
|
||||||
|
if (_Dictionary.Keys.Count == 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user