This commit is contained in:
Master Kwoth 2017-10-21 12:21:03 +02:00
parent fe4cfa732f
commit e609f78eec

View File

@ -54,29 +54,37 @@ namespace NadekoBot.Modules.Utility.Services
private async Task UpdateCurrency(bool shouldLoad) private async Task UpdateCurrency(bool shouldLoad)
{ {
var unitTypeString = "currency"; try
if (shouldLoad)
{ {
var currencyRates = await GetCurrencyRates(); var unitTypeString = "currency";
var baseType = new ConvertUnit() if (shouldLoad)
{ {
Triggers = new[] { currencyRates.Base }, var currencyRates = await GetCurrencyRates();
Modifier = decimal.One, var baseType = new ConvertUnit()
UnitType = unitTypeString {
}; Triggers = new[] { currencyRates.Base },
var range = currencyRates.ConversionRates.Select(u => new ConvertUnit() Modifier = decimal.One,
{ UnitType = unitTypeString
Triggers = new[] { u.Key }, };
Modifier = u.Value, var range = currencyRates.ConversionRates.Select(u => new ConvertUnit()
UnitType = unitTypeString {
}).ToArray(); Triggers = new[] { u.Key },
Modifier = u.Value,
UnitType = unitTypeString
}).ToArray();
var fileData = JsonConvert.DeserializeObject<ConvertUnit[]>( var fileData = JsonConvert.DeserializeObject<ConvertUnit[]>(
File.ReadAllText("data/units.json")); File.ReadAllText("data/units.json"));
var data = JsonConvert.SerializeObject(range.Append(baseType).Concat(fileData).ToList()); var data = JsonConvert.SerializeObject(range.Append(baseType).Concat(fileData).ToList());
_cache.Redis.GetDatabase() _cache.Redis.GetDatabase()
.StringSet("converter_units", data); .StringSet("converter_units", data);
}
}
catch (Exception ex)
{
_log.Warn("Ignore the message below");
_log.Warn(ex);
} }
} }